MATLAB Code
clear all;
close all;
% Define filter parameters
fs = 1000; % Sampling frequency (Hz)
fpass1 = 50; % Lower cutoff frequency (Hz)
fpass2 = 200; % Upper cutoff frequency (Hz)
filterOrder = 4; % Filter order
% Calculate normalized cutoff frequencies
nyquistFreq = fs / 2;
normFpass1 = fpass1 / nyquistFreq;
normFpass2 = fpass2 / nyquistFreq;
% Design the bandpass filter
filter = designfilt('bandpassiir', ...
'FilterOrder', filterOrder, ...
'HalfPowerFrequency1', normFpass1, ...
'HalfPowerFrequency2', normFpass2, ...
'DesignMethod', 'butter');
% Visualize the filter frequency response
fvtool(filter, 'Analysis', 'freq');
% Print filter coefficients
disp('Filter Coefficients:');
disp(filter.Coefficients);
Output
In the above figure, you can see the bandpass filter response of Figure 2 is flatter than that of Figure 1. When we increase a digital filter's order or length, we get better frequency responses.
In the above figures, you can observe that the frequencies of interest have higher magnitude (dB) values. Other frequencies are significantly attenuated. The filter frequencies can vary by +/- 3 dB in magnitude. So, it is called the 3dB bandwidth of the bandpass filter.
In the above figure, the sampling frequency is 1000 Hz, as defined in the MATLAB Code above. And the Nyquist frequency is 1000/2 = 500 Hz. You can calculate which frequency components are available in the above figures from this info. For example, in Figure 2, the filtered frequencies range from (Nyquist frequency)*0.1 to (Nyquist frequency)*0.4 or 50 Hz to 200 Hz. (Which is defined in the MATLAB code).