This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Class: timeseries

Apply ideal (noncausal) filter to timeseries object


ts1 = idealfilter(ts, interval, filtertype)
ts1 = idealfilter(ts, interval, filtertype, index)


ts1 = idealfilter(ts, interval, filtertype) applies an ideal filter of filtertype to one or more frequency intervals that interval specifies for the timeseries object, ts.

ts1 = idealfilter(ts, interval, filtertype, index) applies an ideal filter and uses the optional index integer array to specify the columns or rows to filter.

Input Arguments


The timeseries object to which you want to apply an ideal filter.


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 n represents the number of intervals.


A string specifying the type of filter you want to apply, either pass or notch.


An integer array that specifies the columns or rows to filter when ts.IsTimeFirst is true.

Output Arguments


The timeseries object that results when you apply an ideal filter to the original timeseries object.


expand all

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:

load count.dat

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:

grid on
hold on

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;
title('Notch Filter')
legend('Original Data','Shaped Data','Mean Restored',...

Close the Figure window:


Then, repeat the process using a pass rather than a notch filter:


grid on
hold on

idealfilter_countp = idealfilter(count1,interval,'pass');

countp_restored = idealfilter_countp + countmean;

title('Pass Filter')
legend('Original Data','Shaped Data','Mean Restored',...


expand all


  • 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.

  • All NaNs in the time series are interpolated before filtering, using the interpolation method you assigned to the timeseries object.

See Also


Introduced before R2006a

Was this topic helpful?