filters the input signal
y = lowpass(
x using a lowpass filter with
normalized passband frequency
wpass in units of
lowpass uses a
minimum-order filter with a stopband attenuation of 60 dB and compensates for
the delay introduced by the filter. If
x is a matrix, the
function filters each column independently.
lowpass(___) with no output arguments plots
the input signal and overlays the filtered signal.
Create a signal sampled at 1 kHz for 1 second. The signal contains two tones, one at 50 Hz and the other at 250 Hz, embedded in Gaussian white noise of variance 1/100. The high-frequency tone has twice the amplitude of the low-frequency tone.
fs = 1e3; t = 0:1/fs:1; x = [1 2]*sin(2*pi*[50 250]'.*t) + randn(size(t))/10;
Lowpass-filter the signal to remove the high-frequency tone. Specify a passband frequency of 150 Hz. Display the original and filtered signals, and also their spectra.
Implement a basic digital music synthesizer and use it to play a traditional song. Specify a sample rate of 2 kHz. Plot the spectrogram of the song.
fs = 2e3; t = 0:1/fs:0.3-1/fs; l = [0 130.81 146.83 164.81 174.61 196.00 220 246.94]; m = [0 261.63 293.66 329.63 349.23 392.00 440 493.88]; h = [0 523.25 587.33 659.25 698.46 783.99 880 987.77]; note = @(f,g) [1 1 1]*sin(2*pi*[l(g) m(g) h(f)]'.*t); mel = [3 2 1 2 3 3 3 0 2 2 2 0 3 5 5 0 3 2 1 2 3 3 3 3 2 2 3 2 1]+1; acc = [3 0 5 0 3 0 3 3 2 0 2 2 3 0 5 5 3 0 5 0 3 3 3 0 2 2 3 0 1]+1; song = ; for kj = 1:length(mel) song = [song note(mel(kj),acc(kj)) zeros(1,0.01*fs)]; end song = song/(max(abs(song))+0.1); % To hear, type sound(song,fs) pspectrum(song,fs,'spectrogram','TimeResolution',0.31, ... 'OverlapPercent',0,'MinThreshold',-60)
Lowpass-filter the signal to separate the melody from the accompaniment. Specify a passband frequency of 450 Hz. Plot the original and filtered signals in the time and frequency domains.
long = lowpass(song,450,fs); % To hear, type sound(long,fs) lowpass(song,450,fs)
Plot the spectrogram of the accompaniment.
figure pspectrum(long,fs,'spectrogram','TimeResolution',0.31, ... 'OverlapPercent',0,'MinThreshold',-60)
Filter white noise sampled at 1 kHz using an infinite impulse response lowpass filter with a passband frequency of 200 Hz. Use different steepness values. Plot the spectra of the filtered signals.
fs = 1000; x = randn(20000,1); [y1,d1] = lowpass(x,200,fs,'ImpulseResponse','iir','Steepness',0.5); [y2,d2] = lowpass(x,200,fs,'ImpulseResponse','iir','Steepness',0.8); [y3,d3] = lowpass(x,200,fs,'ImpulseResponse','iir','Steepness',0.95); pspectrum([y1 y2 y3],fs) legend('Steepness = 0.5','Steepness = 0.8','Steepness = 0.95')
Compute and plot the frequency responses of the filters.
[h1,f] = freqz(d1,1024,fs); [h2,~] = freqz(d2,1024,fs); [h3,~] = freqz(d3,1024,fs); plot(f,mag2db(abs([h1 h2 h3]))) legend('Steepness = 0.5','Steepness = 0.8','Steepness = 0.95')
x— Input signal
Input signal, specified as a vector or matrix.
sin(2*pi*(0:127)/16)+randn(1,128)/100 specifies a noisy
[2 1].*sin(2*pi*(0:127)'./[16 64]) specifies a two-channel
Complex Number Support: Yes
wpass— Normalized passband frequency
Normalized passband frequency, specified as a scalar in the interval (0, 1).
fpass— Passband frequency
Passband frequency, specified as a scalar in the interval (0,
fs— Sample rate
Sample rate, specified as a positive real scalar.
xt— Input timetable
xt must contain increasing, finite, and equally spaced
row times of type
duration in seconds.
If a timetable has missing or duplicate time points, you can fix it using the tips in Clean Timetable with Missing, Duplicate, or Nonuniform Times.
timetable(seconds(0:4)',randn(5,1),randn(5,2)) contains a
single-channel random signal and a two-channel random signal, sampled at 1 Hz for 4
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
'ImpulseResponse','iir','StopbandAttenuation',30filters the input using a minimum-order IIR filter that attenuates frequencies higher than
fpassby 30 dB.
'ImpulseResponse'— Type of impulse response
Type of impulse response of the filter, specified as the comma-separated pair consisting of
'fir' — The function designs a minimum-order,
linear-phase, finite impulse response (FIR) filter. To compensate for the
delay, the function appends to the input signal N/2
zeros, where N is the filter order. The function then
filters the signal and removes the first N/2 samples of
In this case, the input signal must be at least twice as long as the filter that meets the specifications.
'iir' — The function
designs a minimum-order infinite impulse response
(IIR) filter and uses the
filtfilt function to perform
zero-phase filtering and compensate for the filter
If the signal is not at least three times as long as the filter that meets the specifications, the function designs a filter with smaller order and thus smaller steepness.
'auto' — The function
designs a minimum-order FIR filter if the input
signal is long enough, and a minimum-order IIR
filter otherwise. Specifically, the function
follows these steps:
Compute the minimum order that an FIR filter must have to meet the specifications. If the signal is at least twice as long as the required filter order, design and use that filter.
If the signal is not long enough, compute the minimum order that an IIR filter must have to meet the specifications. If the signal is at least three times as long as the required filter order, design and use that filter.
If the signal is not long enough, truncate the order to one-third the signal length and design an IIR filter of that order. The reduction in order comes at the expense of transition band steepness.
Filter the signal and compensate for the delay.
'Steepness'— Transition band steepness
0.85(default) | scalar in the interval [0.5, 1)
Transition band steepness, specified as the comma-separated pair
'Steepness' and a scalar in the
interval [0.5, 1). As the steepness increases, the filter response
approaches the ideal lowpass response, but the resulting filter length
and the computational cost of the filtering operation also increase. See
Lowpass Filter Steepness
for more information.
'StopbandAttenuation'— Filter stopband attenuation
60(default) | positive scalar in dB
Filter stopband attenuation, specified as the comma-separated pair consisting of
'StopbandAttenuation' and a positive scalar in dB.
y— Filtered signal
Filtered signal, returned as a vector, a matrix, or a timetable with the same dimensions as the input.
d— Lowpass filter
'Steepness' argument controls the width
of a filter's transition region. The lower the steepness, the wider the transition
region. The higher the steepness, the narrower the transition region.
To interpret the filter steepness, consider the following definitions:
The Nyquist frequency, fNyquist, is the highest frequency component of a signal that
can be sampled at a given rate without aliasing. fNyquist is 1 (×π rad/sample) when the input
signal has no time information, and
fs/2 hertz when
the input signal is a timetable or when you specify a sample
The stopband frequency of the filter, fstop, is the frequency beyond which the attenuation is
equal to or greater than the value specified using
The transition width of the filter,
W, is fstop –
Most nonideal filters also attenuate the input signal across the
passband. The maximum value of this frequency-dependent attenuation is
called the passband ripple. Every filter used by
lowpass has a passband ripple of 0.1 dB.
When you specify a value, s, for
'Steepness', the function computes the transition width as
W = (1 – s) ×
'Steepness' is equal to 0.5, the transition
width is 50% of (fNyquist –
'Steepness' approaches 1, the transition width
becomes progressively narrower until it reaches a minimum value of 1% of (fNyquist –
The default value of
'Steepness' is 0.85, which
corresponds to a transition width that is 15% of (fNyquist –