I expanded your code a little bit, and i think now i know what is really
wrong:
I calculated the power ratio of the output signals of the reference and
predicted filters. In the "random noise section" the power ratio is around
88, meaning that the power of the output signal of the predicted filter is
much more than it should be.
In the "impuls respons section" the ratio is 1, as it should be.
Doesn't this mean that gain calculation works best if the auto correlation
is taken from an impuls respons, and when using noise for auto correlation a
very (probably very )inaccurate result is achieved?
By the way, i tried this also for a fir-filter, and the conclusion is the
same, as expected.
Many thanks for your input.
The modified code is listed below
Clc
close all
clear
% Number of points
N=100;
% IIR denominator order
P=10;
% Design Pth order IIR filter
[num,den] = iirlpnormc(0,P,[0 .15 .4 .5 1],[0 .4 .5 1],[1 1.6 1 0 0],[1 1 1
10 10]);
% Random Noise Input
x=randn(1,N);
% Filter random noise
y=filter(num,den,x);
% Find filter impulse response
y_impulse=filter(num,den,[1 zeros(1,N-1)]);
% Calc autocorrelation (random noise scenario)
ac=xcorr(y);
ac=ac(N:N+P);
% Estimate filter coefficients
[ap e] = levinson(ac,P);
% Compare spectra
Syy=abs(fft(y)).^2;
Syy_predicted=abs(freqz(sqrt(e),ap,N,'whole')).^2;
y_predicted = filter(sqrt(e),ap,x);
% Calculate power of output signals of reference and predicted filter
pow_ref = y * y';
pow_predicted = y_predicted * y_predicted';
pow_predicted/pow_ref
figure(1)
plot(Syy)
hold
plot(Syy_predicted,'r--')
hold
% Calc autocorrelation (impulse response scenario)
ac=xcorr(y_impulse);
ac=ac(N:N+P);
% Estimate
[ap e] = levinson(ac,P);
% Compare
Syy_impulse=abs(fft(y_impulse)).^2;
Syy_predicted=abs(freqz(sqrt(e),ap,N,'whole')).^2;
y_predicted = filter(sqrt(e),ap,x);
% Calculate power of output signals of reference and predicted filter
pow_ref = y * y';
pow_predicted = y_predicted * y_predicted';
pow_predicted/pow_ref
figure(2)
plot(Syy_impulse)
hold
plot(Syy_predicted,'r--')
hold
When using random noise
"Jack" <jack@nospammers.please> wrote in message
news:dvm6lp$2l4n$1@newsbin.cybercity.dk...
> Here is my guess of what you are doing wrong:
>
> 1) You are using FIR filter coefficients
> 2) You are filtering random noise with a FIR filter
>
> LPC analyzes data which is assumed to be the output
> of an IIR filter.
>
> Try this:
>
> clc
> close all
> clear
>
> % Number of points
> N=100;
>
> % IIR denominator order
> P=10;
>
> % Design Pth order IIR filter
> [num,den] = iirlpnormc(0,P,[0 .15 .4 .5 1],[0 .4 .5 1],[1 1.6 1 0 0],[1 1
> 1 10 10])
>
> % Random Noise Input
> x=randn(1,N);
>
> % Filter random noise
> y=filter(num,den,x);
>
> % Find filter impulse response
> y_impulse=filter(num,den,[1 zeros(1,N-1)]);
>
> % Calc autocorrelation (random noise scenario)
> ac=xcorr(y);
> ac=ac(N:N+P);
>
> % Estimate filter coefficients
> [ap e] = levinson(ac,P)
>
> % Compare spectra
> Syy=abs(fft(y)).^2;
> Syy_predicted=abs(freqz(sqrt(e),ap,N,'whole')).^2;
>
> plot(Syy)
> hold
> plot(Syy_predicted,'r--')
> hold
>
> % Calc autocorrelation (impulse response scenario)
> ac=xcorr(y_impulse);
> ac=ac(N:N+P);
>
> % Estimate
> [ap e] = levinson(ac,P)
>
> % Compare
> Syy_impulse=abs(fft(y_impulse)).^2;
> Syy_predicted=abs(freqz(sqrt(e),ap,N,'whole')).^2;
>
> figure
> plot(Syy_impulse)
> hold
> plot(Syy_predicted,'r--')
> hold
>
>
>
>