Synchronise multiple animated lines by merging different time series

2 visualizzazioni (ultimi 30 giorni)
Hi there, can anyone helps me about the synchrnisation of four signals? In the code, the first two channels are from one system, and the last two lines represents another kind of signals. And when I run them together, the time intervals are different, the last two signals are two times faster than the first two data. Can anyone tells me how to merge the time series? For example, if I can read the first time index of the first system and read the second time point of the second system, then the time intervals could get the same. In addition, I want the window to scroll every 30 seconds, but seems only the last two subplots are scrolling, while the first two subplots freeze. Also, I have another question about the function 'drawnow', where I realize the plotting is not in real time (seconds), are there any other functions I can use so that the plot is in seconds? These signals are expected to be burst every 3 seconds.
Sorry I have so many questions to ask. Thanks a lot for your help!
clear
clc
close all
hAnimatedLine(1) = animatedline('Color',[0 .7 .7]);
hAnimatedLine(2) = animatedline('Color',[0 .7 .7]);
hAnimatedLine(3) = animatedline('Color',[0 .7 .7]);
hAnimatedLine(4) = animatedline('Color',[0 .7 .7]);
%%First two signals
axis tight
fs_eeg = 250;
opts = detectImportOptions("OpenBCI-RAW-2021-03-01_21-58-04.txt");
C = readtable('OpenBCI-RAW-2021-03-01_21-58-04.txt');
A = table2array(C(:,23));
t_eeg = (1:height(C))/fs_eeg;
%% Second system
O = readtable('CoolTerm Capture 2021-03-22 22-40-41');
O = table2array(O);
o_ch1 = O(:,1);
o_ch2 = O(:,2);
index = 1:height(O);
fs_o = 125;
t_o = (transpose(index))/fs_o;
% First system
%Create subplot channel 1
sph1 = subplot(4,1,1);
axes1 = animatedline('Color',[0 .7 .7]);
ylim([5000 10000]);
xlabel('time in seconds');
ylabel('uV');
title('EEG signals in channel 1');
%Fisrt system channel 2
sph2 = subplot(4,1,2);
ylim([20000 25000]);
axes2 = animatedline('Color',[0 .7 .7]);
xlabel('time in seconds');
ylabel('uV');
title('EEG signals in channel 2');
linkaxes([sph1,sph2],'x','xlim');
%Filter
C.EXGChannel1 = highpass(C.EXGChannel1,0.5,fs_eeg);
C.EXGChannel6 = highpass(C.EXGChannel6,0.5,fs_eeg);
%Second system
%channel 1
sph3 = subplot(4,1,3);
axes3 = animatedline('Color',[0 .7 .7]);
xlabel('time in seconds');
ylabel('uV');
title('Second System in channel 1');
%Channel 2
sph4 = subplot(4,1,4);
axes4 = animatedline('Color',[0 .7 .7]);
xlabel('time in seconds');
ylabel('uV');
title('Second System in channel 2');
linkaxes([sph3,sph4]);
threshold = 1;
while threshold
threshold = threshold + 1;
%EEG
addpoints(axes1,t_eeg(threshold),C.EXGChannel1(threshold));
addpoints(axes2,t_eeg(threshold),C.EXGChannel6(threshold));
%Second System
addpoints(axes3,t_op(threshold),op_ch1(threshold));
addpoints(axes4,t_op(threshold),op_ch2(threshold));
%For scrolling window
%xlim([max(0,t_eeg(threshold)-10) max(10,t_eeg(threshold))]);
%xlim([max(0,t_op(threshold)-10) max(10,t_op(threshold))]);
%ylim('auto');
handles.axes1.XLim = [t_eeg(threshold)-30,t_eeg(threshold)];
handles.axes1.YLim = [-10 10];
handles.axes2.XLim = [t_eeg(threshold)-30,t_eeg(threshold)];
handles.axes2.YLim = [-10 10];
handles.axes3.XLim = [t_op(threshold)-30,t_op(threshold)];
handles.axes3.YLim = [0 800];
handles.axes4.XLim = [t_op(threshold)-30,t_op(threshold)];
handles.axes4.YLim = [0 500];
%drawnow limitrate nocallbacks
drawnow limitrate
end
  2 Commenti
DGM
DGM il 23 Mar 2021
Modificato: DGM il 23 Mar 2021
The first question should be easy enough. Let's say you have data X1 following timebase T1 and you have another set of data X2 that's following a concurrent timebase T2 with a higher resolution. You can interpolate like so:
% you can make your fine dataset coarser
X2coarser=interp1(T2,X2,T1);
or on the other hand:
% you can try to add points to the coarse dataset
X1finer=interp1(T1,X1,T2);
Either way would make both correspond to a common timebase. How that fits into your code and what type of interpolation is appropriate, you'll have to decide.
As for the other questions, I'm not sure at first glance.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Animation in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by