Azzera filtri
Azzera filtri

Synchronising two different signals

46 visualizzazioni (ultimi 30 giorni)
Marpe
Marpe il 15 Ott 2022
Commentato: Star Strider il 15 Ott 2022
Hello,
I am quite new to signal processing and I am trying my best to synchronize and align two signals that come from different devices.
One has a sample rate of 50 Hz and is recording acceleration with 3 axis (x, y and z). The other is recording ECG at 250Hz.
I have time marks of when both devices are turned on and off (which is different by max 10-20 seconds). Both seems to have 'time-drift', meaning that when looking at the data size, it never perfectly equals the size of Time*SampleRate. And even after resampling the 250Hz signal at 50Hz both data sizes have a small difference.
I have been trying different methods to align those signals but there is always a little delay between the two of them and I don't know what to do. I tried removing the time drift, synchronizing them with time-series, even the cross-correlation (even though I am not sure this can work since one of my signal has 3 axis)… Nothing seems to work.
So is there a way to know if there is major problem in one of the signals ?
Or is there another way of aligning/synchronizing those signals ?
I linked the two unfiltered signals.
Thanks,
Marine
  2 Commenti
Star Strider
Star Strider il 15 Ott 2022
What are we to do with these?
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1157478/Data.zip')
Uz = 1×8 cell array
{'Data/'} {'__MACOSX/._Data'} {'Data/.DS_Store'} {'__MACOSX/Data/._.DS_Store'} {'Data/ECG.csv'} {'__MACOSX/Data/._ECG.csv'} {'Data/Acceleration.csv'} {'__MACOSX/Data/._Acceleration.csv'}
EKG = readtable(Uz{5})
EKG = 904000×1 table
ECG_DATA ________ 680 1372 1740 1774 1805 1832 1853 1870 1883 1889 1884 1870 1850 1832 1815 1800
Acc = readtable(Uz{7})
Acc = 181412×18 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13 Var14 Var15 Var16 Var17 Var18 ____ ____ _____ ____ ____ ____ ____ ____ ____ ______________________ _____ _____ _____ ______ _____ _____ _____ _____ -106 -203 -1969 -157 151 -17 -32 54 -178 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 18 -87 -2052 -169 159 -17 -230 309 -296 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 129 -13 -2062 -169 151 -13 -140 245 -250 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 108 -85 -2073 -159 149 -23 -93 166 -129 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 66 -152 -2119 -169 149 -15 47 89 -143 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 81 -114 -2010 -165 145 -11 116 4 -155 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 59 -109 -2118 -170 148 -26 68 77 -144 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 154 -53 -1999 -163 143 -25 189 -35 -117 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 125 12 -1975 -158 156 -26 221 -132 56 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 9 -110 -2064 -162 142 -20 220 -267 108 {'22-10-11T09:55:47Z'} 105 266 236 1016.5 0.06 25.17 0 4.1 -59 -226 -1893 -162 152 -26 220 -182 78 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN -107 -329 -2100 -160 152 -22 -321 271 -124 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 13 -156 -2148 -158 154 -28 -371 359 -235 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 197 -5 -2076 -166 154 -26 -249 290 -205 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 175 -65 -2140 -162 154 -22 21 32 -70 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN 84 -178 -1973 -159 141 -27 201 -198 -47 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN
Just looking at them, I have no idea.
.
Marpe
Marpe il 15 Ott 2022
Yes sorry I forgot to share my code. This one of my trial to better understand.

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 15 Ott 2022
I got this far, however I have no idea what you want to do with them at this point —
% clear
% close all
% datapathECG = %Data path;
% dECG = dir(datapathECG);
% nd = length(dir);
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1157478/Data.zip');
% EKG = readtable(Uz{5})
% Acc = readtable(Uz{7})
%ECG data
for n=10
% file=[datapathECG,dECG(n).name];
% tbl = readtable(file);
tbl = readtable(Uz{5});
ecg=table2array(tbl);
[~,~]=size(ecg);
Fs1 = 250;
%Resampling of ECG from 250Hz to 50Hz
ecg=resample(ecg,50,Fs1);
[Necg,~]=size(ecg);
end
%Acceleration data
% close all
% datapathAcc= % Data path to data files
% dAcc=dir(datapathAcc);
% nd=length(dir);
for n=5
% file=[datapathAcc,dAcc(n).name];
% tbl = readtable(file);
tbl = readtable(Uz{7});
acctab=tbl(:,1:3);
Tacc=tbl(:,10);
acctab = table2array(acctab);
[Nacc,dum]=size(acctab);
Fs2=50;
end
%Remove drift in both
%ECG
StartECG = datetime(2022,10,11,07,56,40,'TimeZone','UTC');
StartECG.Format = 'hh:mm:ss';
Stop = datetime(2022,10,11,08,57,10,'TimeZone','UTC');
Stop.Format = 'hh:mm:ss';
Fs = 50;
Time = seconds(Stop - StartECG);
Nth = (Time.*Fs);
drift = Nth - Necg;
drift = drift/Fs;
drift = Nth/drift;
drift1 = round(drift/Fs);
ecg(drift1:drift1:end,:) = [];
[Necg,d]=size(ecg);
%Acceleration
DT = datetime(Tacc.Var10, 'InputFormat','yy-MM-dd''T''HHH:mm:ss''Z''','TimeZone','UTC');
DT.Format = 'hh:mm:ss';
DTnew = fillmissing(DT,'linear');
StartR = DTnew(1,1);
disp('Real = ');
Real =
disp(StartR);
09:55:47
StartR = datetime(StartR,"TimeZone","UTC");
StartR.Format = 'hh:mm:ss';
%Have to change everytime
StartTH = datetime(2022,10,11,07,55,20,'TimeZone','UTC');
StartTH.Format = 'hh:mm:ss';
disp('Theory = ');
Theory =
disp(StartTH);
07:55:20
delay = abs(StartR - StartTH);
StartACC = StartR - delay;
Stop = datetime(2022,10,11,08,56,10,'TimeZone','UTC');
Stop.Format = 'hh:mm:ss';
Fs = 50;
Time = seconds(Stop - StartACC);
Nth = (Time.*Fs);
drift = Nth - Nacc;
drift = drift/Fs;
drift = Nth/drift;
drift2 = round(drift/Fs);
acctab(drift2:drift2:end,:) = [];
[Nacc,d]=size(acctab);
%Time for ECG
time=StartECG;
time.Format= 'hh:mm:ss';
s1=seconds(1/Fs2:1/Fs2:Necg/Fs2);
T=time+s1;
Tecg = timetable(T',ecg);
%Time for Acceleration data
time=StartACC;
time.Format= 'hh:mm:ss';
s1=seconds(1/Fs2:1/Fs2:Nacc/Fs2);
T=time+s1;
Tacc = timetable(T',acctab);
TT = synchronize(Tecg,Tacc,"union","nearest");
stackedplot(TT.Time,TT.Variables);
Or, to put it differently, I do not see a problem. You have several different signals all sharing the same time vector. (I have no idea what they refer to, or what you want to wo with them.)
.
  6 Commenti
Marpe
Marpe il 15 Ott 2022
Thank you very much for your help !

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Signal Processing Toolbox 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