The Neurophysiological Biomarker Toolbox (NBT)



1. Detect coherence on simple sinusoidal signals

fs = 100;  % Sampling frequency
T = 1/fs;   % Sample time
N = 1000;   % Length of signal
t = (0:N-1)*T;  % time interval
A1 = 1; % amplitude
A2 = 0.5; % amplitude
f1 = 2; % frequency Hz
f2 = 40; % frequency Hz
f3 = 1;
s1 = A1*sin(2*pi*t*f1)+A2*sin(2*pi*t*f2); % first signal
s2 = A1*sin(2*pi*t*f3)+A2*sin(2*pi*t*f2); % second signal
%--- window function
W_length = 2^4;
W = hamming(W_length);
%--- compute coherence function
[C1,f]=mscohere(s1,s1,W,[],W_length,fs); % autocoherence
[C2,f]=mscohere(s1,s2,W,[],W_length,fs);
figure
subplot(2,2,1)
plot(t,s1,'b')
axis tight
xlabel('time sec')
subplot(2,2,2)
plot(f,C1)
ylabel('MSC')
xlabel('frequency')
axis tight
ylim([0 1])
subplot(2,2,3)
plot(t,s1,'b')
hold on
axis tight
plot(t,s2,'r')
xlabel('time sec')
subplot(2,2,4)
plot(f,C2)
ylabel('MSC')
xlabel('frequency')
axis tight
ylim([0 1])
tutorial/coherence/cohercode.txt · Last modified: 2012/01/09 15:17 by Giusi Schiavone
The NBTwiki platform - version 2.8 - 9 May 2013
Copyright (C) 2008-2015