Prev Next iirfilt1

Filtering With a DIRECT FORM I IIR
Syntax y = iirfilt1(bz,az,x) (No filter history)
Syntax y = iirfilt1(bz,az,x,x0) (Input history only)
Syntax y = iirfilt1(bz,az,x,x0,y0) (Input and output histories)
Include: include spt\iirfilt1.oms
See Also Other Window Functions

ARGUMENTS:
   INPUTS:
      bz = INPUT, COLUMN VECTOR, numerator   polynomial in z^(-1).
      az = INPUT, COLUMN VECTOR, denominator polynomial in z^(-1).
      x  = INPUT, COLUMN VECTOR, data to be filtered
      x0 = INPUT, COLUMN VECTOR, input history
      y0 = INPUT, COLUMN VECTOR, output history
   RETURN: COLUMN VECTOR, filtered sequence.

Description

DIRECT FORM I IIR filtering of a data sequence.

This function performs a DIRECT FORM I method IIR filtering of an input data sequence. Input column vectors 'bz' and 'az' represent the numerator and denominator polynomials of the digital transfer function as follows:

   bz(z)   b(1) + b(2)*z^(-1) + b(3)*z^(-2) + ... + b(Nb)*z^(-N)
   ----- = -----------------------------------------------------
   az(z)   a(1) + a(2)*z^(-1) + a(3)*z^(-2) + ... + a(Ma)*z^(-M)

   where: N  = numerator   polynomial order
          M  = denominator polynomial order
          Nb = rowdim(bz), N = Nb-1
          Ma = rowdim(az), M = Ma-1

In this method a FIR filter (the numerator polynomial) is applied first using the coefficients in vector 'bz'. Secondly, the previous results are applied as an input to a recursive filter with coefficients from vector 'az'. The function returns the same number of outputs as there are inputs.

The output result coerced to the same type as the input 'x'. The transfer function denominator coefficients 'a' are normalized such that the first coefficient a(1)=1 and the result is divided by the original a(1) to preserve a properly scaled step response (unity-in yields unity-out, steady state).

Previous history vectors x0 and y0 are optional parameters. If they are included they are pre-pended to the input data and output data for local processing. The number of history (previous) values required for the input sequence is Nb-1, where Nb=rowdim(bz). The number of history (previous) values required for the output sequence is Ma-1, where Ma=rowdim(az). If x0 length is lesser than Nb-1, extra zeros are added. If x0 has length greater than Nb-1, only the last Nb-1 elements are pre-pended to the input. Same principle applies for output history y0. If neither is included, zeros of input type are pre-pended. This feature allows separate blocks of contigous data to be processed for filtering data streams longer than the allowed array size.

All arguments must be of the same numerical type or 'novalue' is returned.

Example

Create a sinusoidal pulse and filter it with a Cheby 1 Bandpass filter using the iirfilt1() function.

#--- Simulation Parameters ---
N      = 2048;       # Record Length
fs     = 256d3;      # Sampling Rate
dt     = 1d0/fs;     # Sampling interval
T      = N*dt;       # Record time length

#--- Create a sinusoidal pulse ---
t  = timeaxis(dt,N); # time vector for record
fc = 8d3;            # Test waveform freq
x  = sin(2*PI*fc*t); # Create input sinusoid
x.row(1,N/8)     = fill(0d0,N/8,1); # Zero-out 1st  1/8 of record
x.row(N/2+1,N/2) = fill(0d0,N/2,1); # Zero-out Last 1/2 of record

#--- Make a Chey 1 bandpass filter for filtering ---
Norder = 5;        # Filter order
Ap     = .5d0;     # Passband ripple in [dB]
BW     = 2d3;      # Bandpass filter BANDWIDTH [Hz]
flo    = fc-BW/2;  # LOW Cutoff frequency
fhi    = fc+BW/2;  # HIGH Cutoff frequency
wlo    = 2*PI*flo; # [radians/sec]
whi    = 2*PI*fhi; # [radians/sec]
a = novalue; b = novalue;        # reserve polynomials
fncheb1(Norder,Ap,b,a);          # Create analog filter prototype
bz = novalue; az = novalue;;     # reserve polynomials
fn2dbp([wlo,whi],dt,b,a,bz,az);  # Convert to IIR BANDPASS

#--- Filter the input usinf iirfilt1() ---
y  = iirfilt1(bz,az,x);         # Perform digital filtering