how to design a FIR filter.

6 Ansichten (letzte 30 Tage)
paul
paul am 12 Mai 2011
Kommentiert: AJAY KUMAR am 29 Mai 2014
DESING OF FIR FILTER WITH BOTH HAMMING AND BLACKMAN WINDOW METHOD

Antworten (2)

Emanuel
Emanuel am 12 Mai 2011
Hello Paul,
I think it can help you!
__________________________________________________
function [b,a] = my_fir_emanuel(Ap,As,fc,fs,Fs)
close all
%This routine will be used to obtain the coefficient of a FIR filter.
%After entering the required parameters the type of filter (low pass,
%high pass, band-pass or band-stop) and the window function is
%automatically selected.
%For details on FIR filter specifications recommended reading the book
% E.C. Ifeachor, Digital Signal Processing - A Pratical Approach,
%Pearson Education, 2ª Edition, 2002.
%Especificações do Filtro FIR (FIR Filter Specifications
)
% fc = [fc1 fc2]
% fs = [fs1 fs1]
% Ap [1x1]
% As [1x1]
% Fs [1x1]
%Obs.: fc2 e fs2 apenas para filtros passa-faixa ou rejeita-faixa
Note: fc2 and fs2 only for band-pass filters or band-stop.
%Frequencia normalizada(Normalized Frequency)
fcn = fc/Fs;
fsn = fs/Fs;
f0n = 1000/Fs;
%Faixa de transição(Transition range)
df= abs(fc(1)-fs(1));
dfn= df/Fs;
%Seleciona a função janela (select de window function)
%
if As<=21 && Ap>=0.7416
N=ceil(0.9/dfn);
w=rectwin(N);%Função ajanelamento(Window Function)
disp('Rectangular Window Chosen')
elseif As<=44 && Ap>=0.0546
N=ceil(3.1/dfn) %a função ceil aredonda os coeficientes para mais ex: 3.2 aredonda para 4
w = hanning(N);%Função de Ajanelamento
disp('Hanning window chosen')
elseif As<=53 && Ap>=0.0194
N=ceil(3.3/dfn)
w = hamming(N);%Função de Ajanelamento
disp('Hamming window chosen')
elseif As<=75 && Ap>=0.0017
N=ceil(5.5/dfn)
w = blackman(N);%Função de Ajanelamento
disp('Blackman window chosen')
elseif As<90 && Ap>=0.000275
N=ceil(4.71/dfn)
w = kaiser(N);%Função de Ajanelamento
disp('Kaiser window chosen')
end
n= 1: (N-1)/2;
% Função resposta ao impulso ideal
% Selects the filter type
%Low-Pass Filter
if fc(1)<fs(1)&& length(fc)==1
hi0= 2*fcn(1);
hip = (2*fcn(1)*sin(2*pi*fcn(1)*n)./(2*pi*fcn(1)*n));
hin = fliplr(hip);
hi = [hin hi0 hip];
stem(hi)
disp('Low-Pass Filter selected')
%High-Pass Filter
elseif fc(1)>fs(1) && length(fc)==1
if length(fc)==2
hi0= 1-2*fcn(1);
hip = (-2*fcn(1)*sin(2*pi*fcn(1)*n)./(2*pi*fcn(1)*n));
hin = fliplr(hip);
hi = [hin hi0 hip];
stem(hi)
disp('High-Pass Filter Selected')
end
%Band-Stop Filter
elseif (length(fc)==2) && (length(fs)==2)
if fc(1)<fs(1)&& fc(2)>fs(2) && (length(fc)==2)
hi0= 1-2*(fcn(2)-fcn(1));
hip = (2*fcn(1)*sin(2*pi*fcn(1)*n)./(2*pi*fcn(1)*n))-(2*fcn(2)*sin(2*pi*fcn(2)*n)./(2*pi*fcn(2)*n));
hin = fliplr(hip);
hi = [hin hi0 hip];
stem(hi)
disp('Band-Stop Filter Selected')
end
%Band-Pass Filter
elseif (length(fc)==2) && (length(fs)==2)
if fc(1)>fs(1)&& fc(2)<fs(2) %&&
hi0= 2*(fcn(2)-fcn(1));
hip = (2*fcn(2)*sin(2*pi*fcn(2)*n)./(2*pi*fcn(2)*n))-(2*fcn(1)*sin(2*pi*fcn(1)*n)./(2*pi*fcn(1)*n));
hin = fliplr(hip);
hi = [hin hi0 hip];
stem(hi)
disp('Band-Pass Filter Selected')
end
disp(' ')
disp(' ')
elseif fc(1)>fs(1)& fc(2)> fs(2)
error('Impossível selecionar o tipo de filtro com os dados de entrada fc e fs.Digite: Help my_fir_emanuel para instruções')
elseif fc(1)==0 & fc(2)==1
error('Unable to select filters with the input data')
elseif fs(1)==0 & fs(2)==1
error('Unable to select filters with the input data')
end
%if size(hi,1)
% Desired impulse response function
if length(hi) == length(w)
b = hi.*w';
a=1;
figure(1)
stem(b)
figure(2)
freqz(b,a,1000,Fs);
%error('Impossível determinar a resposta em frequência para os parâmetros escolhidos')
end

Wayne King
Wayne King am 28 Jan. 2012
You can use fdesign
You do not give any information about your filter. Here is a lowpass filter with a cutoff frequency of 0.2 radians/sample and an order of 20.
d = fdesign.lowpass('N,Fc',20,0.2);
Hd1 = window(d,'window',@hamming);
Hd2 = window(d,'window',@blackman);
  1 Kommentar
AJAY KUMAR
AJAY KUMAR am 29 Mai 2014
how to design without using rectwin function....

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by