Trying to use for loop to create an array of bandpass filters, but gets error “conversion to double from dfilt.df2sos is not possible”
I have been trying to use a for loop to generate an array of bandpass filters using the dfilt.df2sos command in order to minimise numerical errors, and then using fvtool to analyze the filters. However, when running the command I keep running into the error "Unable to perform assignment because value of type ‘dfilt.df2sos’ is not convertible to ‘double’." on line bppf(i) = dfilt.df2sos(s,g);. I suspect this is probably due to how I initialised the array bppf, but I can’t seem to find a workaround for this. I am also trying to use the web browser to run this code, but I’m not sure if that’s really the cause of the problem. Any help would be much appreciated thank you.
Edit: I realised I accidentally missed out on variables ap and as when copying and pasting my code
fs = 48000; % sample frequency
wss1 = [5680 2840 1420 710 355 177 88 44]*2*pi/fs;
wss2 = [11360 5680 2840 1420 710 355 177 88 44]*2*pi/fs;
wpp1 = 0.9*[8000 4000 2000 1000 500 250 125 63]*2*pi/fs;
wpp2 = zeros(8);
dp = 0.05;
ds = 0.05;
% peak passband ripple and minimum stopband attenuation in dB
ap = -20*log10(1-dp); as = -20*log10(ds);
% append wpp2
for i = 1:length(wpp2)
wpp2(i) = wss1(i)*wss2(i)/wpp1(i);
end
% design of prototype butteworth bandpass filter
bppf = zeros(8);
for i = 1:8
% bandedge frequencies for analog filter (T=1)
omp1 = 2*tan(wpp1(i)/2);
omp2 = 2*tan(wpp2(i)/2);
oms1 = 2*tan(wss1(i)/2);
oms2 = 2*tan(wss2(i)/2);
% filter design
[N Wn] = buttord([omp1/pi omp2/pi],[oms1/pi oms2/pi],ap,as);
[z,p,k] = butter(N,Wn,’bandpass’);
[s,g] = zp2sos(z,p,k);
bppf(i) = dfilt.df2sos(s,g);
end
fvtool(bppf(1),bppf(2),bppf(3),bppf(4),bppf(5),bppf(6),bppf(7),bppf(8))I have been trying to use a for loop to generate an array of bandpass filters using the dfilt.df2sos command in order to minimise numerical errors, and then using fvtool to analyze the filters. However, when running the command I keep running into the error "Unable to perform assignment because value of type ‘dfilt.df2sos’ is not convertible to ‘double’." on line bppf(i) = dfilt.df2sos(s,g);. I suspect this is probably due to how I initialised the array bppf, but I can’t seem to find a workaround for this. I am also trying to use the web browser to run this code, but I’m not sure if that’s really the cause of the problem. Any help would be much appreciated thank you.
Edit: I realised I accidentally missed out on variables ap and as when copying and pasting my code
fs = 48000; % sample frequency
wss1 = [5680 2840 1420 710 355 177 88 44]*2*pi/fs;
wss2 = [11360 5680 2840 1420 710 355 177 88 44]*2*pi/fs;
wpp1 = 0.9*[8000 4000 2000 1000 500 250 125 63]*2*pi/fs;
wpp2 = zeros(8);
dp = 0.05;
ds = 0.05;
% peak passband ripple and minimum stopband attenuation in dB
ap = -20*log10(1-dp); as = -20*log10(ds);
% append wpp2
for i = 1:length(wpp2)
wpp2(i) = wss1(i)*wss2(i)/wpp1(i);
end
% design of prototype butteworth bandpass filter
bppf = zeros(8);
for i = 1:8
% bandedge frequencies for analog filter (T=1)
omp1 = 2*tan(wpp1(i)/2);
omp2 = 2*tan(wpp2(i)/2);
oms1 = 2*tan(wss1(i)/2);
oms2 = 2*tan(wss2(i)/2);
% filter design
[N Wn] = buttord([omp1/pi omp2/pi],[oms1/pi oms2/pi],ap,as);
[z,p,k] = butter(N,Wn,’bandpass’);
[s,g] = zp2sos(z,p,k);
bppf(i) = dfilt.df2sos(s,g);
end
fvtool(bppf(1),bppf(2),bppf(3),bppf(4),bppf(5),bppf(6),bppf(7),bppf(8)) I have been trying to use a for loop to generate an array of bandpass filters using the dfilt.df2sos command in order to minimise numerical errors, and then using fvtool to analyze the filters. However, when running the command I keep running into the error "Unable to perform assignment because value of type ‘dfilt.df2sos’ is not convertible to ‘double’." on line bppf(i) = dfilt.df2sos(s,g);. I suspect this is probably due to how I initialised the array bppf, but I can’t seem to find a workaround for this. I am also trying to use the web browser to run this code, but I’m not sure if that’s really the cause of the problem. Any help would be much appreciated thank you.
Edit: I realised I accidentally missed out on variables ap and as when copying and pasting my code
fs = 48000; % sample frequency
wss1 = [5680 2840 1420 710 355 177 88 44]*2*pi/fs;
wss2 = [11360 5680 2840 1420 710 355 177 88 44]*2*pi/fs;
wpp1 = 0.9*[8000 4000 2000 1000 500 250 125 63]*2*pi/fs;
wpp2 = zeros(8);
dp = 0.05;
ds = 0.05;
% peak passband ripple and minimum stopband attenuation in dB
ap = -20*log10(1-dp); as = -20*log10(ds);
% append wpp2
for i = 1:length(wpp2)
wpp2(i) = wss1(i)*wss2(i)/wpp1(i);
end
% design of prototype butteworth bandpass filter
bppf = zeros(8);
for i = 1:8
% bandedge frequencies for analog filter (T=1)
omp1 = 2*tan(wpp1(i)/2);
omp2 = 2*tan(wpp2(i)/2);
oms1 = 2*tan(wss1(i)/2);
oms2 = 2*tan(wss2(i)/2);
% filter design
[N Wn] = buttord([omp1/pi omp2/pi],[oms1/pi oms2/pi],ap,as);
[z,p,k] = butter(N,Wn,’bandpass’);
[s,g] = zp2sos(z,p,k);
bppf(i) = dfilt.df2sos(s,g);
end
fvtool(bppf(1),bppf(2),bppf(3),bppf(4),bppf(5),bppf(6),bppf(7),bppf(8)) filter, transfer function MATLAB Answers — New Questions