Why is my loop not working?
4 views (last 30 days)
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:
Error using ellip (line 60)
Wn must be a one or two element vector.
Error in total_power (line 19)
My code is as follows:
for k=1:100 %%here loop runs for 100 times since a goes from 50 to 5000
PowerW=rms(x_h)^2; %RMS formula
%%%%%%Figure of Merit%%%%%%
Please help! Thanks!
Stephen23 on 21 Jul 2021
Edited: Stephen23 on 21 Jul 2021
Look closely at the variable a:
At the start of the first iteration a = 0, to which you add 50. However you then completely replace that variable a with an entirely different one (the second output from ELLIP, which is a vector of transfer function coefficients of the filter).
After that it appears that you assume that a is still as scalar, whereas in fact you have replaced it with a vector.