Why is my loop not working?
Afficher commentaires plus anciens
Hi,
I have a code, where I am using elliptical bandpass filter and trying to filter some signals and calculate total power for them, and this should happen for cut-off frequency starting from 50 upto 5000 with a step size of 50. My code works fine if I run for each frequency seperately, but when I run inside all loops to get values all at once, I receive this problem:
>>Total_power
2.5945
Error using ellip (line 60)
Wn must be a one or two element vector.
Error in total_power (line 19)
[b,a]=ellip(1,20,25,[a 5000]/(fs/2),'bandpass');
My code is as follows:
close all;
%Filter design
a=0;
b=10;
%x=zeros[];
for k=1:100 %%here loop runs for 100 times since a goes from 50 to 5000
a=a+50;
[b,a]=ellip(1,20,25,[a 5000]/(fs/2),'bandpass');
% 2
y2=audioread('2.mp3');
y_h2=filter(b,a,y2);
power2=rms(y_h2)^2;
% 3
y3=audioread('3.mp3');
y_h3=filter(b,a,y3);
power3=rms(y_h3)^2;
%Power calculations
PowerN=((0.14*power2)+(0.14*power3))/2;
%%%%%%%%%%%
[x,fs]=audioread('fr1.mp3');
x_h=filter(b,a,x);
PowerW=rms(x_h)^2; %RMS formula
%%%%%%Figure of Merit%%%%%%
Total_power= PowerW/PowerN;
disp(Total_power)
end
Please help! Thanks!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Digital Filter Analysis 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!