2
votes

I am trying to plot the frequency response of my sequence when filtered by a butterworth, low-pass filter. I have my pole and zero plot figured out just fine but can't seem to get my frequency response plotted correctly. When I do my axis are always way out of scale. I've tried using Matlab's bode function to no avail. A sample input that I have been using would be something like this buttdes(1000, 2500, -3, -20, 20000). Any help is much appreciated!! Here is my code so far :

function buttdes(fpass, fstop, dp, ds, fs)

%// Design a discrete-time Butterworth filter

%// BUTTDES(fpass, fstop, dp, ds, fs) designs and plots the bode plot

%// of the resulting analog-equivalent filter that has been

%// designed to match the analog parameters fpass (in Hz),

%// fstop (in Hz), dp (in dB) and ds (in dB).

%// fs is the sample rate in Hz

wp = fpass/fs;        
ws = fstop/fs;
WpT = 2 * tan(wp / 2);
WsT = 2 * tan(ws / 2);
qp = log10(10^-(dp/10)-1);
qs = log10(10^-(ds/10)-1);

N = ceil((qs-qp) / 2 / log10(WsT / WpT)); 
WcT = WpT * 10^(-qp/2/N);

k = 0:N-1;
skT = WcT * exp(j*pi*(2*k+N+1)/2/N);

b = real(prod(skT./(skT -2))) * poly(-ones(1, N));
a = real(poly(-(skT+2)./(skT-2)));

zplane(b, a);
1
@Benoit_11 zplane is my pole-zero plot.KarmaPimp
How did you try plotting frequency response? freqz(b,a) works fine.Navan
@Navan Sorry for the late response. I tried using freq. but my axis were still not getting formatted rightKarmaPimp

1 Answers

2
votes

To expand on the comment by Navan, you can use the freqz command to compute and plot the frequency response of the filter. freqz is in the Signal Processing Toolbox, so if you don't have that toolbox, you'll need another method.

freqz normally makes two plots: (1) one plot of the amplitude response and (2) one plot of the phase response. If you just want the amplitude response, you can plot it like this

%compute the filter response
npoints = 1000;  %how many points to you want?   
[h,f]=freqz(b,a,npoints,fs);
response_dB = 10.*log10(h.*conj(h));
response_deg = 180/pi*angle(h);

% make plot
figure;
semilogx(f,response_dB);
xlabel('Frequency (Hz)');
ylabel('Response (dB)');