数学建模(4)

191 阅读2分钟

正文

本文已参与「新人创作礼」活动,一起开启掘金创作之路。近半个多世纪以来,随着计算机技术的迅速发展,数学的应用不仅在工程技术、自然科学等领域发挥着越来越重要的作用,而且以空前的广度和深度向经济、管理、金融、生物、医学、环境、地质、人口、交通等新的领域渗透,所谓数学技术已经成为当代高新技术的重要组成部分。

数学模型(Mathematical Model)是一种模拟,是用数学符号、数学式子、程序、图形等对实际课题本质属性的抽象而又简洁的刻画,它或能解释某些客观现象,或能预测未来的发展规律,或能为控制某一现象的发展提供某种意义下的最优策略或较好策略。数学模型一般并非现实问题的直接翻版,它的建立常常既需要人们对现实问题深入细微的观察和分析,又需要人们灵活巧妙地利用各种数学知识。这种应用知识从实际课题中抽象、提炼出数学模型的过程就称为数学建模(Mathematical Modeling)。本文介绍数学建模中的ar模型

AR模型

clc;
clear;
close all;

randn('state',0); 
noise = randn(50000,1);  % Normalized white Gaussian noise
x = filter(1,[1 1/2 1/3 1/4],noise);
x = x(45904:50000);
a = lpc(x,3);
est_x = filter([0 -a(2:end)],1,x);  % Estimated signal
e = x - est_x;                      % Prediction error
[acs,lags] = xcorr(e,'coeff');      % ACS of prediction error

%   Compare the predicted signal to the original signal
figure;
plot(1:97,x(4001:4097),1:97,est_x(4001:4097),'--');
title('Original Signal vs. LPC Estimate');
xlabel('Sample Number'); ylabel('Amplitude'); grid on;
legend('Original Signal','LPC Estimate')

%   Look at the autocorrelation of the prediction error.
figure;
plot(lags,acs); 
title('Autocorrelation of the Prediction Error');
xlabel('Lags'); ylabel('Normalized Value'); grid on;

clc;
clear;
close all;

% Estimate model order using decay of reflection coefficients.
rng default;
y=filter(1,[1 -0.75 0.5],0.2*randn(1024,1));
% Create AR(2) process
[ar_coeffs,NoiseVariance,reflect_coeffs] = aryule(y,10);

% Fit AR(10) model
stem(reflect_coeffs);
axis([-0.05 10.5 -1 1]);
title('Reflection Coefficients by Lag');
xlabel('Lag');ylabel('Reflection Coefficent');

clc;
clear;
close all;

%  Estimate input noise variance for AR(4) model.
A = [1 -2.7607 3.8106 -2.6535 0.9238]; 
% Generate noise standard deviations
rng default;
noise_stdz = rand(1,50)+0.5;

% Generate column vectors that have corresponding standard deviation
x = bsxfun(@times,noise_stdz,randn(1024,50));

% filter each column using the AR model.
y = filter(1,A,x);

% Compute the estimated coefficients and deviations for each column
[ar_coeffs,NoiseVariance]=arburg(y,4);

% Display the mean value of each estimated polynomial coefficient
estimatedA = mean(ar_coeffs);

% Compare actual vs. estimated variances
plot(noise_stdz.^2,NoiseVariance,'k*');
xlabel('Input Noise Variance');
ylabel('Estimated Noise Variance');