ts1 = idealfilter(ts, interval, filtertype)
ts1 = idealfilter(ts, interval, filtertype, index)
Ideal filters require data to have a mean of zero and prepare the data by subtracting its mean. You can restore the filtered signal amplitude by adding the mean of the input data to the filter output values.
Use the ideal notch filter when you want to remove variations in a specific frequency range. Alternatively, use the ideal pass filter to allow only the variations in a specific frequency range.
If the time-series data is sampled nonuniformly, filtering resamples this data on a uniform time vector.
NaNs in the time series are
interpolated before filtering, using the interpolation method you
assigned to the
The frequency interval (specified in cycles per time unit) at
which you want the ideal filter applied. To specify several frequency
intervals, use an n-by-2 array of start and end frequencies, where
A string specifying the type of filter you want to apply, either
An integer array that specifies the columns or rows to filter
Filters are ideal in the sense that they are not realizable. An ideal filter is noncausal and the ends of the filter amplitude are perfectly flat in the frequency domain.
This example first applies an ideal notch filter to the data in
count.dat. Then, it applies a pass filter to the data.
Load the count matrix into the workspace:
Create a timeseries object from column one of this matrix. Specify a time vector that ranges from 1 to 24 s in 1-s intervals.
count1 = timeseries(count(:,1),1:24);
Obtain the mean of the data:
countmean = mean(count1);
Enter the frequency interval, in hertz, for filtering the data:
interval = [0.08 0.2];
Invoke an ideal notch filter:
idealfilter_countn = idealfilter(count1,interval,'notch');
Compare the original data and the shaped data on a line plot:
plot(count1,'-.') grid on hold on plot(idealfilter_countn,'-')
Restore the mean to the filtered data and show it on the line plot, adding a legend and a title:
countn_restored = idealfilter_countn + countmean; plot(countn_restored,':') title('Notch Filter') legend('Original Data','Shaped Data','Mean Restored',... 'Location','NorthWest')
Close the Figure window:
Then, repeat the process using a
pass rather than a
figure plot(count1,'-.') grid on hold on idealfilter_countp = idealfilter(count1,interval,'pass'); plot(idealfilter_countp,'-') countp_restored = idealfilter_countp + countmean; plot(countp_restored,':') title('Pass Filter') legend('Original Data','Shaped Data','Mean Restored',... 'Location','NorthWest')