clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 22;
fprintf('Beginning to run %s.m ...\n', mfilename);
EOG_Data = load('EOG_Data.mat');
EOG_Data_v = double(EOG_Data.EOG_Data_4ch(1,:)) - double(EOG_Data.EOG_Data_4ch(2,:));
fs = 256;
N = length(EOG_Data_v);
T = 1/fs;
EOG_Time = [0:(N - 1)] * T;
subplot(2, 1, 1);
plot(EOG_Time, EOG_Data_v);
title('x_v[n]', 'FontSize', fontSize);
grid on;
Blink = EOG_Data_v(500:720);
[R, lags] = xcorr(EOG_Data_v, Blink);
R = R(lags>=0);
lags = lags(lags>=0);
[peakValues, indexesOfPeaks, widths, proms] = findpeaks(R, 'MinPeakHeight',10e6);
subplot(2, 1, 2);
plot(EOG_Time, R);
title('Occurance of Blinks from Cross-Correlation plot', 'FontSize', fontSize);
xlabel('Time in seconds', 'FontSize', fontSize);
ylabel('Voltage in mV', 'FontSize', fontSize);
grid on;
axis tight;
hold on;
plot(EOG_Time(indexesOfPeaks), peakValues, '*r')
valleyIndexes = zeros(length(widths), 2);
for k = 1 : length(widths)
valleyIndexes(k, 1) = floor(indexesOfPeaks(k) - widths(k)/2);
valleyIndexes(k, 2) = ceil(indexesOfPeaks(k) + widths(k)/2);
t1 = EOG_Time(valleyIndexes(k, 1));
t2 = EOG_Time(valleyIndexes(k, 2));
xline(t1, 'Color', 'm', 'LineWidth', 2);
xline(t2, 'Color', 'm', 'LineWidth', 2);
end
hold off;
g = gcf;
g.WindowState = 'maximized'
fprintf('Done running %s.m.\n', mfilename);
Best Answer