Biomedical Engineering Reference
In-Depth Information
in the matrix, the mean routine will produce the en-
semble average.
matrix where n is the number of signals (i.e., columns of
x ). The diagonals of this matrix represent the correlation
of the signals with themselves, r xx (and, hence, will be 1),
and the off-diagonals represent the correlations of the
various combinations. For example, r 12 is the correlation
between signals 1 and 2. Because the correlation of signal
1 with signal 2 is the same as signal 2 with signal 1, r 12 ¼
r 21 , and in general r m , n ¼ r n , m , so the matrix will be
symmetrical about the diagonals:
Example 2.4.8: Load eye movement data, plot the data,
then construct and plot the ensemble average.
close all; clear all;
load vergence;
% Get vergence eye
movement data
Ts ¼ .005;
% Sample interval ¼
5 msec
2
3
r 1 ; 1
r 1 ; 2
/
r 1 ;N
4
5
r 2 ; 1
r 2 ; 2
.
r 2 ;N
[nu,N] ¼ size
(data_out) ;
% Get data length
(N)
r xx ¼
[Eq. 2.4.38]
«
« 1 «
r N; 1
r N; 2
/
r N;N
t ¼ (1:N)*Ts;
% Generate time
vector (t ¼ N Ts)
The cov routine produces a similar output, except the
diagonals are the variances of the various signals and the
off-diagonals are the covariances as shown in Eq. 2.4.39
below.
%
% Plot ensemble
data superimposed
plot(t,data_out,'k');
hold on;
%
% Construct and plot
the ensemble average
avg ¼ mean(data_out); % Calculate
ensemble
average and
2
3
s 1 ; 1
s 1 ; 2 /
s 1 ;N
4
5
s 2 ; 1
s 2 ; 2 /
s 2 ;N
S ¼
[Eq. 2.4.39]
«
« 1 «
s 2 N; 1
s 2 N; 2 .
s 2 N;N
Example 2.4.8 uses covariance and correlation analysis to
determine if sines and cosines of the same frequency and
sine waves at multiple frequencies are orthogonal. Recall
that two orthogonal signals will have zero correlation.
Either covariance or correlation could be used to de-
termine if signals are orthogonal. Example 2.4.9 uses
both.
plot(t,avg-3,'k');
% plot, separate
from the other
% data
xlabel( ' Time
(sec)');
% Label axes
ylabel
('Eye Position');
plot([.43 .43],
[0 5];'-k');
Example 2.4.9: Determine if a sine wave and a cosine
wave at the same frequency are orthogonal and if sine
waves at harmonically related frequencies are orthogonal.
Include one sinusoid at a nonharmonic frequency.
% Plot horizontal
line
text(1,1.2,'
Averaged ... Data');
% Label data
average
Solution: Generate a data matrix where the columns
consist of a 1.0-Hz sine and cosine, a 2.0-Hz sine and
cosine, and a 3.0-Hz sine and a 3.5-Hz (i.e.,
nonharmonic) cosine. The six sinusoids should all be at
different amplitudes. Apply the covariance (cov) and
correlation (corrcoef) MATLAB functions. All of the
sinusoids except the 3.5-Hz cosine are orthogonal and
should show negligible correlation and covariance.
The results are shown in Figure. 2.4-13 .
2.4.4.3 Covariance and correlation
MATLAB has specific functions for determining the
correlation and/or covariance between two or more sig-
nals. Correlation or covariance matrices are calculated
using the corrcoef or cov functions, respectively.
Again, the calls are similar for both functions:
% Example 2.4.9: Application of the
correlation and
% covariance matrices to sinusoids that
are orthogonal and
% nonorthogonal
%
clear all; close all;
N ¼ 256;
Rxx ¼ corrcoef(x); % Signal correlation
S ¼ cov(x);
% Signal covariance
where x is a matrix that contains the various signals to be
compared in columns. Some options are available as
explained in the associated MATLAB help file. The
output, Rxx, of the corrcoef routine will be an n-by-n
% Number of points in
waveform
Search WWH ::




Custom Search