Assignment
Add and remove noise from an audio signal
Department Of Information Technology
UNIVERSITY INSTITUTE Of ENGINEERING AND
TECHNOLOGY
PANJAB UNIVERSITY, CHANDIGARH
Submitted to: Submitted by:
Dr. Sukesha Sharma Namish Pruthi(UE168069)
Assistant Professor
Information Technology
UIET, Panjab University
%Reading Audio File
[f,fs] = audioread('[Link]');
% Determine total number of samples in audio file
N = size(f,1);
fig = figure;
%Plotting Left Channel
stem(1:N, f(:,1));
title('Left Channel');
saveas(fig,'Left [Link]')
%Plotting Right Channel
stem(1:N, f(:,2));
title('Right Channel');
saveas(fig,'Right [Link]')
%Adding Noise to the Audio Signal
fn = f + 2*randn(length(f),1);
%Plotting Time domain of Original Signal
time=(1/fs)*length(f);
t=linspace(0,time,length(f));
plot(t,f);
title('Time domain plot of Original signal');
saveas(fig,'original_td.jpg')
%Plotting Time Domain of Signal with Noise
time1=(1/fs)*length(fn);
t1=linspace(0,time1,length(fn));
plot(t1,fn);
title('Time domain plot of Noise Added Siganl i.e fn.');
saveas(fig,'noise_td.jpg')
%Plotting Frequency of Original Signal
N=length(f);
Fc=(-N/2:N/2-1)/N;
F=fs*Fc;
wa=fft(f);
wa=fftshift(wa);
plot(F,wa);
title('Frequency plot of Orignal Signal');
saveas(fig,'original_f.jpg')
%Plotting Frequency of Signal with noise
N1=length(fn);
Fa=(-N1/2:N1/2-1)/N1;
F1=Fa*fs;
wq=fft(fn);
wq=fftshift(wq);
plot(F1,wq) ;title('Frequency plot of fn.');
saveas(fig,'noise_f.jpg')
sound(fn,fs);
%Noise removal
i=1;
%Averaging for reducing intensity of high frequencies
for j=2:N1-1
f(j,i) = (f(j-1,i) + f(j,i) + f(j+1,i))/3 ;
end
g = gausswin(20);%Creating Gaussian window of 20
g = g/sum(g);
y= conv(f(:,1), g, 'same'); %Applying Conv to filter added noise
audiowrite('[Link]',result,fs); % resultant signal can be written to the
new file
%Plotting Frequency plot after removing noise
Nn=length(result);
Fn=(-Nn/2:Nn/2-1)/Nn;
Fq=fs*Fn;
new=fft(result);
new=fftshift(new);
plot(Fq,new); title('Frequency plot after removing Noise');