how can i put the type de fir1 window as input in fuction?

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 commentaires

Can you please show how you are calling CalculateFilterCoeff() at the command line?
Show us what kind of input values you want to give it. I don't understand your post as it currently stands.
for this moment i'm calling it like this :
[c1 c9 MGhann] = CalculateFilterCoeff(N,D,hann(N),hann(N-1))
suppose that i defined N=20, D=3e-3 what i need to use the window type as input arfument without the N value, i want it inside the function. so
function [c1 c9 MargeGain] =CalculateFilterCoeff(Nelec,DinterElec,windtype1)
if mod(N,2) == 0
w1= windtype1(N)
w2= windtype1(N-1)
else
w1= windtype1(N)
w2= 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
so where is the windtype1 function? We need to see that.
its in that line where is written :
w1=windtype1(N)
then i use it for the fir1
c1 =fir1(N-1,2*95*D,'low',w1)
Maria
Maria le 12 Déc 2013
Modifié(e) : Maria le 12 Déc 2013
lets make it more simple, if i have that function:
function [coef]= CalFilterCoef(N,D,windtype1)
w1=windtype1(N)
c1 =fir1(N-1,2*95*D,'low',w1);
[h1 w1]=freqz(c1*sqrt(2),1,512);
end
when i want to call it by writing in the command window :
CalFilterCoef(20,3e-3,hann)
I have that error ! ??? Error using ==> hann at 15 Not enough input arguments.
I dont want to put the length of window in the function thanks

Connectez-vous pour commenter.

 Réponse acceptée

Wayne King
Wayne King le 12 Déc 2013
Modifié(e) : Wayne King le 12 Déc 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.

1 commentaire

Thank you very much i like this solution ! But i solved it too by declaring the input argument windtype as char ('hann') then i created another m file which uses a switch case of all window type. But urs is easier :) Thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by