bandpass filter with db in matlab

To design a digital bandpass filter in Matlab with the decibel (dB) scale, you can follow these steps:

  1. Define the filter's specifications, such as the passband range, stopband range, passband ripple, and stopband attenuation, in decibels using the "designfilt" function. The 'passband' and 'stopband' variables are specified in Hz.
main.m
fs = 1000;           % sampling frequency in Hz
passband = [50 200]; % passband range in Hz
stopband = [0 25 300 350];  % stopband range in Hz
pass_ripple = 0.5;   % passband ripple in dB
stop_attenuation = 60; % stopband attenuation in dB
bandpass = designfilt('bandpassiir', 'FilterOrder', 10, ...
         'PassbandFrequency', passband, ...
         'StopbandFrequency', stopband, ...
         'PassbandRipple', pass_ripple, ...
         'StopbandAttenuation', stop_attenuation, ...
         'SampleRate', fs);
514 chars
12 lines
  1. Next, apply the filter to your signal using the "filter" function. In this example, we generate and plot a sinusoidal signal with noise, and then apply the bandpass filter to obtain the filtered signal.
main.m
t = 0:1/fs:1;       % time vector of 1 second
x = sin(2*pi*70*t) + sin(2*pi*120*t) + 0.4*randn(size(t)); % signal with noise
x_filtered = filter(bandpass, x); % apply bandpass filter
subplot(2,1,1);
plot(t,x);
title('Original signal (with noise)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(t,x_filtered);
title('Filtered signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
411 chars
16 lines

The resulting plot shows the original signal (with noise) and the filtered signal. The filtered signal has much less noise and consists mainly of the two sinusoidal components within the passband range.

gistlibby LogSnag