DSPRelated.com
Forums

Building an impulse response function in MATLAB

Started by mata mata July 31, 2003
Hi all,
I have builded a function of impulse response in matlab

from pole and zero functions I adopted from the internet

but I'm not so sure about the result....anyone can help me please ?

perhaps I made mistakes on the function
The impulse response, h(n), of the weighted synthesis filter H(z)W(z)
=A(z/g1)/[A'(z)A(z/g2)] is computed each subframe. This impulse response is
needed for the search of adaptive and fixed codebooks. The impulse response
h(n), is computed by filtering the vector of coefficients of the filter A(z/g1)
extended by zeros through the two filters 1/A'(z) and 1/A(z/g2).
function h=impulse_res(fc,pc,no,cmp)

%cmp = codec mode in AMR system for choosing gamma values

(for example : 12.2 kbps )

%no (the order of LPC)

%fc = the set vector of quantized LP coefficient A'(z) (size = 11x1)

%pc = the set vector of unquantized LP coefficient A(z)(size = 11x1)

%h = impulse response (size 40x1)
L@; %L=size of each subframe(40 samples)

h=zeros(L,1);h(1)=1.0;

d1=zeros(no+1,1);

d2=zeros(no+1,1);

d3=zeros(no+1,1);
%for A(z/y1)

if (cmp=.2)

gamma1=0.9;

else

gamma1=0.94;

end

pcexp2=bwex(gamma1,pc,no);

[d1,h]=zero(pcexp2,no,d1,h,L);
%for 1/A(z)

[d2,h]=pole(fc,no,d2,h,L);
%for 1/A(z/y2)

gamma2=0.6;

pcexp1=bwex(gamma2,pc,no);

[d3,h]=pole(pcexp1,no,d3,h,L);
----------------------

function pcexp = bwex( gamma, pc, no )
% SCALE PREDICTOR COEFFICIENTS TO SHIFT POLES RADIALLY INWARD

pcexp( 1:no+1, 1 ) = ( pc( 1:no+1 ) .* ( gamma .^ (0:no)' ) );
-----
function [ d, h ] = pole(pcexp, no, d, h, L )
if pcexp(1) ~= 1.0

fprintf( 'polefilt: bad coefficients\no');

end
for t = 1:L

d(1) = h(t) - sum( d(2:n+1) .* pcexp(2:n+1) );

d(2:n+1) = d(1:n);

h(t) = d(1);

end

-------

function [ d, h ] = zero( pcexp, no, d, h, L )
for t = 1:len

d(1) = h(t);

ar = sum( d(2:n+1) .* pcexp(2:n+1) );

d(2:n+1) = d(1:n);

h(t) = ar + ( d(1) * pcexp(1) );

end
-------------------------------
* Example
the inputs are :

fc = [1, -2.6668, 4.8836, -6.2675, 5.2687, -2.2201, -1.6791,

4.6678, -4.8297, 3.1372, -1.2942];

pc = [1, -9.113, 38.056, -95.897, 161.47, -189.84, 157.81, -

91.597, 35.525, -8.314, 0.89166];

no = 10 ;

cmp = 7.95;
the output is :

h =[ 1.0000

-0.4316

-3.0501

0.0726

6.2639

1.4851

-9.2364

-5.1018

9.4839

7.0807

-9.9621

-13.4065

-1.1086

5.2565

1.4810

-6.9308

-17.2031

-11.5825

15.7709

19.8724

-19.9871

-36.0993

9.3675

35.4143

-7.4783

-40.0359

-14.3673

8.2341

4.4951

5.3959

-14.8422

-50.8667

-7.5202

73.2907

18.7850

-99.2104

-43.5024

89.4611

34.5656

-87.3220];