iir filter design

3
17-11- 2014 ADSP Assignment # 2 Sumaiyya Farooq 6557 (MS-81) Implementation of a System using Difference Equation function [ Y, x, y ] = IIR_filter ( a, b, x, y, x_in ) % b = numerator coefficients % a = denominator coefficients % x_in = input sample % Y = output sample % x,y = input & output buffers N_b = length(b); N_a = length(a); % shift right input buffer for n = N_b-1:-1:1 x(n+1) = x(n); end % new sample x(1) = x_in; % convolution of b(n) and x(n) y1 = 0; for k=1:1:N_b y1 = y1 + b(k)*x(k); end % convolution of a(n) and y(n) y2 = 0; for k=1:1:N_a y2 = y2 + a(k)*y(k); end % shift right output buffer for n = N_a-1:-1:1 y(n+1) = y(n);

Upload: skanshah

Post on 22-Jan-2016

3 views

Category:

Documents


0 download

DESCRIPTION

design

TRANSCRIPT

Page 1: IIR Filter Design

17-11-2014

ADSP Assignment # 2Sumaiyya Farooq

6557 (MS-81)

Implementation of a System using Difference Equation

function [ Y, x, y ] = IIR_filter ( a, b, x, y, x_in ) % b = numerator coefficients% a = denominator coefficients% x_in = input sample% Y = output sample% x,y = input & output buffers N_b = length(b);N_a = length(a); % shift right input bufferfor n = N_b-1:-1:1 x(n+1) = x(n);end % new samplex(1) = x_in; % convolution of b(n) and x(n)y1 = 0;for k=1:1:N_b y1 = y1 + b(k)*x(k);end % convolution of a(n) and y(n)y2 = 0;for k=1:1:N_a y2 = y2 + a(k)*y(k);end % shift right output bufferfor n = N_a-1:-1:1 y(n+1) = y(n);end y(1) = y1+y2;Y = y(1); end

Page 2: IIR Filter Design

17-11-2014

Main Method

clcclear % b = numerator coefficients% a = denominator coefficients a = [0.3 0.4];b = [2 4 6 5]; % an arbitrary signalx_in = 2:2:10; x_in = [x_in, zeros(1,5)];x = zeros(1,length(b));y = zeros(1,length(a)); % outputoutput = zeros(1,length(x_in)); for i = 1:length(x_in) [ Y, x, y ] = IIR_filter ( a, b, x, y, x_in(i)); output(i) = Y; end % MATLAB filter commanda = [1 -1*a]; Y = filter(b,a,x_in); error = output – Y

ERROR

error =

1.0e-013 *

0 0 0 0.1421 0 0 0 0 0 0