# Fir filter not working according to frequency response

I have designed a FIR filter with following parameters

fs=30,
f_pass1 = 1, stop1 = 0.5, f_pass2 = 3, f_stop2 = 4,
A_pass = 1,A_stop = 40

Here is code :

fs_filter=30;

f_pass1 = 1; %1.2
f_stop1 = 0.5;%0.7

f_pass2 = 3;
f_stop2 = 4; %6

A_pass = 1;
A_stop = 40;

del_f1 = -f_stop1 + f_pass1;
del_f2 = f_stop2-f_pass2;

del_f = min(del_f1,del_f2);

fc1 = f_pass1 -(( del_f)/2);
fc2 = f_pass2 +( (del_f)/2);

w_c1 = (2*pi*fc1)/(fs_filter);
w_c2 = (2*pi*fc2)/(fs_filter);

S_pass = ((10^(A_pass/20))-1)/((10^(A_pass/20))+1);
S_stop = 10^(-A_stop/20);

S = min(S_pass ,S_stop);

A = -20*log10(S)

alpha =0;
D = 0.922;

if A > 21 && A < 50
alpha = 0.5842*((A-21)^0.4)+0.07886*(A-21);
D = (A-7.95)/14.35;
elseif A>=50
alpha = 0.1102*(A-8.7);
D = (A-7.95)/14.35;
end

N = floor(((D*fs_filter)/del_f)+1);

N = N + mod(N-1,2)

M = (N-1)/2;

coeff= zeros(1,N);
w   = zeros (1,N);
d   = zeros (1,N);

for i=0:N-1
x_b= sqrt(1-(((i-M)/M)^2));

w(i+1) = besseli(0,(alpha*x_b))/besseli(0,alpha);

if i ~= M
d(i+1) =((w_c2/pi)*(sin(w_c2*(i-M)))/(w_c2*(i-M)))-((w_c1/pi)*(sin(w_c1*(i-M)))/(w_c1*(i-M)));
coeff(i+1) = w(i+1)*d(i+1);
else
d(i+1) = ((w_c2-w_c1)/pi);
coeff(i+1) = w(i+1)*d(i+1);
end

end

fft_coeff = abs(fft(coeff));
num_bins = length(fft_coeff);
bins = 0 : num_bins-1;
bin_Hz = bins*fs_filter/num_bins;
N_2 = ceil(num_bins/2);

plot(bin_Hz(1:N_2) , fft_coeff(1:N_2),'x');

but when i am convoluting it with the sin wave of say frequency f ( 0.1 to 5) sampled at fs = 50 the output of the signal is not actually following the response.

Code for generating signal :-

fs=50;
f0 = 0.6593;
cyc = 50;
t = 0:1/fs:cyc/f0;
x = sin(2*pi*f0*t);
y = conv(x,coeff,'valid');

am i missing something ?

• The sampling frequency you used to specify the filter, and that used to create the input signal, must be the same. – MBaz Jul 10 '15 at 14:18

\begin{align}f_{s1}&=0.5/30=0.017\\ f_{p1}&=1/30=0.033\\ f_{p2}&=3/30=0.1\\ f_{s2}&=4/30=0.133\end{align}
And the normalized frequency of your sinusoidal input signal is $0.6593/50\approx 0.013$, which is smaller than $f_{s1}$, so it's in the filter's stop band.