Removing random noise from audio signal
4 views (last 30 days)
Show older comments
Hi, guys below are my code .. I am a newbie in Matlab and in my code audio file I add random noise in my audio file and after adding it I want to design a filter which removes that noise. Any hint or comment will be helpful to me. I also attached the audio file. Thanks
clear
close all
clc
[x,fs] = audioread('D.wav');
whos x; % Name Size Bytes Class sampling frequency
% x 556542x2 8904672 double 44100
% pOrig = audioplayer(x,fs);
% pOrig.play;
N = size(x,1); % Determine total number of samples in audio file
figure;
subplot(2,1,1);
stem(1:N, x(:,1));
title('Left Channel');
subplot(2,1,2);
stem(1:N, x(:,2));
title('Right Channel');
pause
%Adding Noise in audio signal
y=x;
y = y + randn(size(y));
% pOrig = audioplayer(y,fs);
% pOrig.play;
figure;
subplot(2,1,1);
stem(1:N, y(:,1));
title('Left Channel with Noise');
subplot(2,1,2);
stem(1:N, y(:,2));
title('Right Channel with Noise');
%nyquist frequncy = fs/2;44100/2=22050
%plot the spectrum
df = fs/N;
w = (-(N/2):(N/2)-1)*df;
y1= fft(y(:,1),N)/N;
y2 = fftshift(y1);
figure;
plot(w,abs(y2));
pause
n = 7;
beginFreq = 50 / (fs/2);
endFreq = 150 / (fs/2);
[b,a] = butter(n, [beginFreq, endFreq], 'stop');
fout = filter(b,a,y2);
% A = audioplayer(fout,fs);
% pOrig.play;
figure;
plot(b,a);
6 Comments
Ameer Hamza
on 6 Dec 2020
I am looking for zip file, and it does seem to be present here. Kindly someone mention here
Answers (2)
harsini j
on 19 Aug 2019
clear
close all
clc
[x,fs] = audioread('D.wav');
whos x; % Name Size Bytes Class sampling frequency
% x 556542x2 8904672 double 44100
% pOrig = audioplayer(x,fs);
% pOrig.play;
N = size(x,1); % Determine total number of samples in audio file
figure;
subplot(2,1,1);
stem(1:N, x(:,1));
title('Left Channel');
subplot(2,1,2);
stem(1:N, x(:,2));
title('Right Channel');
pause
%Adding Noise in audio signal
y=x;
y = y + randn(size(y));
% pOrig = audioplayer(y,fs);
% pOrig.play;
figure;
subplot(2,1,1);
stem(1:N, y(:,1));
title('Left Channel with Noise');
subplot(2,1,2);
stem(1:N, y(:,2));
title('Right Channel with Noise');
%nyquist frequncy = fs/2;44100/2=22050
%plot the spectrum
df = fs/N;
w = (-(N/2):(N/2)-1)*df;
y1= fft(y(:,1),N)/N;
y2 = fftshift(y1);
figure;
plot(w,abs(y2));
pause
n = 7;
beginFreq = 50 / (fs/2);
endFreq = 150 / (fs/2);
[b,a] = butter(n, [beginFreq, endFreq], 'stop');
fout = filter(b,a,y2);
% A = audioplayer(fout,fs);
% pOrig.play;
figure;
plot(b,a);
0 Comments
harinie Jr
on 5 Oct 2020
clear
close all
clc
[x,fs] = audioread('D.wav');
whos x; % Name Size Bytes Class sampling frequency
% x 556542x2 8904672 double 44100
% pOrig = audioplayer(x,fs);
% pOrig.play;
N = size(x,1); % Determine total number of samples in audio file
figure;
subplot(2,1,1);
stem(1:N, x(:,1));
title('Left Channel');
subplot(2,1,2);
stem(1:N, x(:,2));
title('Right Channel');
pause
%Adding Noise in audio signal
y=x;
y = y + randn(size(y));
% pOrig = audioplayer(y,fs);
% pOrig.play;
figure;
subplot(2,1,1);
stem(1:N, y(:,1));
title('Left Channel with Noise');
subplot(2,1,2);
stem(1:N, y(:,2));
title('Right Channel with Noise');
%nyquist frequncy = fs/2;44100/2=22050
%plot the spectrum
df = fs/N;
w = (-(N/2):(N/2)-1)*df;
y1= fft(y(:,1),N)/N;
y2 = fftshift(y1);
figure;
plot(w,abs(y2));
pause
n = 7;
beginFreq = 50 / (fs/2);
endFreq = 150 / (fs/2);
[b,a] = butter(n, [beginFreq, endFreq], 'stop');
fout = filter(b,a,y2);
% A = audioplayer(fout,fs);
% pOrig.play;
figure;
plot(b,a);
0 Comments
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!