# FIR filter design in matlab using Kaiser window (using 'fir1' and 'designfilt')

Here are the specs for FIR filter using Kaiser window.

Ap = 0.2   %Maximum Passband ripple
Aa = 20    %Minimum stopband attenuation
Wp1 = 500  %Lower passband edge
Wp2 = 1000 %Upper passband edge
Wa1 = 200  %Lower stopband edge
Wa2 = 1200 %Upper stopband edge
Ws = 3200  %Sampling frequency


I used two methods. designfilt function and kaiserord with fir

Code using designfilt

Ap = 0.2;   %Maximum Passband ripple
Aa = 20;    %Minimum stopband attenuation
Wp1 = 500;  %Lower passband edge
Wp2 = 1000; %Upper passband edge
Wa1 = 200;  %Lower stopband edge
Wa2 = 1200; %Upper stopband edge
Ws = 3200;  %Sampling frequency

fp1 = Wp1/(2*pi);
fp2 = Wp2/(2*pi);
fa1 = Wa1/(2*pi);
fa2 = Wa2/(2*pi);
fs = Ws/(2*pi);

bpFilt = designfilt('bandpassfir','PassbandFrequency1',fp1, ...
'PassbandFrequency2',fp2, 'StopbandFrequency1',fa1, ...
'StopbandFrequency2',fa2, 'SampleRate',fs, ...
'PassbandRipple',Ap,'StopbandAttenuation1',Aa, 'StopbandAttenuation2',Aa,...
'DesignMethod','kaiserwin');
h = fvtool(bpFilt);

filtord(bpFilt) %Order of the filter
[b,a]=tf(bpFilt);


Code using kaiserord with fir

fcuts = [fa1 fp1 fp2 fa2];  %Band edges
mags = [0 1 0];     %Desired amplitudes on bands defined by fcuts

deltaP = (10^(0.05*Ap)-1)/(10^(0.05*Ap)+1); %Passband ripple
deltaA = 10^(-0.05*Aa);  %Stopband ripple

errors = [deltaA deltaP deltaA];    %maximum allowable error in each frequency band

%Order n, frequency vector Wn, multiband magnitude type ftype, and the Kaiser window parameter beta
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,errors,fs);

bpFilt = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');   %length of window = filter order + 1


Problem is that coefficients in bpFiltfrom 2nd method are not the same as bin 1st.

Refer following:

Why is that happening?

• and how do they differ? Are the filter orders the same? Can you add a plot with both of them? Jun 5, 2017 at 16:56
• @MarcusMüller Yes. For filter order I get 35. But transfer function coefficients are not the same.
– Sndn
Jun 6, 2017 at 8:08
• to repeat myself: 1. and how do they differ? as well as 2. Can you add a plot with both of them? Jun 6, 2017 at 8:47
• @MarcusMüller Coefficient values are different. Check the two images.
– Sndn
Jun 10, 2017 at 5:57
• .... oh, really. How do they differ? Are they scaled? Where's the plot I'm asking for thrice? Jun 10, 2017 at 6:50