Arrays have incompatible sizes for firpm() function.

I have two 1X15 arrays, included in the attached file.
There is a frequency array and response array.
If you plot(frequency,response), you should be able to visualize the function I am trying to fit.
First I define the variables "frequency" and "response" as the arrays attached.
frequency=[0.1, 0.2, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
response=[0.0342, 0.0744, .2451, .6944, 1.2715, 1.9350, 3.4740, 5.2542, 7.0560, 8.7253, 10.3268, 11.2043, 12.4141, 12.6797, 12.9498];
Next I try to fit a 5th order differential filter to this data:
coeff = firmpm(5,frequency,response,'differentiator');
The error response is "arrays have incompatible sizes for this operation
I am not aware of a size restriction on the arrays, am I missing something here?
Any insight into what could be wrong here?

 Accepted Answer

The ‘frequency’ and ‘response’ vectors must be the same lengths, and they must have even numbers of elements (according to the documentation). The frequency vector must be on the interval (0,1) so dividing it by the maximum value (the end value would also work) of the ‘frequency’ vector forces that requirement.
This works, however you may need to make changes to the vectors to get the result you want —
frequency=[0.1, 0.2, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
frequency = 1×14
0.1000 0.2000 0.5000 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000
response=[0.0342, 0.0744, .2451, .6944, 1.2715, 1.9350, 3.4740, 5.2542, 7.0560, 8.7253, 10.3268, 11.2043, 12.4141, 12.6797] % 12.9498]
response = 1×14
0.0342 0.0744 0.2451 0.6944 1.2715 1.9350 3.4740 5.2542 7.0560 8.7253 10.3268 11.2043 12.4141 12.6797
coeff = firpm(5,frequency/max(frequency),response,'differentiator');
figure
freqz(coeff, 1, 2^16)
,

2 Comments

This is one of those moments when "reading the documentation" is the the answer.
Thank you for spelling it out for me.
Much Appreciated!

Sign in to comment.

More Answers (0)

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!