You are on page 1of 4

6/14/2021 Filtering noise from an audio file - MATLAB Answers - MATLAB Central

MATLAB Answers

Filtering noise from an audio file


 Follow 685 views (last 30 days) Show older comments

Naser Je
on 11 May 2018  Vote 0
Commented: zina shalchi
on 27 Oct 2020


DSP.zip

I have a corrupted audio file which contains a message with very loud noise, and I should filter the noise as
much as possible. I tried couple of filters, and I could eliminate some of the noises but it's not enough. P.S.
The expected audio file is also there, which I plotted it to compare the filtered one with it. Both audio files
and the code are provided in the zip file.

 
clc;
close all;
clear;

[Clean, Fs2] = audioread('expected.m4a');


[sample_data, sample_rate] = audioread('corrupted.m4a');

https://www.mathworks.com/matlabcentral/answers/400244-filtering-noise-from-an-audio-file 1/4
6/14/2021 Filtering noise from an audio file - MATLAB Answers - MATLAB Central

signal = medfilt1(sample_data,90); % Applying median filter

%_______________________________________________________________________________%
Fs = sample_rate; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = 1000/Fn; % Passband Frequency (Normalised)
Ws = 1010/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 150; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws,'low'); % Filter Design
[soslp,glp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability

filtered_sound2 = filtfilt(soslp, glp, signal);


%_______________________________________________________________________________%

fs2_d = [filtered_sound2,filtered_sound2];

sound(fs2_d, sample_rate)

subplot(4,1,1);
plot(sample_data); % Original Signal
title('Original Signal');
xlabel('Time (s)'); ylabel ('Amplitude');

subplot(4,1,2);
plot(filtered_sound2); % Filtered output
title('Filtered Signal Double');
xlabel('Time (s)'); ylabel ('Amplitude');

subplot(4,1,3);
plot(fs2_d); % Filtered output
title('Filtered Signal Double');
xlabel('Time (s)'); ylabel ('Amplitude');

subplot(4,1,4);
plot(Clean); % Expected output
title('Expected Signal');
xlabel('Time (s)'); ylabel ('Amplitude');

   10 Comments Show 9 older comments

zina shalchi
on 27 Oct 2020 

Hello, I faced the following errors

Error using sound (line 76)

Only one- and two-channel audio supported.

https://www.mathworks.com/matlabcentral/answers/400244-filtering-noise-from-an-audio-file 2/4
6/14/2021 Filtering noise from an audio file - MATLAB Answers - MATLAB Central

Error in dsp (line 26)

sound(fs2_d, sample_rate)

while trying to implement your code

@Naser Je

would you help

Sign in to comment.

Sign in to answer this question.


Answers (0)
Sign in to answer this question.

See Also
MATLAB Answers
matlab code for digital filter design to remove gaussian noise from a speech signal ?
2 Answers

Can you help remove the noise from this audio file?
1 Answer

Filtering out high frequency noise of an audio file


1 Answer

Entire Website
Filter_Signal
File Exchange

audio
File Exchange

Audio Filter
File Exchange

Categories
Signal Processing
> Signal Processing Toolbox
> Digital and Analog Filters
> Digital Filtering

Tags
filter dsp digital signal pro... audio file noise cancellation

Products
MATLAB

https://www.mathworks.com/matlabcentral/answers/400244-filtering-noise-from-an-audio-file 3/4
6/14/2021 Filtering noise from an audio file - MATLAB Answers - MATLAB Central

Release

R2016b

mathworks.com
© 1994-2021 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See mathworks.com/trademarks for a list of additional
trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.

https://www.mathworks.com/matlabcentral/answers/400244-filtering-noise-from-an-audio-file 4/4

You might also like