Compute the Discrete Cosine Transform (DCT-II) of a real-valued signal. DCT-II is defined as X[k] = sum_{n=0}^{N-1} x[n] * cos(pi*(2n+1)*k/(2N)). Computed directly in O(N^2). The DC component X[0] equals the sum of all input samples.
Compute the Discrete Sine Transform (DST-I) of a real-valued signal. X[k] = sum_{n=0}^{N-1} x[n] * sin(pi * (n+1) * (k+1) / (N+1)). Computed directly in O(N^2). Useful for PDEs with Dirichlet boundary conditions. The DST-I is its own inverse up to the scaling factor 2/(N+1), so idst(dst(x)) == x.
Compute one level of the Discrete Wavelet Transform (DWT). Decomposes the signal into approximation (lowpass) and detail (highpass) coefficients. Supported wavelets: "haar" (Haar wavelet) and "db2" (Daubechies-2). For "haar": approx[i] = (x[2i] + x[2i+1]) / sqrt(2), detail[i] = (x[2i] - x[2i+1]) / s
Syntax
dwt(signal | wavelet)
Type Signatures
Array, string
Parameters
Name
Type
Description
signal
Array
Real-valued input signal (length must be even for haar)
Compute the 2D Discrete Fourier Transform of a real-valued matrix. The 2D DFT is applied by computing a 1D DFT along each row, then along each column of the result. Returns a 2D array of complex numbers with properties re and im. The DC component (zero frequency) is at position [0][0].
Compute the Fourier transform of a real-valued signal with user-friendly output. Returns an object with frequencies, amplitudes, and phases arrays. Amplitudes are scaled by 1/N. Optionally accepts options.sampleRate (default: 1) for physical frequency bins, and options.output = "complex" to return t
A vector of frequencies (in radians/sample) at which the frequency response is to be computed or the number of points to compute (if a number is not provided, the default is 512 points)
Returns
Object — An object with two properties: h, a vector containing the complex frequency response, and w, a vector containing the normalized frequencies (in radians/sample) at which the response was computed.
Examples
freqz([1 2
See Also
highpassFilter
Apply a 2nd order Butterworth highpass IIR filter to a signal. The cutoff and sampleRate must use the same time unit (e.g., both in Hz).
Compute the Hilbert transform of a real-valued signal. The Hilbert transform produces a 90-degree phase shift of the input. It is computed via DFT: multiply positive-frequency components by -i, zero out the DC and Nyquist, zero out negative frequencies, then take the imaginary part of the IDFT resul
Syntax
hilbertTransform(signal)
Parameters
Name
Type
Description
signal
Array
Real-valued input array (length should be a power of 2 for best accuracy)
Returns
Array — Hilbert transform (imaginary part of the analytic signal)
Compute the Inverse Discrete Sine Transform (IDST-I). x[n] = (2/(N+1)) * sum_{k=0}^{N-1} X[k] * sin(pi * (n+1) * (k+1) / (N+1)). The IDST-I is self-inverse: applying it to the output of dst with scaling 2/(N+1) recovers the original signal. idst(dst(x)) == x within floating-point tolerance.
Reconstruct a real-valued signal from its Fourier spectrum. Accepts either a complex coefficient array (as returned by fourier with output:"complex") or a spectrum object { frequencies, amplitudes, phases } (as returned by the default fourier() call). Applies the inverse FFT with proper N-scaling.
Syntax
invFourier(spectrum)
Parameters
Name
Type
Description
spectrum
Array|Object
Returns
Array — Reconstructed signal (real parts of ifft output, scaled by N)
Apply a median filter to a 1D signal. For each position, computes the median of the windowSize-element sliding window centered on that position. Edge samples use mirror (reflect) padding. windowSize must be a positive odd integer. The median filter is effective for removing impulse noise (spikes) wh
Estimate the power spectral density (PSD) of a signal using the periodogram method. Computes |FFT(x)|^2 scaled by window normalization. Returns the one-sided spectrum (DC to Nyquist) as an object with frequencies and power arrays. Options: sampleRate (default: 1), window type (default: "rectangular"
Resample a signal by a given factor using linear interpolation. A factor > 1 upsamples (increases length), a factor < 1 downsamples (decreases length). The output has round((N-1)*factor)+1 samples, mapping evenly between the first and last input samples. Non-integer factors are fully supported.
Compute the spectrogram (Short-Time Fourier Transform magnitude) of a signal. Slides a window across the signal, applies a window function, and computes the FFT magnitude at each position. Returns an object with times, frequencies, and magnitude (2D array indexed by [timeIndex][freqBin]). Options: h