📄 demolin8.html
字号:
<!--This HTML is auto-generated from an m-file.Your changes will be overwritten.--><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:x-large">Adaptive Noise Cancellation</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">A linear neuron is allowed to adapt so that given one signal, it can predict asecond signal.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Copyright 1992-2002 The MathWorks, Inc.$Revision: 1.13 $ $Date: 2002/03/29 19:36:13 $</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">TIME defines the time steps of this simulation. P defines a signal over thesetime steps. T is a signal derived from P by shifting it to the left,multiplying it by 2 and adding it to itself.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">time = 1:0.01:2.5;X = sin(sin(time).*time*10);P = con2seq(X);T = con2seq(2*[0 X(1:(end-1))] + X);</pre><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Here is how the two signals are plotted:</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">plot(time,cat(2,P{:}),time,cat(2,T{:}),<span style="color:#B20000">'--'</span>)title(<span style="color:#B20000">'Input and Target Signals'</span>)xlabel(<span style="color:#B20000">'Time'</span>)legend({<span style="color:#B20000">'Input'</span>,<span style="color:#B20000">'Target'</span>})</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demolin8_img03.gif"><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">The linear network must have tapped delay in order to learn the time-shiftedcorrelation between P and T. NEWLIN creates a linear layer. [-3 3] is theexpected input range. The second argument is the number of neurons in thelayer. [0 1] specifies one input with no delay and one input with a delay ofone. The last argument is the learning rate.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">net = newlin([-3 3],1,[0 1],0.1);</pre><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">ADAPT simulates adaptive networks. It takes a nework, a signal, and a targetsignal, and filters the signal adaptively. Plot the the output Y in blue, thetarget T in red and the error E in green. By t=2 the network has learned therelationship between the input and the target and the error drops to nearzero.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">[net,Y,E,Pf]=adapt(net,P,T);plot(time,cat(2,Y{:}),<span style="color:#B20000">'b'</span>, <span style="color:blue">...</span> time,cat(2,T{:}),<span style="color:#B20000">'r'</span>, <span style="color:blue">...</span> time,cat(2,E{:}),<span style="color:#B20000">'g'</span>,[1 2.5],[0 0],<span style="color:#B20000">'k'</span>)legend({<span style="color:#B20000">'Output'</span>,<span style="color:#B20000">'Target'</span>,<span style="color:#B20000">'Error'</span>})</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demolin8_img05.gif"><originalCode xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" code="%% Adaptive Noise Cancellation
% A linear neuron is allowed to adapt so that given one signal, it can predict a
% second signal.
% 
% Copyright 1992-2002 The MathWorks, Inc.
% $Revision: 1.13 $ $Date: 2002/03/29 19:36:13 $

%%
% TIME defines the time steps of this simulation. P defines a signal over these
% time steps. T is a signal derived from P by shifting it to the left,
% multiplying it by 2 and adding it to itself.

time = 1:0.01:2.5;
X = sin(sin(time).*time*10);
P = con2seq(X);
T = con2seq(2*[0 X(1:(end-1))] + X);

%%
% Here is how the two signals are plotted:

plot(time,cat(2,P{:}),time,cat(2,T{:}),'--')
title('Input and Target Signals')
xlabel('Time')
legend({'Input','Target'})

%%
% The linear network must have tapped delay in order to learn the time-shifted
% correlation between P and T. NEWLIN creates a linear layer. [-3 3] is the
% expected input range. The second argument is the number of neurons in the
% layer. [0 1] specifies one input with no delay and one input with a delay of
% one. The last argument is the learning rate.

net = newlin([-3 3],1,[0 1],0.1);

%%
% ADAPT simulates adaptive networks. It takes a nework, a signal, and a target
% signal, and filters the signal adaptively. Plot the the output Y in blue, the
% target T in red and the error E in green. By t=2 the network has learned the
% relationship between the input and the target and the error drops to near
% zero.

[net,Y,E,Pf]=adapt(net,P,T);
plot(time,cat(2,Y{:}),'b', ...
 time,cat(2,T{:}),'r', ...
 time,cat(2,E{:}),'g',[1 2.5],[0 0],'k')
legend({'Output','Target','Error'})
"></originalCode>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -