RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • blackman
    • butter
    • buttord
    • cheb2ord
    • conv
    • conv2
    • deconv
    • downsample
    • envelope
    • filter
    • filtfilt
    • fir1
    • freqz
    • gauspuls
    • hamming
    • hann
    • hilbert
    • periodogram
    • pulstran
    • pwelch
    • rectpuls
    • resample
    • sawtooth
    • sinc
    • spectrogram
    • square
    • tripuls
    • unwrap
    • upsample
    • zplane

pwelch — Estimate power spectral density using Welch's method.

pwelch(x) estimates the power spectral density of a signal by averaging modified periodograms of overlapped, windowed segments. Optional arguments select the window, overlap, FFT length, sampling frequency, frequency range, and spectrum scale.

Syntax

pxx = pwelch(x, window, noverlap, nfft, fs, freqrange)
[pxx, f] = pwelch(x, window, noverlap, nfft, fs, freqrange)

Inputs

NameTypeRequiredDefaultDescription
xNumericArrayYes—Input signal vector or matrix with one signal per column.
windowAnyNo[]Window vector or scalar segment length.
noverlapNumericScalarNo[]Number of overlapped samples.
nfftNumericArrayNo[]FFT length or explicit frequency vector.
fsNumericScalarNo—Sampling frequency in Hz.
freqrangeStringScalarNo—Frequency range selector (`onesided`, `twosided`, or `centered`) and spectrum type (`psd` or `power`).

Returns

NameTypeDescription
pxxNumericArrayPower spectral density estimate.
fNumericArrayFrequency vector in radians/sample or Hz when fs is supplied.

Returned values from pwelch depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:pwelch:ArgCountThe argument count is outside supported forms.pwelch: expected pwelch(x, [window, [noverlap, [nfft_or_f, [fs, [freqrange_or_scale]]]]])
RunMat:pwelch:InvalidSignalInput signal is not a numeric vector or matrix.pwelch: x must be a nonempty numeric vector or 2-D matrix
RunMat:pwelch:InvalidWindowWindow input is invalid.pwelch: window must be a nonempty vector or positive integer length
RunMat:pwelch:InvalidOverlapOverlap is invalid.pwelch: noverlap must be a nonnegative integer less than window length
RunMat:pwelch:InvalidNfftFFT length is invalid.pwelch: nfft must be a positive integer at least as large as the window length
RunMat:pwelch:InvalidFsSampling frequency is invalid.pwelch: fs must be a positive finite scalar
RunMat:pwelch:InvalidRangeFrequency range selector is invalid.pwelch: freqrange must be 'onesided', 'twosided', or 'centered'; spectrum type must be 'psd' or 'power'
RunMat:pwelch:InternalOutput tensor construction fails internally.pwelch: internal error

How pwelch works

  • pxx = pwelch(x) returns a one-sided PSD estimate for real inputs and a two-sided estimate for complex inputs.
  • Matrix inputs are processed column-wise; pxx has one output column per input column. Single input produces single pxx and f outputs, while double and admitted typed-integer input produce double outputs.
  • [pxx, f] = pwelch(...) also returns the frequency grid. Without fs, frequencies are in radians/sample; with fs, frequencies are in Hz.
  • The window argument may be a vector or a scalar segment length. A scalar creates a Hamming window of that length; [] uses a default Hamming window sized for roughly eight 50%-overlapped sections, capped at 256 samples.
  • noverlap defaults to half the window length and must be less than the window length.
  • nfft defaults to max(256, length(window)), must be at least the window length, and controls the FFT grid. A real frequency vector may be supplied in the same position to evaluate the PSD at explicit frequencies.
  • The optional range selector accepts 'onesided', 'twosided', or 'centered'.
  • The optional spectrum type accepts 'psd' (default) or 'power'; 'power' omits the density bandwidth normalization.
  • The compatibility target documents single and double signal, window, and frequency data. RunMat mode additionally accepts all eight typed-integer classes for the signal and numeric controls after proving every value is exactly representable at the binary64 Welch boundary, and retains logical signal/control admission as a separately declared extension; strict compatibility mode rejects those extensions before provider dispatch.

Examples

PSD of a sine wave

fs = 1000;
t = (0:999) / fs;
x = sin(2*pi*100*t);
[pxx, f] = pwelch(x, hamming(256), 128, 512, fs);

Use a scalar window length

[pxx, w] = pwelch(randn(1,1024), 128, 64, 256);

Two-sided spectrum

x = exp(1i*2*pi*(0:127)/16);
[pxx, w] = pwelch(x, 64, 32, 128, 'twosided');

Centered spectrum in Hz

[pxx, f] = pwelch(randn(1,512), [], [], 512, 2000, 'centered');

Column-wise spectra for a matrix

x = [sin(2*pi*(0:255)'/16), cos(2*pi*(0:255)'/32)];
[pxx, f] = pwelch(x, 64, 32, 128, 'power');

Evaluate at explicit normalized frequencies

w = linspace(0, pi, 64);
[pxx, wout] = pwelch(randn(1,512), hamming(128), 64, w);

Using pwelch with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how pwelch changes the result.

Run a small pwelch example, explain the result, then change one input and compare the output.

FAQ

Can I pass a Hamming window from the hamming builtin?⌄

Yes. pwelch(x, hamming(n), noverlap, nfft, fs) uses the provided window directly. Passing the scalar n instead creates the same kind of Hamming segment window internally.

Does pwelch include the Nyquist bin?⌄

For one-sided output and even nfft, yes. The output length is nfft/2 + 1, with DC first and the Nyquist bin last.

Does pwelch plot when no outputs are requested?⌄

RunMat currently returns values using normal output-count semantics instead of opening a plot. Use the returned pxx and frequency vector with plotting functions explicitly.

Related Math functions

Signal

blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane

Elementwise

abs · angle · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · gamma · gammaln · heaviside · hypot · idivide · imag · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · swapbytes · times · typecast · uint16 · uint32 · uint8

Trigonometry

acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh

Reduction

all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var

Structure

bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · decomposition · eig · eigs · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref · vecnorm

Optim

coneprog · fminbnd · fminunc · fsolve · fzero · integral · linprog · lsqcurvefit · lsqnonlin · optimoptions · optimset · quad · secondordercone

Ops

cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose

Symbolic

digits · int · limit · piecewise · sym · syms · vpa

Fft

fft · fft2 · fftn · fftshift · ifft · ifft2 · ifftn · ifftshift

Interpolation

griddedInterpolant · interp1 · interp1q · interp2 · pchip · ppval · spline

Discrete

lcm · primes

Ode

ode15s · ode23 · ode45

Poly

polyder · polyfit · polyint · polyval · roots

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how pwelch is executed, line by line, in Rust.

  • View the source for pwelch in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How pwelch works
  • Examples
  • PSD of a sine wave
  • Use a scalar window length
  • Two-sided spectrum
  • Centered spectrum in Hz
  • Column-wise spectra for a matrix
  • Evaluate at explicit normalized frequencies
  • Using pwelch with coding agents
  • FAQ
  • Related Math functions
  • Signal
  • Elementwise
  • Trigonometry
  • Reduction
  • Structure
  • Rounding
  • Factor
  • Solve
  • Optim
  • Ops
  • Symbolic
  • Fft
  • Interpolation
  • Discrete
  • Ode
  • Poly
  • Open-source implementation
  • About RunMat