how can the noise be removed from a recorded sound,using fft in MATLAB?

yuna picture yuna · May 4, 2011 · Viewed 27.3k times · Source

I want to remove noises from a recorded sound and make the fft of it finding fundamental frequencies of that sound, but I don't know how to remove those noises. I'm recording the sound of falling objects from different heights. I want to find the relation between the height and the maximum frequency of the recorded sound.

  [y,fs]=wavread('100cmfreefall.wav');

 ch1=y(:,1);
 time=(1/44100)*length(ch1);
t=linspace(0,time,length(ch1));


L=length(ch1);
 NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
Y1=log10(Y);
figure(1)

f = fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y1(1:NFFT/2+1))) ;

[b,a]=butter(10,3000/(44100/2),'high');
Y1=filtfilt(b,a,Y1);

% freqz(b,a)
figure(2)

plot(f,2*abs(Y1(1:NFFT/2+1))) ;

title('Single-Sided Amplitude Spectrum of y(t)');
xlabel('Frequency (Hz)');
ylabel('|Y(f)|')
xlim([0 50000])


% soundsc(ch1(1:100000),44100)

Answer

abcd picture abcd · May 4, 2011

Saying that there is noise in your signal is very vague and doesn't convey much information at all. Some of the questions are:

  • Is the noise high frequency or low frequency?
  • Is it well separated from your signal's frequency band or is it mixed in?
  • Does the noise follow a statistical model? Can it be described as a stationary process?
  • Is the noise another deterministic interfering signal?

The approach you take will certainly depend on the answers to the above questions.

However, from the experiment setup that you described, my guess is that your noise is just a background noise, that in most cases, can be approximated to be white in nature. White noise refers to a statistical noise model that has a constant power at all frequencies.

The simplest approach will be to use a low pass filter or a band pass filter to retain only those frequencies that you are interested in (a quick look at the frequency spectrum should reveal this, if you do not know it already). In a previous answer of mine, to a related question on filtering using MATLAB, I provide examples of creating low-pass filters and common pitfalls. You can probably read through that and see if it helps you.

A simple example:

Consider a sinusoid with a frequency of 50 Hz, sampled at 1000 Hz. To that, I add Gaussian white noise such that the SNR is ~ -6dB. The original signal and the noisy signal can be seen in the top row of the figure below (only 50 samples are shown). As you can see, it almost looks as if there is no hope with the noisy signal as all structure seems to have been destroyed. However, taking an FFT, reveals the buried sinusoid (shown in the bottom row)

enter image description here

Filtering the noisy signal with a narrow band filter from 48 to 52 Hz, gives us a "cleaned" signal. There will of course be some loss in amplitude due to the noise. However, the signal has been retrieved from what looked like a lost cause at first.

enter image description here

How you proceed depends on your exact application. But I hope this helped you understand some of the basics of noise filtering.

EDIT

@Shabnam: It's been nearly 50 comments, and I really do not see you making any effort to understand or at the very least, try things on your own. You really should learn to read the documentation and learn the concepts and try it instead of running back for every single error. Anyway, please try the following (modified from your code) and show the output in the comments.

[y,fs]=wavread('100cmfreefall.wav');
ch1=y(:,1);
time=(1/fs)*length(ch1);
t=linspace(0,time,length(ch1));
L=length(ch1);
NFFT = 2^nextpow2(L);
f = fs/2*linspace(0,1,NFFT/2+1);

[b,a]=butter(10,3e3/(fs/2),'high'); 
y1=filtfilt(b,a,ch1);

figure(1)
subplot(2,1,1)
Y=fft(ch1,NFFT)/L;
plot(f,log10(abs(Y(1:NFFT/2+1))))
title('unfiltered')

subplot(2,1,2)
Y1=fft(y1,NFFT)/L;
plot(f,log10(abs(Y1(1:NFFT/2+1))))
title('filtered')