Documentation Center

  • Trial Software
  • Product Updates

idealfilter

Class: timeseries

Apply ideal (noncausal) filter to timeseries object

Syntax

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

Description

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.

Tips

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

Input Arguments

ts

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

interval

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.

filtertype

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

index

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

Output Arguments

ts1

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

Definitions

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

Examples

expand all

Apply Ideal Notch and Pass Filters

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:

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:

close

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

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')

See Also

|

Was this topic helpful?