-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdalineNN.m
64 lines (49 loc) · 1.37 KB
/
AdalineNN.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
clear all;
clc;
close all;
load speech.mat
sig = y;
X = randn(length(sig),1); % Noise source
D = sig + 0.7*X; % Speech corrupted with noise
M=length(D); % Signal Length
Delay=10; % Size of the Tapped Delay Line
MSE=0;
b=0; % Bias
alfa=0.01; % Learning Rate
n = 0;
iterations = 4; % Learning Iterations
W=zeros(1,Delay); %Synaptic Weights
TDL=[zeros(1,Delay)]; %Tapped Delay Line
e=zeros(M,1); %Error
y=zeros(M,1); %Noise estimation
while (n < iterations)
for i = 1 : M-Delay
TDL=[X(i) TDL(1:Delay-1)]; %insert X(n) into the first position of the delay line
b=alfa*e(i); %Bias b(n)
%Calculate y(n)
s = 0;
for j = 1:Delay
s = s + TDL(j)*W(j);
end
y(i)= s + b;
%Error e(n)
e(i)=(D(i)-y(i));
%Update synaptic weights
W = W + (alfa.*e(i)*TDL)';
end
MSE=(1/M)*sum(e,'all')^2;
n=n+1;
end
subplot(411);
plot(sig); title('Signal');
subplot(412);
plot(D); title('Signal plus noise');
subplot(413);
plot(X); title('Reference noise');
subplot(414);
plot(e); title('Signal after noise cancellation ');
%% May use sound(...) to listen to the samples
% Original sound - sound(sig)
% Reference noise - sound(X)
% Sound + noise - sound(D)
% Reconstructed sound - sound(e)