-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinal-Code.txt
55 lines (48 loc) · 1.34 KB
/
Final-Code.txt
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
a='D:\Karan-ICT\SS_Project\strings.wav';
[y,Fs] = audioread(a);
info = audioinfo(a);
Mean=0.05;
Var=0.005;
z=imnoise(y,'Gaussian',Mean,Var);
b='D:\Karan-ICT\SS_Project\stringsnoise.wav';
audiowrite(b,z,Fs);
mtlb_noisy = y;
noise = z;
% Define Adaptive Filter Parameters
filterLength = 1000;
weights = zeros(1,filterLength);
step_size = 0.004;
% Initialize Filter's Operational inputs
output = zeros(1,length(mtlb_noisy));
err = zeros(1,length(mtlb_noisy));
input = zeros(1,filterLength);
% For Loop to run through the data and filter out noise
for n = 1: length(mtlb_noisy),
%Get input vector to filter
for k= 1:filterLength
if ((n-k)>0)
input(k) = noise(n-k+1);
end
end
output(n) = weights * input'; %Output of Adaptive Filter
err(n) = mtlb_noisy(n) - output(n); %Error Computation
weights = weights + step_size * err(n) * input; %Weights Updating
end
yClean = err;
c='D:\Karan-ICT\SS_Project\stringsexpected.wav';
audiowrite(c,output,Fs);
subplot(3,1,1);
plot(y); % Original Signal
title('Original Signal');
xlabel('Time (s)');
ylabel ('Amplitude');
subplot(3,1,2);
plot(z); % Noisy output
title('Noisy signal');
xlabel('Time (s)');
ylabel ('Amplitude');
subplot(3,1,3);
plot(output); % Filtered output
title('Filtered Signal');
xlabel('Time (s)');
ylabel ('Amplitude');