Hi @ Hanlin Wang,
You mentioned, “ 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);”
You did not provide full code by not defining parameters for variables ap and as in the code provided by you.
% filter design [N Wn] = buttord([omp1/pi omp2/pi],[oms1/pi oms2/pi],ap,as);
These variables typically represent the maximum allowable passband ripple and the minimum stopband attenuation, respectively. However, I defined them by using synthetic numbers and was able to execute the code with no problems, please see attached.
![](/matlabcentral/answers/uploaded_files/1780550/IMG_7940.jpeg)
After analyzing error you encountered while trying to create an array of bandpass filters using the dfilt.df2sos command in MATLAB, it indicates a type mismatch when attempting to assign a filter object to a numeric array. This issue raised from the initialization of the bppf array. So, in MATLAB, when you initialize bppf as a numeric array using zeros(8), it can only hold numeric values, not objects like dfilt.df2sos. To resolve this, you should initialize bppf as a cell array, which can store different types of data, including objects. Here’s how you can modify your code:
bppf = cell(1, 8); % Initialize bppf as a cell array 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); % Store the filter object in the cell array end fvtool(bppf{1}, bppf{2}, bppf{3}, bppf{4}, bppf{5}, bppf{6}, bppf{7}, bppf{8});
By using a cell array, you can successfully store the filter objects and analyze them with fvtool. Additionally, make sure that your MATLAB environment is properly set up, as running code in a web browser may introduce other limitations.
Please let me know if this helped resolved your problem.