%--------------------------- Begin Lab 4 -------------------- % Colin Joye % ECE 3770-01 % Lab 4, Linear Adaptive Prediction % due 3/01 % run 'c:\my documents\elec\neural' clear; wk = 0; % Weights for predictor. x = 0; % Signal being predicted. u = 0.01; % Optimization step size. leng = 4; % length of the filter. lrate = u/leng; % learning rate (real), 0< lrate <1.0 %wk[n]=wk[n-1]+u*x[n-k]*e[n]; % Weight calculation. %e[n]=x[n]-sum(wk[n]*x[n-m]); % Error calculation. % "time" defines the time steps of the simulation. time = 1:2000; %time=1:0.01:3.5; % X is a noisy signal, with SNR=20dB. %X=sin((time/80).^1.6)+wgn(1,length(time),-20); X = [sin(time(1:1220)/50) sin(time(1221:end)/15)]+wgn(1,length(time),-20); %X=sin(sin(time).*time*10); % P is the signal over these steps. P = con2seq(X); % T is a signal derived from P by shifting it to the % left, multiplying it by 2, and adding it to itself. T = con2seq(2*[0 X(1:(end-1))]+X); % plotting the two signals. figure(1) subplot(211); plot(time,cat(2,P{:}),time,cat(2,T{:}),[1 length(time)],[0 0],'k'); title('Input and Target Signals'); xlabel('Time'); ylabel('Input (blue), Target (green)'); % The linear network must have tapped delay in order to % learn the time-shifted correlation between P and T: % "newlin" creates a linear layer. net = newlin([-3 3],1,[0 1],lrate); % [-3 3] is the expected input range. % 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. % "Adapt" simulates adaptive networks. It takes a network, a % signal, and a target signal, and filters the signal adaptively. [net,Y,E,Pf] = adapt(net,P,T); figure(1) subplot(212); plot(time,cat(2,Y{:}),'b',time,cat(2,T{:}),'r',time,cat(2,E{:}),'g',[1 length(time)],[0 0],'k'); xlabel('Time'); ylabel('Input (red), Target (blue), Error (green)'); %--------------------------- End Lab 4 --------------------