Thread Subject: Removing noise by using a lowpass filter

Subject: Removing noise by using a lowpass filter

From: badegakk

Date: 14 Oct, 2011 09:35:14

Message: 1 of 7

Hi,

I'm quite new to matlab, I've got an audio signal with sampling frequency 44100 Hz and I'm trying to remove noise from the signal. After using almost all week on google, and on this forum, I've come close, but are missing the final part, so I'm hoping some of you can see what I'm missing. This is my code:

Fs = 44100;
t = linspace(0,1,Fs);
x =wavread('sound.wav');

% Specifying the filter
%'Fp,Fst,Ap,Ast' (passband frequency, stopband frequency, passband ripple, stopband attenuation)
hlpf = fdesign.lowpass('Fp,Fst,Ap,Ast',4.0e3,4.1e3,0.5,50,40e3);

% Designing the filter
D = design(hlpf);
% Applying the filter
y = filter(D,x);
sound(y,Fs)

I tried to read up on the passband freq, stoppband freq., etc, but I just cant get the hang of it. Can some of you see what I need to do to make the code work? I'm close, most of the noise is removed, but I can still hear some low pitch noise.

Thanks!

Subject: Removing noise by using a lowpass filter

From: Wayne King

Date: 14 Oct, 2011 10:49:13

Message: 2 of 7

"badegakk" wrote in message <j78voi$rlv$1@newscl01ah.mathworks.com>...
> Hi,
>
> I'm quite new to matlab, I've got an audio signal with sampling frequency 44100 Hz and I'm trying to remove noise from the signal. After using almost all week on google, and on this forum, I've come close, but are missing the final part, so I'm hoping some of you can see what I'm missing. This is my code:
>
> Fs = 44100;
> t = linspace(0,1,Fs);
> x =wavread('sound.wav');
>
> % Specifying the filter
> %'Fp,Fst,Ap,Ast' (passband frequency, stopband frequency, passband ripple, stopband attenuation)
> hlpf = fdesign.lowpass('Fp,Fst,Ap,Ast',4.0e3,4.1e3,0.5,50,40e3);
>
> % Designing the filter
> D = design(hlpf);
> % Applying the filter
> y = filter(D,x);
> sound(y,Fs)
>
> I tried to read up on the passband freq, stoppband freq., etc, but I just cant get the hang of it. Can some of you see what I need to do to make the code work? I'm close, most of the noise is removed, but I can still hear some low pitch noise.
>
> Thanks!

Your sampling frequency is 44.1 kHz

hlpf = fdesign.lowpass('Fp,Fst,Ap,Ast',4.0e3,4.1e3,0.5,50,44.1e3);

The rest looks correct. How do you know there is not noise in your passband? If there is noise in your signal below 4,000, then your filter leaves it unattenuated.

You have to first investigate the spectrum of your input signal and see if perhaps a lower frequency passband cutoff is more appropriate, or perhaps even a passband filter.

If there is noise in the same frequency band as your signal, then conventional filtering is not going to help that.

Wayne

Subject: Removing noise by using a lowpass filter

From: badegakk

Date: 14 Oct, 2011 11:32:10

Message: 3 of 7

Thanks for the quick response!

I got so excited that almost all the noise got damped, that I just figured that there were some small errors, but now I'm starting to loose faith in my code. I've got the spectrum for my input signal, but I'm so inexperienced in dealing with these signals in matlab, so they aren't telling me much. The spectrum is here; http://imageshack.us/photo/my-images/839/freqb.jpg/ Can you see something that I don't?

The signal is divided in the middle, with the first part being noise-free, while the noise starts at the second part. So I've made the spectrum for the no-noise part on the left, and with the noise on the right.

I'm adding the code for the right picture below, in case there is some errors there. The code for the left picture is the same, just moved to look at t = 0:1/fs:2-1/fs
Again, thank you so much for your time!

t = 2:1/fs:4-1/fs; % 4 sec sample

% Use fft to compute the DFT y and its power:
m = length(x/2); % Window length
n = pow2(nextpow2(m)); % Transform length
y = fft(x(length(x)/2:length(x)),n); % DFT


y0 = fftshift(y); % Rearrange y values
f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
power0 = abs(20*log10(y));


figure(3)
plot(f0,power0);
xlabel('Frequency (Hz)')
ylabel('dB')
title('{\bf 0-Centered Periodogram}')

Subject: Removing noise by using a lowpass filter

From: Wayne King

Date: 14 Oct, 2011 12:00:30

Message: 4 of 7

"badegakk" wrote in message <j796jq$i1d$1@newscl01ah.mathworks.com>...
> Thanks for the quick response!
>
> I got so excited that almost all the noise got damped, that I just figured that there were some small errors, but now I'm starting to loose faith in my code. I've got the spectrum for my input signal, but I'm so inexperienced in dealing with these signals in matlab, so they aren't telling me much. The spectrum is here; http://imageshack.us/photo/my-images/839/freqb.jpg/ Can you see something that I don't?
>
> The signal is divided in the middle, with the first part being noise-free, while the noise starts at the second part. So I've made the spectrum for the no-noise part on the left, and with the noise on the right.
>
> I'm adding the code for the right picture below, in case there is some errors there. The code for the left picture is the same, just moved to look at t = 0:1/fs:2-1/fs
> Again, thank you so much for your time!
>
> t = 2:1/fs:4-1/fs; % 4 sec sample
>
> % Use fft to compute the DFT y and its power:
> m = length(x/2); % Window length
> n = pow2(nextpow2(m)); % Transform length
> y = fft(x(length(x)/2:length(x)),n); % DFT
>
>
> y0 = fftshift(y); % Rearrange y values
> f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
> power0 = abs(20*log10(y));
>
>
> figure(3)
> plot(f0,power0);
> xlabel('Frequency (Hz)')
> ylabel('dB')
> title('{\bf 0-Centered Periodogram}')

This is not correct:

power0 = abs(20*log10(y));

the absolute value of log(z) is not the same as log(abs(z))
when plotting a power estimate, you want

20*log10(abs(y))

Subject: Removing noise by using a lowpass filter

From: badegakk

Date: 14 Oct, 2011 13:28:28

Message: 5 of 7

Ok. I've been changing it back and forwards during the last couple of days, so thanks for making it clear. With the changes you sugested, the plot becomes; http://imageshack.us/f/651/freq2.jpg/

So in the signal with the noise, the dB is higher than in the one without noise. But how and what does this say about the filter that's needed? Would I need to change to a bandpass filter, or can I change my lowpass filter on some way to eliminate the noise?

Thanks again Wayne!

Subject: Removing noise by using a lowpass filter

From: badegakk

Date: 18 Oct, 2011 09:58:29

Message: 6 of 7

Hi again,

I've found some errors in my code, so the new periodograms becomes http://imageshack.us/photo/my-images/805/periodogram.jpg/ The 1st one is for the whole signal, the 2nd for the part without noise, and the last for the part with noise.
I've tried to make a bandstop filter by using fdatool with the specifications;
Fpass1 = 7000;
Fstop1 = 10000;
Fstop2 = 20000;
Fpass2 = 22050;

This creates the filter by fdatool, but I wondered on how to use it? I've tried running the .m code, but I'm not getting something that I know how to apply to my signal. Is there anybody out there who can see what I need to do? And do you see something that my inexperienced eye aren't in the periodograms? I've just tried to use some pass/stop band frequencies so that I can try to "clean up" my audio by using trial and error, but if anyone out there can give better parameters, then don't hesitate to do so.

Thanks

Subject: Removing noise by using a lowpass filter

From: badegakk

Date: 18 Oct, 2011 12:19:11

Message: 7 of 7

I've figured out how to use the Hd output from my signal now, but after hours of trial and error I cant seem to get the parameters from fdatool correct. There's always some noise left in my signal when I use sound(y,fs) to play the filtered signal. Can anybody see what my bandstop parameters must be?

Thanks

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com