# Separating noise from a signal in Matlab

Started by May 3, 2007
```Hi,
I am very new to the subject. I spent hours online on trying to
find how to use autocorrelation and fft in matlab, in order to separate
a signal from noise.
I have this so far:

t   = 0:.01:1;               % independent (time) variable
A = 8;                       % amplitude
Fs = 101;                    % Sampling frequency

frequency1 = 2;
frequency2 = 12;
sineFunction1 = A*sin(2*pi*frequency1*t);
sineFunction2 = A*sin(2*pi*frequency2*t);

sineFunctionCombined = sineFunction1 + sineFunction2;

%Gaussian noise
randn('state',0);
%Initialize RAND to a different state each time.
randn('state',sum(100*clock));
noise = 3*randn(size(t));    % 3 here affects how strong will the noise
will disturb the sine wave

sinePlusNoise = sineFunction1+noise;

%plot the summed sine waves in the top panel
subplot(2,1,1)
plot(t, sinePlusNoise)
title('35Hz noisy Sine wave')
ylabel('Amplitude')
xlabel('Time (s)')

subplot(2,1,2)
%Fs=1000;
%t=0:1/Fs:1;
c = xcorr(sinePlusNoise);
plot(c)

Well, now I would need to use fft to extract the sine wave from it, but
how?

_____________________________________
Do you know a company who employs DSP engineers?
Is it already listed at http://dsprelated.com/employers.php ?
```
```On 4 May, 01:06, "Paulina7m" <paulin...@yahoo.ca> wrote:
> Hi,
> I am very new to the subject. I spent hours online on trying to
> find how to use autocorrelation and fft in matlab, in order to separate
> a signal from noise.
> I have this so far:
>
> t   = 0:.01:1;               % independent (time) variable
> A = 8;                       % amplitude
> Fs = 101;                    % Sampling frequency
>
> frequency1 = 2;
> frequency2 = 12;
> sineFunction1 = A*sin(2*pi*frequency1*t);
> sineFunction2 = A*sin(2*pi*frequency2*t);
>
> sineFunctionCombined = sineFunction1 + sineFunction2;
>
> %Gaussian noise
> randn('state',0);
> %Initialize RAND to a different state each time.
> randn('state',sum(100*clock));
> noise = 3*randn(size(t));    % 3 here affects how strong will the noise
> will disturb the sine wave
>
> sinePlusNoise = sineFunction1+noise;
>
> %plot the summed sine waves in the top panel
> subplot(2,1,1)
> plot(t, sinePlusNoise)
> title('35Hz noisy Sine wave')
> ylabel('Amplitude')
> xlabel('Time (s)')
>
> subplot(2,1,2)
> %Fs=1000;
> %t=0:1/Fs:1;
> c = xcorr(sinePlusNoise);
> plot(c)
>
> Well, now I would need to use fft to extract the sine wave from it, but
> how?

I am a bit confused about what you try to do. From the heading
of your post, it seems that you want a filter. In that case, you need
to
design a filter which then can be implemented by using the FFT. If
this is what you want to do, the correlation function is not needed.

On the other hand, computing the FFT of the correlation function
can be useful if you want to check if there is a sinusoidal embedded
in a given signal.

Could you explain in a little mor edetail exactly what you want to do?

Rune

```
```Well, all I did is added the noise to a sine wave.
Now I would like to extract the sine wave from a noisy signal, as if I
wouldn't know that it's a sine wave.
I am trying to do two things here:
1. Learn how to extract useful features of a signal using
autocorrelation.
2. Learn how to smooth the signal as much as possible, using Matlab.

_____________________________________
Do you know a company who employs DSP engineers?
Is it already listed at http://dsprelated.com/employers.php ?
```
```On May 3, 7:02 pm, "Paulina7m" <paulin...@yahoo.ca> wrote:
> Well, all I did is added the noise to a sine wave.
> Now I would like to extract the sine wave from a noisy signal, as if I
> wouldn't know that it's a sine wave.
> I am trying to do two things here:
> 1. Learn how to extract useful features of a signal using
> autocorrelation.
> 2. Learn how to smooth the signal as much as possible, using Matlab.
>

If you know in advance that your signal consists of 2 sine waves,
you can try to estimate the parameters of the signal components
(i.e. the frequency, amplitude, phase).

Try to search for "frequency estimation", "ESPRIT", "MUSIC",
line spectral estimation.

One possible method for frequency estimation is to compute
its spectra:  compute the autocorrelation, then the magnitude
of the fourier transform of it.  Then find the peaks, and voila,
you get a frequency estimate or two.

Hope that helps,
Julius

```
```Thank you very much for your answers. Julius, you have been especially
helpful. In the end, I found a wavelet Toolbox for Matlab, which has a lot
of nice denoising functions.
Is there anything I should know about their limitations?

_____________________________________
Do you know a company who employs DSP engineers?
Is it already listed at http://dsprelated.com/employers.php ?
```
```On May 3, 11:58 pm, "Paulina7m" <paulin...@yahoo.ca> wrote:
> Thank you very much for your answers. Julius, you have been especially
> helpful. In the end, I found a wavelet Toolbox for Matlab, which has a lot
> of nice denoising functions.
> Is there anything I should know about their limitations?
>
> _____________________________________
> Do you know a company who employs DSP engineers?
> Is it already listed athttp://dsprelated.com/employers.php?

Why do you want to use wavelets if you know in advance that
the signal that you are interested in has a parameteric form?

Julius

```
```I was only learning the concepts, using sine waves.
The actual signals I have do denoise are EEG.

_____________________________________
Do you know a company who employs DSP engineers?
Is it already listed at http://dsprelated.com/employers.php ?
```
```On May 5, 12:32 am, "Paulina7m" <paulin...@yahoo.ca> wrote:
> I was only learning the concepts, using sine waves.
> The actual signals I have do denoise are EEG.
>
I guess you want to de-noise your signal using fast wavelet
transforms, and
get approximation signal.
Did you look at Matlab Wavelet toobox help? there are lot.Try with
default threshold levels.
It works well for signals like your one, if the noise is gaussian and
zero mean.

I use matlab version 7_2006B3. Old releases may not have these help
pages.

-bsj

```