xlinpred.m

来自「这是一些关于MATLAB的小程序」· M 代码 · 共 68 行

M
68
字号
% LinPred.m 
%  Linear prediction.
%  用NEWLIND设()计一个线性网络,用SIM()对此线性网络进行仿真。 
%  网络利用过去五个信号值可以对下一个信号进行预测。
%
%   Author: HUANG Huajiang
%   Copyright 2003 UNILAB Research Center, 
%   East China University of Science and Technology, Shanghai, PRC
%   $Revision: 1.0 $  $Date: 2003/01/12 $
%
%   [Ref] MATLAB demo, Mathworks Co.

clear all

% (1) Defining a wave form 
% ------------------------
% TIME defines the time steps of this simulation.
time = 0:0.025:5;  % from 0 to 6 seconds

% T defines the signal in time to be predicted:
t = sin(time*4*pi);
q = length(t);

% The input p to the network is the last five values of the signal T:
p = zeros(5,q);
p(1,2:q) = t(1,1:(q-1));
p(2,3:q) = t(1,1:(q-2));
p(3,4:q) = t(1,1:(q-3));
p(4,5:q) = t(1,1:(q-4));
p(5,6:q) = t(1,1:(q-5));

% (2)Plotting the signals to be predicted
% ---------------------------------------
plot(time,t)
xlabel('Time');
ylabel('Target Signal');
title('Signal to be Predicted');

% (3)Design the network...
% NEWLIND solves for weights and biases which will let
% the linear neuron model the system.
net = newlind(p,t);

% (4)Testing the predictor 
% ------------------------
% SIM simulates the linear neuron which attempts
% to predict the next value in the signal at each timestep
a = sim(net,p);

% (5)绘制输出信号(Plotting the Output Signal)
% ----------------------------------------
% 绘制输出信号和目标信号
plot(time,a,time,t,'+')
xlabel('Time');
ylabel('Output -  Target +');
title('Output and Target Signals');

% 绘制神经元输出信号与目标信号之差,以便观察预测性能 
figure
e = t - a;
plot(time,e)
hold on
plot([min(time) max(time)],[0 0],':r')
hold off
xlabel('Time');
ylabel('Error');
title('Error Signal');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?