Samuele Cornell
Samuele Cornell

Reputation: 165

Computing coefficients of FIR filter in Matlab

I have to create the function G(z) = [3*H^2(z)-2H^3(z)]*(z^-2) which takes as an input the impulse response of the filter H(z) , and outputs the impulse response of G(z).

I assume H(z) is a generic FIR filter

b = fir1(10,0.5); 
h = impz(b); 
t = impzlength(b);

where h is the values of the impulse response. I think H^2(z) = h(n).*z(-2n) and H^3(z) = h(n).*z^(-3n); H(z) is the transfer function of the filter .

I have to calculate the coefficients of num and den of the equation now, but I am stuck. I thought at first to use coeffs and a for loop but i need also the zero coefficients, while coeffs only provides the non zero coefficients.

Now I thought that maybe there is a work-around for obtaining the coefficients: basically I have to select only certain values of h. For example, to obtain the coefficients only for z^-3n:

n = 3; 
y = h(n:n:end);  % = 3 6 9 12 ...

But now I can't figure out how to sum appropriately the coefficients for z^-3n and z^-2n.

Upvotes: 2

Views: 455

Answers (1)

SleuthEye
SleuthEye

Reputation: 14579

Unless you are using a non-standard notation, H^2(z) is not h(n).*z(-2n) but rather the multiplication of a polynomial with coefficients h with itself. This can be computed with:

H2 = conv(h, h);

Similarly, H^3(z) can be computed using:

H3 = conv(H2, h);

Then, summing the polynomials boils down to summing the coefficients, with the only catch that you have to pad H2 so that the two vectors of coefficients have the same size:

H2 = [H2 zeros(1,length(H3)-length(H2))];
S  = 3*H2 -2*H3;

The final multiplication by z^(-2) (which can be represented by the polynomial coefficients [0 0 1]) could be achieve in the same way using conv with:

G = conv(S, [0 0 1 zeros(1,length(Sum)-3)]);

or alternatively, you may realize that multiplying by a single term polynomial is essentially equivalent to shifting the coefficients:

G = [0 0 S];

Upvotes: 1

Related Questions