next up previous contents
Next: Correlation of noise Up: Correlation Previous: Correlation   Contents

Introduction to correlation

Another important operation between signals is `correlation'. As we will see, correlation is very near to convolution (we can compute correlation by using convolution). In Scilab the command that performs convolution is `corr'. It can be used with one or two vectors. If we call `corr' with only one vector we get the correlation of the vector with itself (`autocorrelation'). On the contrary if we use two vectors we get the correlation between them (`crosscorrelation').

The correlation can be used to measure the degree at which both signals are related. One example can be used to understand its action. In the chapter `Plotting a vector or some part of a vector' we generated something similar to an EEG segment by using two sinusoids near in frequency


-->t = 0:.01:10;
 
-->signalbase = sin(2 * %pi * 9.7 * t) + sin(2 * %pi * 10.3 * t);
 
With the previous code we simulated 10 seconds of signal sampled at 100 Hz. The signal (contained in `signalbase') is modulated in amplitude by adding two sinusoids near in frequency. Now we are going to create a Gaussian noise (contained in `noise') of the same length. Since it contains all the frequencies, it is called `white noise' by analogy with `white light'. When we use `rand' having previously called the option `normal' we get a distribution of values whose mean is '0' and whose standard deviation is '1'. Since we multiply by `2' we get a normal distribution of values with a mean of `0' and a standard deviation of `2'.

 
-->rand('normal')
 
-->rand('seed',0)
 
-->noise = 2 * rand(signalbase);
 
-->signalnoise = signalbase + noise;
Now we are going to study the correlation of the `EEG' and of the `noise'. We begin with the `EEG'.

-->xbasc()
  
-->corrsignalbase = corr (signalbase,1000);
 
-->xsetech([0,0,1,1/2])
 
-->plot2d(t(1:500),signalbase(1:500));
 
-->xsetech([0,1/2,1,1/2])
 
-->plot2d(t(1:500),corrsignalbase(1:500))
Figure 9.1: Autocorrelation of `signalbase': A simulation of alpha rhythm (upper trace) and its autocorrelation (lower trace)
\begin{figure}
\epsfbox{figures/corr1.eps}
\end{figure}
At first sight both traces seem very similar. The bottom frame which plots the autocorrelation of the signal seems to decrease in amplitude. Another difference is that while the upper trace spans from -2 to 2, the lower trace (the autocorrelation) spans from -1 to 1.

We can see autocorrelation as a way to detect periodicity in signals. The following code represents only a few values to improve the resolution.


-->xbasc()
 
 
-->corrsignalbase = corr (signalbase,1000);
 
-->xsetech([0,0,1,1/2])
 
-->plot2d(t(1:50),signalbase(1:50));
 
-->xsetech([0,1/2,1,1/2])
 
-->plot2d(t(1:50),corrsignalbase(1:50))
Figure 9.2: Autocorrelation of `signalbase': an expansion of the previous figure to stress the periodicity at 10 Hz (period of 0.1 s)
\begin{figure}
\epsfbox{figures/corr2.eps}
\end{figure}
We can see that the autocorrelation detects a periodicity whose period is 0.1 seconds, the basic frequency of our signal. But we usually work on noised signals and we are interested in how the correlation of a signal is affected by noise.


next up previous contents
Next: Correlation of noise Up: Correlation Previous: Correlation   Contents
j 2003-01-23