Hi Sadi,
As per my understanding, you want to design a three-pole continuous-time Butterworth lowpass filter and visualize its zeros and poles. You then plan to convert it into a discrete-time filter, transform it into a bandpass filter, and finally, plot the magnitude responses of all filters.
The code provided works fine. Since, the number of poles required in the filter is three, using ‘N=3’ should indeed be appropriate.
Please follow the below mentioned steps to convert the low pass filter to a discrete-time filter, then to a bandpass filter, and plot the filter responses.
- To plot the poles and zeros in a square plane, you can utilize the 'zplane' function. Here's the corresponding code snippet for your reference:
zplane(b,a); % ‘a’ and ‘b’ are filter coefficients
2. The ‘bilinear’ function can be used to convert continuous-time filter to a discrete-time filter. Please refer to the code snippet below:
% Sampling frequency
fs = 1000; % adjust as needed
% Convert to discrete-time filter
[bd,ad] = bilinear(b,a,fs);
3. The ‘lp2bp’ function can be used to convert the lowpass filter into a bandpass filter. Please refer to the code snippet below:
% Desired bandpass frequencies
W0 = 500; % center frequency, adjust as needed
BW = 200; % bandwidth, adjust as needed
% Transform lowpass to bandpass
[bb,ab] = lp2bp(bd,ad,W0,BW);
4. The ‘freqz’ function returns the frequency response of the filter in the form of complex numbers. The 'abs' function can be used to obtain the magnitude, and the 'plot' function can be used to depict the magnitude response. Please refer to the code snippet below:
% Frequency response of bandpass filter
[Hb,Omegab] = freqz(bb,ab,2048,fs);
plot(Omegab/pi, abs(Hb));
Please refer to the following documentations of ‘zplane’, ‘bilinear’, ‘lp2bp’, ‘freqz’ and ‘plot’ functions for more information:
- ‘zplane’: https://www.mathworks.com/help/dsp/ref/dsp.allpassfilter.zplane.html
- ‘bilinear’: https://www.mathworks.com/help/signal/ref/bilinear.html
- ‘lp2bp’: https://www.mathworks.com/help/signal/ref/lp2bp.html
- ‘freqz’: https://www.mathworks.com/help/signal/ref/freqz.html
- ‘plot’: https://www.mathworks.com/help/matlab/ref/plot.html
Hope this helps!