periodogram — Estimate power spectral density using a periodogram.
periodogram(x) estimates the power spectral density of a signal by windowing the full input and evaluating its DFT. Optional arguments select the analysis window, DFT length or explicit frequency grid, sampling frequency, frequency range, and spectrum scale.
Syntax
pxx = periodogram(x, window, nfft, fs, freqrange)
[pxx, f] = periodogram(x, window, nfft, fs, freqrange)Inputs
x- Type
NumericArray- Required
- Yes
- Description
- Input signal vector or matrix with one signal per column. In RunMat its floating precision determines every numerical output class.
window- Type
NumericArray- Required
- No
- Default
[]- Description
- Window vector. [] uses a rectangular window matching the signal length.
nfft- Type
NumericArray- Required
- No
- Default
[]- Description
- DFT length or explicit frequency vector.
fs- Type
NumericScalar- Required
- No
- Description
- Sampling frequency in Hz.
freqrange- Type
StringScalar- Required
- No
- Description
- Frequency range selector (`onesided`, `twosided`, or `centered`) and spectrum type (`psd` or `power`).
Returns
pxx- Type
NumericArray- Description
- Power spectral density or power spectrum estimate.
f- Type
NumericArray- Description
- Frequency vector in radians/sample or Hz when fs is supplied.
Returned values from periodogram depend on how many outputs the caller requests.
Errors
RunMat:periodogram:ArgCount- When
- The argument count is outside supported forms.
- Message
periodogram: expected periodogram(x, [window, [nfft_or_f, [fs, [freqrange_or_scale]]]])
RunMat:periodogram:InvalidSignal- When
- Input signal is not a numeric vector or matrix.
- Message
periodogram: x must be a nonempty numeric vector or 2-D matrix
RunMat:periodogram:InvalidWindow- When
- Window input is invalid.
- Message
periodogram: window must be a finite real vector matching the signal length
Behavior
RunMat returns the computed Pxx and F outputs in the signal's floating precision: single signals produce single PSD and frequency arrays, and double signals produce double arrays. Window and sampling-control classes do not change this rule. This is RunMat's policy, not a claim of verified MATLAB class parity. The host reference computes FFT and window arithmetic in double and casts once when publishing single outputs.
pxx = periodogram(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.
[pxx, f] = periodogram(...) also returns the frequency grid. Without fs, frequencies are in radians/sample; with fs, frequencies are in Hz. Passing fs as [] uses 1 Hz units.
window must be a finite real vector matching the signal length. [] uses a rectangular window.
nfft defaults to max(256, 2^nextpow2(length(x))) and controls the DFT grid. If nfft is shorter than the window, windowed samples are summed modulo nfft before the DFT. A real frequency vector may be supplied in the same position to evaluate explicit frequencies.
The optional range selector accepts 'onesided', 'twosided', or 'centered'; 'onesided' is valid only for real-valued signals.
The optional spectrum type accepts 'psd' (default) or 'power'; 'power' reports power spectrum values using coherent-gain normalization.
Typed-integer signals and typed-integer numeric controls are separate RunMat extensions. Structural DFT lengths are decoded exactly; signals, windows, frequency grids, and sample rates must be exactly representable before entering the floating spectral domain.
Execution and ownership
Resident routes use the signal's exact owner and native class. Typed unsupported capabilities select the reference path; operational failures retain their source and do not replay execution.
Requested computed outputs use checked class-preserving restoration after reference evaluation. Explicit placement requires successful restoration; automatic placement may return a host output when restoration is unsupported. Original inputs and earlier outputs remain protected.
Uniform-grid periodograms keep GPU-resident signal data on device through windowing, folded framing when needed, FFT, frequency selection, and power scaling. Explicit-frequency forms fall back to host execution.
Examples
PSD of a sine wave
fs = 1000;
t = (0:999) / fs;
x = sin(2*pi*100*t);
[pxx, f] = periodogram(x, [], 1024, fs);Use a Hamming window and power spectrum scaling
x = 1.8*cos(2*pi*(0:127)/16);
[pxx, f] = periodogram(x, hamming(128), 128, 'power');Two-sided complex spectrum
x = exp(1i*2*pi*(0:127)/16);
[pxx, w] = periodogram(x, [], 128, 'twosided');Column-wise spectra for a matrix
x = [sin(2*pi*(0:255)'/16), cos(2*pi*(0:255)'/32)];
[pxx, f] = periodogram(x, [], 256, 1000);Evaluate at explicit normalized frequencies
w = linspace(0, pi, 64);
[pxx, wout] = periodogram(randn(1,512), [], w);Using periodogram with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how periodogram changes the result.
Run a small periodogram example, explain the result, then change one input and compare the output.
FAQ
How is periodogram different from pwelch?⌄
periodogram estimates a spectrum from one windowed full-signal segment. pwelch splits the signal into overlapped segments and averages the modified periodograms.
Does periodogram 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 periodogram 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 · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Elementwise
abs · angle · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · expm1 · flintmax · gamma · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8
Optim
acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fminbnd · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · ga · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.exp · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · 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
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Interpolation
griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline
Integer Division
Source you can read
Every RunMat function's source is public. Read exactly how periodogram is executed, line by line, in Rust.
- View the source for periodogram in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.