| MATLAB® | ![]() |
ts2 = filter(ts1,b,a)
ts2 = filter(ts1,b,a,Index)
ts2 = filter(ts1,b,a)
applies the transfer function filter
to the data in the timeseries object ts1.
b and a are the coefficient arrays of the transfer function numerator and denominator, respectively.
ts2 = filter(ts1,b,a,Index) uses the optional Index integer array to specify the columns or rows to filter. When ts.IsTimeFirst is true, Index specifies one or more data columns. When ts.IsTimeFirst is false, Index specifies one or more data rows.
The time-series data must be uniformly sampled to use this filter.
The following function
y = filter(b,a,x)
creates filtered data y by processing the data in vector x with the filter described by vectors a and b.
The filter function is a general tapped delay-line filter, described by the difference equation

Here, n is the index of the current sample, Na is the order of the polynomial described by vector a, and Nb is the order of the polynomial described by vector b. The output y(n) is a linear combination of current and previous inputs, x(n) x(n-1)..., and previous outputs, y(n-1) y(n-2)... .
You use the discrete filter to shape the data by applying a transfer function to the input signal.
Depending on your objectives, the transfer function you choose might alter both the amplitude and the phase of the variations in the data at different frequencies to produce either a smoother or a rougher output.
In digital signal processing (DSP), it is customary to write transfer
functions as rational expressions in
and to order the numerator and denominator terms in ascending
powers of
.
Taking the z-transform of the difference equation

results in the transfer function

where Y(z) is the z-transform of the filtered output y(n). The coefficients b and a are unchanged by the z-transform.
Consider the following transfer function:

You will apply this transfer function to the data in count.dat.
Load the matrix count into the workspace.
load count.dat;
Create a time-series object based on this matrix.
count1=timeseries(count(:,1),[1:24]);
Enter the coefficients of the denominator
ordered in ascending powers of
to represent
.
a = [1 0.2];
Enter the coefficients of the numerator to
represent
.
b = [2 3];
filter_count = filter(count1,b,a)
Compare the original data and the shaped data with an overlaid plot of the two curves:
plot(count1,'-.'), grid on, hold on
plot(filter_count,'-')
legend('Original Data','Shaped Data',2)

idealfilter (timeseries), timeseries, tsprops
![]() | filter | filter2 | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |