1
$\begingroup$

I'm trying to understand how Matlab LPC function works. So I made a little example script : I generate a real cosinus, calculate the LPC coefficients of this signal and then I try to predict the signal using only its first samples of it.

clear all;

%% Configuration

Fs = 1e4; % Sampling frequency
F = 1054; % Signal frequency
order = 128; % LPC order

%% Generate signal
t = 0:1/Fs:1 - 1/Fs; 
t = t.';

ft = exp(2*1i*pi*F*t);
ft = real(ft);

[a, g] = lpc(ft, order);

%% Apply LPC filter
samples = ft(1:order);
for k = 1:length(ft) - order - 1
    warm_up = fliplr(samples(end - order + 1:end));
    samples(end + 1) = sum(warm_up .* a(2:end).');
end

%% Plot result
figure;
plot(t(1:length(samples)), samples, 'DisplayName', 'LPC', 'LineWidth', 2); hold on;
plot(t, ft, 'DisplayName', 'Original');
xlim([0 20/F]);
ylim([-2 2]);
title('Estimated and original signals');
legend;

When using a cosinus

I observe a phase error between the predicted signal and the real one. This error increase with time.

enter image description here

When using a sinus

The real issue appears when I change ft = real(ft); by ft = imag(ft); (so I generate a sinus and not a cosinus).

When doing this, the generated signal diverge

enter image description here

I think the issue is not that big, but I've been stucked on this for 3 hours now ><.

Any idea :) ?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.