# 线性预测和自回归建模

### 使用以白噪声为输入的全极点滤波器生成 AR 信号

b = fir1(1024, .5); [d,p0] = lpc(b,7);

rng(0,'twister'); % Allow reproduction of exact experiment u = sqrt(p0)*randn(8192,1); % White Gaussian noise with variance p0

x = filter(1,d,u);

### 使用尤尔-沃克方法从信号中求得 AR 模型

[d1,p1] = aryule(x,7);

### 比较 AR 模型与 AR 信号

[H1,w1] = freqz(sqrt(p1),d1);

periodogram(x) hold on hp = plot(w1/pi,20*log10(2*abs(H1)/(2*pi)),'r'); % Scale to make one-sided PSD hp.LineWidth = 2; xlabel('Normalized frequency (\times \pi rad/sample)') ylabel('One-sided PSD (dB/rad/sample)') legend('PSD estimate of x','PSD of model output')

### 使用 LPC 执行线性预测

[d2,p2] = lpc(x,7); [d1.',d2.']
ans = 8×2 1.0000 1.0000 -3.5245 -3.5245 6.9470 6.9470 -9.2899 -9.2899 8.9224 8.9224 -6.1349 -6.1349 2.8299 2.8299 -0.6997 -0.6997 

xh = filter(-d2(2:end),1,x);

### 比较实际信号和预测信号

cla stem([x(2:end),xh(1:end-1)]) xlabel('Sample time') ylabel('Signal value') legend('Original autoregressive signal','Signal estimate from linear predictor') axis([0 200 -0.08 0.1])

### 比较预测误差

p3 = norm(x(2:end)-xh(1:end-1),2)^2/(length(x)-1);

[p0 p1 p2 p3]
ans = 1×4 10-5 × 0.5127 0.5305 0.5305 0.5068