User manual › Signal processing in the command window
kind: manual#console#signal-processing#filters#spectra#windows#manual

Signal processing in the command window#

Every name on this page is typed at the command window (or passed to ICoreBlocks --console "<line>") and answers what MATLAB's Signal Processing Toolbox answers for the same arguments — same defaults, same shapes, same edge cases. If you have MATLAB code that designs a filter, measures a spectrum or finds peaks, it should paste in and run.

That is a promise about NUMBERS, not just about names: each of these is checked against a live MATLAB, argument form by argument form, and the places where the two would otherwise disagree are called out below rather than left for you to discover.

The families, and what to reach for#

You want toUse
Design an IIR filterbutter, cheby1, cheby2, ellip, besself, sized by buttord, cheb1ord, cheb2ord, ellipord
Design an FIR filterfir1 (windowed), fir2 (frequency sampling), firls (least squares), firpm (equiripple), sized by kaiserord or firpmord; sgolay for the Savitzky–Golay projection matrix
Look at a filterfreqz, freqs, impz, stepz, grpdelay, phasez
Filter a signalfilter, filtfilt (zero phase), sosfilt, fftfilt, medfilt1, sgolayfilt, hampel
Change a filter's formtf2ss, ss2tf, tf2zp, zp2tf, tf2sos, sos2tf, zp2sos, sos2zp, ss2sos, ss2zp, zp2ss
Move a design in frequencylp2lp, lp2hp, lp2bp, lp2bs, bilinear, impinvar
Measure a spectrumperiodogram, pwelch, cpsd, mscohere, tfestimate, spectrogram
Measure a spectrum through a modelpyulear, pburg, pcov, pmcov
Measure a signalrms, peak2peak, peak2rms, rssq, bandpower, meanfreq, medfreq, obw, powerbw, snr, thd, sinad, sfdr
Find featuresfindpeaks, hilbert, envelope, xcorr, xcov, xcorr2 (2-D), cconv (circular), finddelay, alignsignals
Change a rateupsample, downsample, decimate, interp, resample, upfirdn
Window somethingall fifteen: hann, hamming, blackman, blackmanharris, bartlett, triang, bohmanwin, parzenwin, nuttallwin, flattopwin, rectwin, kaiser, chebwin, tukeywin, gausswin — or window(@name, n)
Make a test signalchirp, sawtooth, square, sinc, gauspuls, rectpuls, tripuls, pulstran
Fit an all-pole modellpc, aryule, arburg, arcov, armcov, levinson; convert between its forms with poly2rc, rc2poly, poly2ac, ac2poly
Start from an analog prototypebuttap, cheb1ap, cheb2ap, ellipap, besselap — the unit-cutoff lowpass each design is built from
Take another transformdct, idct, czt (chirp z), goertzel (single bins of the DFT)

A worked line or two#

Design a 20th-order lowpass at 0.3 of Nyquist and look at its first taps and its magnitude response on an 8-point grid:

>>> b = fir1(20, 0.3); b(1:5)
[[3.11392e-19, 0.0029289, 0.00634235, 0.00378304, -0.0123878]]  # Matrix of Double

>>> [h, w] = freqz(b, 1, 8); abs(h)
[[1], [0.997965], [0.751936], [0.14917], [0.0024298], [0.000401409], [1.54439e-05], [0.000751753]]  # Matrix of Double

The equiripple design of the same specification — a different filter, and usually a shorter one for the same stopband:

>>> firpm(10, [0, 0.4, 0.5, 1], [1, 1, 0, 0])
[[0.0594916, -0.0979816, -0.117369, 0.0371959, 0.307877, 0.445963, 0.307877, 0.0371959, -0.117369, -0.0979816, 0.0594916]]  # Matrix of Double

Measure a two-tone signal — an averaged spectrum, the peaks' prominences, and three single-number summaries:

>>> x = sin(0:0.25:12) + 0.3*sin(0:0.75:36); pwelch(x, 16, 8, 16)
[[0.524733], [0.757164], [0.113157], [0.0126083], [0.000159285], [0.000163977], [0.000151014], [0.000141381], [6.90395e-05]]  # Matrix of Double

>>> [p, q, w, pr] = findpeaks(x); pr
pr = [[0.915061, 0.20885, 0.216574, 1.82706, 0.197127, 0.220018]]  # Matrix of Double

>>> [meanfreq(x, 4), medfreq(x, 4), rms(x)]
[[0.194992, 0.167362, 0.743232]]  # Matrix of Double

Every transcript on this page is real output, captured with ICoreBlocks --console "<line>" on 2026-09-03 at commit 4a011586 — with the bartlett/triang pair in surprise 8 captured the same day from a later build of the same tree, the two windows' code being unchanged between them.

Eight things that surprise people#

These are not this console's quirks — they are MATLAB's, reproduced on purpose because a filter that "looks right" and differs in the third digit is worse than one that refuses. Each has cost somebody a debugging session.

  1. fir1 is not a windowed sinc. It windows the LEAST-SQUARES design that firls produces. A textbook windowed-sinc lowpass agrees with it to about three digits and no further, so a filter you derived by hand will not match one fir1 designed.
  2. Wn is normalised to NYQUIST, not to the sample rate. fir1(20, 0.3) cuts off at 0.3 × (fs/2). Passing a fraction of fs designs a filter at twice the frequency you meant.
  3. A scalar window argument is a LENGTH; a vector is the window. pwelch(x, 16, ...) asks for 16-sample Hamming segments; pwelch(x, hann(16), ...) asks for that window. The same position means two things and the shape decides which.
  4. pwelch's default segmentation is eight segments with 50% overlap, which makes the default segment fix(n / 4.5) samples — not n / 8.
  5. A peak's PROMINENCE is not its height above the neighbouring valleys. It is the height above the higher of the two lowest points reached before the signal rises above that peak again, a walk that can cross other peaks. The local quantity people usually mean is findpeaks(..., "Threshold", t). And findpeaks(..., "WidthReference", "halfheight") quietly drops peaks at or below zero, because a peak at zero has no half height to measure.
  6. powerbw's default reference is the exact half power — 3.0103 dB, not the 3 dB the name is always said with. Ask for powerbw(x, fs, [], 3) and you get a slightly narrower answer; both are right, they are different questions.
  7. filtfilt needs a signal longer than three times the filter's order, because it reflects that many samples onto each end before it filters:
>>> y = filtfilt(fir1(6, 0.3), 1, [1, 2, 3, 4, 5, 4, 3, 2, 1, 0]); y(1:5)
error: filtfilt(b, a, x): x must be longer than 18 samples for a filter of order 6 -- filtfilt reflects that many samples onto each end before it filters, and cannot reflect more of the signal than there is
  1. bartlett and triang are both "the triangular window" and they are not the same window. bartlett(n) reaches zero at both ends; triang(n) does not — for an odd length its end samples sit at 2/(n+1) of the peak (1/3 at n = 5, 1/4 at n = 7, 1/5 at n = 9):

    `` >>> [bartlett(5)'; triang(5)'] [[0, 0.5, 1, 0.5, 0], [0.333333, 0.666667, 1, 0.666667, 0.333333]] # Matrix of Double ``

    Two of a five-point window's samples are zero in one and not the other, so swapping the names changes a spectrum's sidelobes rather than merely scaling it. MATLAB draws the same distinction and this is its arithmetic.

What is not here#

Some names are refused with a sentence saying why, and some the console simply does not know. The difference is visible when you type them, so it is worth knowing which you will get.

Refused, with the reason in the message:

  • pmtm, peig and pmusic — the multitaper and subspace spectral estimates. pmtm needs the Slepian sequences dpss produces, which this console has no name for; peig and pmusic answer a pseudospectrum, a different quantity from a power spectral density. The four names beside them (pyulear, pburg, pcov, pmcov) answer the density.
  • zplane — it only ever draws, and its outputs are graphics handles. The numbers behind that picture cross under their own names: tf2zp(b, a) for a coefficient pair, sos2zp(sos) for a section cascade.

Not known to the console at all — typing one of these answers unknown function '<name>', with no advice in the message, so take the advice from here instead:

If you reach forUse
designfilt, digitalFilter, dsp.*the design functions directly — butter, cheby1, ellip, fir1, firpm. This console has no object types; a filter is its coefficients
fvtoolfreqz for the response, impz/stepz for the time response, grpdelay for group delay
wvtoolthe window function itself — hann(n), kaiser(n, beta) — and read the values
filterDesigner, sptool, signalAnalyzerthe same design and measurement names; there is no interactive tool here

Those seven are meant to answer with a sentence of their own one day. Until they do, the table above is that sentence.

Two behaviours differ deliberately and are worth knowing:

  • Where MATLAB draws a plot when you use a name without asking for its value, this console answers the value. freqz(b, a) gives you the response; spectrogram(x) gives you the transform. Nothing is drawn as a side effect.
  • findpeaks(..., "Annotate", ...) is refused, because it only ever addressed the plot.

Three names on this console are not MATLAB's and are kept only for console scripts written before the toolbox names arrived: butterlp, butterhp and butternotch, each of which designs a Butterworth filter and answers a transfer function rather than coefficients. MATLAB spells all three butter, and new work should — but the two do not take the same numbers, so translating a script is not a find-and-replace. These three take the cutoff and the sample rate in hertz where butter takes one frequency normalised to the Nyquist rate, so butterlp(4, 100, 1000) is butter(4, 100 / (1000 / 2)), and the coefficients it answers become a model with tf(b, a, 1 / 1000). butterhp adds "high" and butternotch passes the two band edges with "stop" — and that last one is an approximation rather than the same design: this console pins the null exactly at the centre frequency while MATLAB's bandstop is symmetric about the geometric mean of its edges, so the two responses part company near the notch. They are marked as the console's own in Command glossary — console commands, verbs, functions, so nothing on this page's parity promise rests on them.

Where to look next#