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

老子叫甜甜 提交于 2019-12-03 06:06:52

问题


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)

回答1:


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)

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.

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')



回答2:


Answer to your question is highly dependent on the characteristics of what you call "noise" - its spectral distribution, the noise being stationary or not, the source of the noise (does it originate in the environment or the recording chain?).

If the noise is stationary, i.e its statistical characteristics do not change over time, you can try recording a few seconds (10-15 is a good initial guess) of noise only, preform FFT, and then subtract the value of the noise in FFT bin n from your measurement FFT bin n.

You can read some background here: http://en.wikipedia.org/wiki/Noise_reduction



来源:https://stackoverflow.com/questions/5879851/how-can-the-noise-be-removed-from-a-recorded-sound-using-fft-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!