how can i put the type de fir1 window as input in fuction?
2 views (last 30 days)
Show older comments
I have a function which calculates the filter coefficients,return the frequency response .... But i want to see the difference between each type of window. my function is called like this:
[c1 c9 MGhann] =CalculateFilterCoeff(N,D,hann(N),hann(N-1))
and the function is :
%----------------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------------
function [c1 c9 MargeGain] = CalculateFilterCoeff(Nelec,DinterElec,windtype1,windtype2)
w1= windtype1
w2= windtype2
%%calcul des coefficients des fitres utilisant fir1
c1 =fir1(Nelec-1,2*95*DinterElec,'low',w1);
c9 =fir1(Nelec-2,2*95*DinterElec,'high',w2);
%%Dessin des réponse fréquentielle des filtres appliqués
[h1 w1]=freqz(c1*sqrt(2),1,512);
[h9 w2]=freqz(c9*sqrt(2),1,512);
%%calcul du marge de gain entre Filtre passe-bas et passe-haut
MargeGain = []
y=find(f9>=50, 1, 'first')
MargeGain(1)=20*log10(abs(h9(y)))
end
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %------------------------------------------------------------------------------------------------------------------------------------------------------------------------
THE PROBLEM is that i want to prevent to prevent to specify the window length (N) because in my function i want it with different length depending on the value of N. So if N is even: [c1 c9 gain] =CalculateFilterCoeff(N,D,window(N),window(N-1)) else % N is odd [c1 c9 gain] =CalculateFilterCoeff(N,D,window(N),window(N))
I can't but the type of window alone such as [c1 c9 gain] =CalculateFilterCoeff(N,D,hann) and inside the function deside which is the length because it returns that error message: ??? Error using ==> hann at 15 Not enough input arguments.
Thanks for helping to solve this problem
5 Comments
Accepted Answer
Wayne King
on 12 Dec 2013
Edited: Wayne King
on 12 Dec 2013
function [c1 c9] =CalculateFilterCoeff(N,D,windtype1)
if (mod(N,2) == 0)
w1= feval(windtype1,N);
w2= feval(windtype1,N-1);
else
w1= feval(windtype1,N);
w2= feval(windtype1,N);
end
c1 =fir1(N-1,2*95*D,'low',w1); % Fcn=Fc*2/Fsech = Fc*2*d
c9 =fir1(N-2,2*95*D,'high',w2);
end
Then call the function like this:
N = 20;
D = 0.003;
[c1 c9 ] = CalculateFilterCoeff(N,D,@hann);
[c1 c9 ] = CalculateFilterCoeff(N,D,@hamming);
Note I removed the MargeGain part because you had some problems there.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!