I am using the Digital Filter with properties in MATLAB. I have defined the filter object filt(1)
as:
digitalFilter with properties:
Coefficients: [20x6 double]
Specifications:
FrequencyResponse: 'bandpass'
ImpulseResponse: 'iir'
SampleRate: 1000
PassbandFrequency1: 59.9000
PassbandRipple: 3
StopbandAttenuation2: 80
StopbandAttenuation1: 80
PassbandFrequency2: 60.0800
FilterOrder: 40
DesignMethod: 'ellip'
Similarly, I have other filters under filt object as filt(2)
, filt(3)
up to filt(8)
, each at different frequencies.
Now, for some reason, I get the error when my program tries to run the line:
Q = filter(filt(1),x);
where x
is a 600000 x 1
column vector with only positive and negative real values (resembling a long sine wave).
The error that I get is:
Subscript indices must either be real positive integers or logicals.
Error in digitalFilter/filter (line 870)
y = obj.FilterFunction(obj.Coefficients,x);
Could anyone please point out the problem?
EDIT:
The designfilt
command opens up an interactive interface where you can change and tune your filter requirements. I have optimized the filters, and saved the results as a .mat
file. (This whole program used to work, was part of a significant project which we completed succesfully, but after a year doesn't seem to work somehow).
I have attached the filter_8th.mat
file. There are various filters here. I have already created these filters before hand because MATLAB takes a lot of time to create these.
In this .mat
file, the filter objects are named as D_n1_50
, D_n1_60
, D_sig50
, D_sig60
etc. (easily recognizable from the Workspace.)
The line of code that assigns these filter to the variable filt
is, for example: filt = D_sig50
. This is being selected in a loop. Which filter will be selected depends on a conditional if-else structure.
The .mat
file containing "filters" and the variable x
are in this dropbox link:
x
with your exact dimensons withrand([600000 1])
and there is no error at all. Maybe you should add to the question the lines where you create thatx
, as that seems to be the problem. Also, you could post how you declare thefilt(1)
object. $\endgroup$ – Tendero Mar 3 '17 at 21:28x
and everything works fine. Post your whole code so we can check where the problem is. $\endgroup$ – Tendero Mar 4 '17 at 14:03