If we invoke `rand' with the parameter `normal' it calculates values with a Gaussian distribution of mean `0' and variance `1'. Values obtained mostly span from -2 to +2 standard deviation, more or less from -2 to 2 uV. And if we multiply by `2', the noise signal that we are going to add will have a range of about 8 uV, more than double than `cleanvep'.
We have a matrix (`sweeps') containing in each row one trace. Extracting `cleanvep' is an easy task
-->cleanvep = 2 * (sin(%pi*[0:127]/128).^2) .* (cos(2*%pi*[0:127]/128)); -->cleanvep = [zeros(1,36), cleanvep,zeros(1,36)]; -->sweeps = cleanvep + 2 * rand (cleanvep,'normal'); -->// adds sweeps with noise -->for k=1:299 --> noisevep = cleanvep + 2 * rand (cleanvep,'normal'); --> sweeps = [sweeps ; noisevep]; -->end; -->// calculates average -->meanvep = mean (sweeps, 'r'); -->// plots it with `cleanvep' -->plot2d ([1:200;1:200]',[meanvep;cleanvep]')
This code has been written in a file and executed with `exec'. The result can be seen in figure 3.2.
This way of calculating has some problems, being perhaps the worst of them the fact that it consumes a great amount of memory and, if we use this method to average a great amount of sweeps or a great number of channels, it could be not feasible. An alternative is maintaining a buffer and adding each sweep to it (something like an averager).
But the method we used has some advantages too: we can easily calculate a `median evoked potential'
-->medianvep = median (sweeps, 'r');Median is less sensitive than mean to large values produced by artifacts. The cost to pay is that we need much more resources to obtain the graph. Some combinations of methods could be used (for instance to calculate the median for `n' traces and accumulate the result in a buffer) which would eliminate large isolated values produced by artifacts.
The process of averaging to extract low amplitude signals from noisy environments implies that the signals that we want to extract are constant and lined with the beginning of the vector. It is a general method widely used in clinical practice. We could use some variants of this technique
The extraction of repetitive characteristics by averaging is a powerful technique. Until recently, the access to the raw signal has been limited by shortage of memory. Now, and probably even more in the future, we will be able to treat very long traces. To indicate points that have some characteristic and act as triggers, one efficient method is to maintain arrays of indexes which can be used as triggers in the process of averaging. We will dedicate more attention to indexes in coming sections.