Language Reference

DFFILT Function

DFFILT (x, b, a) ;

DFFILT (x, z, p, k) ;

This function is supported by the IML procedure and the iml action.

The DFFILT function filters a time series by using a digital filter’s transfer function. You can use the DFDESIGN subroutine to compute the numerator and denominator coefficients, zeros, poles, and gain of a filter’s transfer function. You can choose to use either the transfer function’s numerator and denominator coefficients or its zeros, poles, and gain to filter the data. The output time series has the same length as the input time series.

The input arguments to the DFFILT function are as follows:

x

specifies the input data vector. It can be either a column vector or a row vector. Any missing value in this vector is replaced with 0.

b

is a vector that specifies the numerator polynomial coefficients of the digital filter’s transfer function. It can be a column vector or a row vector.

a

is a vector that specifies the denominator polynomial coefficients of the digital filter’s transfer function. It can be a column vector or a row vector.

z

is a matrix that contains the zeros of the digital filter’s transfer function. It can be a two-column matrix or a two-row matrix. When z is a two-row matrix, each column represents one zero value whose real part is in the first row and whose imaginary part is in the second row. When z is a two-column matrix, each row represents one zero value, which is a complex number whose real part is in the first column and whose imaginary part is in the second column. If z is a 2 times 2 matrix, each column represents one zero value.

p

is a matrix that contains the poles of the digital filter’s transfer function. It can be a two-column matrix or a two-row matrix. When p is a two-row matrix, each column represents one pole value whose real part is in the first row and whose imaginary part is in the second row. When p is a two-column matrix, each row represents one pole value, which is a complex number whose real part is in the first column and whose imaginary part is in the second column. If p is a 2 times 2 matrix, each column represents one pole value.

k

is a scalar that specifies the gain of the digital filter’s transfer function.

The DFFILT function returns the filtered data that are column vectors of the same length as the input data.

The following example shows how to use a DFDESIGN call to get the desired lowpass filter transfer function and then use the DFFILT function to filter an input signal. First an input signal (which is the sum of two sinusoidal signals, with frequencies f1 = 20 Hz, f2 = 80 Hz and sampling frequency samp_freq = 800 Hz) is generated. The Nyquist frequency of this signal is 400 Hz, and the normalized frequencies of the two sinusoids are StartFraction 20 Over 400 EndFraction = 0.05 and StartFraction 80 Over 400 EndFraction = 0.2. Then you use the DFDESIGN call to design a lowpass filter whose normalized cutoff frequency is 0.125. Finally, you use the DFFILT function to apply a lowpass filter to the input signal. Only the sinusoidal signal whose normalized frequency is 0.05 is in the output; the other sinusoidal signal, whose normalized frequency is 0.2, is filtered out. The results, shown in Figure 106, use the filter transfer function coefficients b and a. You can also call the DFFILT function by using the filter transfer function’s zeros, poles, and gain, as shown in the code comments.

proc iml;
sf  = 800;   /* sampling frequency */
sf2 = sf/2;
T = 1.0/sf;  /* sampling period */
N = 200;
t = do(0, (N-1)*T, T);

f1 = 20;
f2 = 80;
pi = constant("pi");
x1 = sin(2*pi*f1*t);
x2 = sin(2*pi*f2*t);
x = x1 + x2; /* input signal */

filter_name = "butter";
filter_type = "lowpass";
n = 8;
Wc = 0.125;
call dfdesign(b, a, z, p, k, filter_name, filter_type, n, Wc);

/* use b, a for filtering */
y = dffilt(x, b, a);

/* use z, p, k for filtering */
/* y = dffilt(x, z, p, k);  */

create results var {"t", "x", "y"};
append;
close results;
quit;

title "Input and Output of the Digital Filter";
proc sgplot data=results;
   series x=t y=x / legendlabel="Input Signal";
   series x=t y=y / legendlabel="Filtered Signal" lineattrs=(thickness=2);
   xaxis grid label="Time";
   yaxis grid label="Amplitude";
run;

Figure 106: Lowpass Filtering Example

Lowpass Filtering Example


Last updated: July 20, 2026