I am designing an FIR filter in Matlab using a Kaiser window.
I need to plot the filter's magnitude and phase responses with the x-axis as frequency in Hertz instead of plotting them with the normalized angular frequency. Doing this, the returned wn is equal to 0.34 (returned by kaiserord()
) , which when I convert it to Hertz it gives me 42.5 Hz as required.
My question is that when I plot the amplitude response, the -3dB point occurs at frequency above 100 Hz, which means that the cutoff frequency is not equal to 42.5 Hz. So what is wrong with my code? Here is the code (with the required filter specifications):
fs=250;
fcuts=[40 45]; % passband and stopband frequencies
mags=[1 0]; % The required filter amplitude in these bands (Absolute value not in dB)
devs=[0.23 0.23];% Passband and stopband ripples (Absolute value not in dB)
[N,wn,beta,ftype]=kaiserord(fcuts,mags,devs,fs); % using kaiser window for designing the fir filter . This function will return the cuttoff freq. , order of the filter , filter type and betta according to the design specs.
x=fir1(N,wn,ftype,kaiser(N+1,beta)); % designing the corresponding fir filter ( note that fir1 takes an even filter order so we wrote N+1)
[h w]=freqz(x)
f=[w*fs]/2
subplot(2,1,1);
plot(f,20*log10(abs(h))); % we will use 20log10() for ploting the mag. response in dB . abs(h) is the magnitude response
title('magnitude response')
grid on % turning the grid on
set(gca,'YTick',-80:5:0)
xlabel('Frequency(Hz)')
ylabel('Magnitude(dB)')
subplot(2,1,2);
plot(f,rad2deg(angle(h)));
title('phase response')
grid on
%set(gca,'YTick',-100:5:0)
xlabel('Frequency(Hz)')
ylabel('phase(degree)')
Edit : Does wn=0.34 corresponds to 42.5 Hz in the first place? Am I calculating it right?