02.10.2019 Views

UploadFile_6417

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

FIR Filter Structures 235<br />

6.3.8 MATLAB IMPLEMENTATION<br />

Given the impulse response h (n) orthe DFT H(k), we have to determine<br />

the coefficients in (6.13) and (6.14). The following MATLAB function,<br />

dir2fs, converts a direct form [h (n) values] to the frequency sampling<br />

form by directly implementing (6.13) and (6.14).<br />

function [C,B,A] = dir2fs(h)<br />

% Direct form to Frequency Sampling form conversion<br />

% -------------------------------------------------<br />

% [C,B,A] = dir2fs(h)<br />

% C = Row vector containing gains for parallel sections<br />

% B = Matrix containing numerator coefficients arranged in rows<br />

% A = Matrix containing denominator coefficients arranged in rows<br />

% h = impulse response vector of an FIR filter<br />

%<br />

M = length(h); H = fft(h,M);<br />

magH = abs(H); phaH = angle(H)’;<br />

% check even or odd M<br />

if (M == 2*floor(M/2))<br />

L = M/2-1; % M is even<br />

A1 = [1,-1,0;1,1,0]; C1 = [real(H(1)),real(H(L+2))];<br />

else<br />

L = (M-1)/2; % M is odd<br />

A1 = [1,-1,0]; C1 = [real(H(1))];<br />

end<br />

k = [1:L]’;<br />

% initialize B and A arrays<br />

B = zeros(L,2); A = ones(L,3);<br />

% compute denominator coefficients<br />

A(1:L,2) = -2*cos(2*pi*k/M); A = [A;A1];<br />

% compute numerator coefficients<br />

B(1:L,1) = cos(phaH(2:L+1));<br />

B(1:L,2) = -cos(phaH(2:L+1)-(2*pi*k/M));<br />

% compute gain coefficients<br />

C = [2*magH(2:L+1),C1]’;<br />

In this function, the impulse response values are supplied through the<br />

h array. After conversion, the C array contains the gain values for each<br />

parallel section. The gain values for the 2nd-order parallel sections are<br />

given first, followed by H (0) and H (M/2) (if M is even). The B matrix<br />

contains the numerator coefficients, which are arranged in length-2 row<br />

vectors for each 2nd-order section. The A matrix contains the denominator<br />

coefficients, which are arranged in length-3 row vectors for the 2nd-order<br />

sections corresponding to those in B, followed by the coefficients for the<br />

1st-order sections.<br />

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).<br />

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!