How to calculate the synchronization error using signal time shifting

4 views (last 30 days)
Hello and Good day
I have a problem regarding calculating the following equation which is called synchronization error. the expressions in the angle brackets are mean() function. My major problem lies in the term corresponding to time shifting, which is PR(t + delta_t). I used every kind of interpolation and extrapolation methods yet the answers have been quite out of range yet.
I also searched other similar questions regarding this matter yet the answers were not helpful to my matter. The data is attached. by the way the parameter a, a = 2 in the above equation. thanks for your time devoted to my problem

Accepted Answer

Mathieu NOE
Mathieu NOE on 10 Nov 2021
Hello
this is a code that will do the time shifting and sigma computation for a time shift of - 10 to + 10 samples
seems the two signals are pretty well time aligned as the error is minimal for a delta of 0 sample
now we could refine the analysis if we would resample the data with a smaller time increment.
you can uncommet those lines if you want to see the effect of time shift on the data - but this is not a key point here
% figure(1)
% plot(tra2,Pt2,tra2,Pra2)
% pause(1)
full code :
clc
clearvars
%% load('');
load('dataP.mat')
dt = mean(diff(t));
a = 2;
Pra = Pr/a; % normalize Pr data by factor a
%% main code
samples = 10;
delta_samples = (-samples:samples);
delta_t = delta_samples*dt;
for ci = 1:numel(delta_samples)
tra = t+delta_t(ci);
% find common time axis
ind = (tra>=min(t) & tra<=max(t));
tra2 = tra(ind);
Pra2 = Pra(ind);
% resample Pt data on time axis of Pra2 data (tra2)
Pt2 = interp1(t,Pt,tra2,'linear');
% figure(1)
% plot(tra2,Pt2,tra2,Pra2)
% pause(1)
% error (cf equation)
num = mean((Pt2(:)-Pra2(:)).^2);
den = mean((Pt2(:)).^2);
sigma(ci) = num./den;
end
figure(2)
plot(delta_t,sigma);
xlabel('Delta Time (s)');
ylabel('Sigma error');
title('Synchronization Error using Signal Time Shifting');
  2 Comments
Proman
Proman on 11 Nov 2021
Dear Mathieu
Special thanks to your help. Wonderfully done!
Can you just explain a bit about the stuff in the loop? I mean these parts:
tra = t+delta_t(ci);
% find common time axis
ind = (tra>=min(t) & tra<=max(t));
tra2 = tra(ind);
Pra2 = Pra(ind);
% resample Pt data on time axis of Pra2 data (tra2)
Pt2 = interp1(t,Pt,tra2,'linear');
To my opinion, this algorithm of yours can not only be used for signal shifting, but also for time reversal and signal scaling, am I right?
Mathieu NOE
Mathieu NOE on 12 Nov 2021
hello Quantum
tra : we create a time shifted version of t for data Pra
of course to do the sigma error computation both data Pt and Pra must have same length so we have to keep only the common part of both data sets. this new common time axis (data) is tra2;
then we have to compute the Pt data for this truncated time vector so that's why we use interp1 function to have Pt data for tra2 time vector
after that the sigma error computation is straightforward
yes , in a similar manner you could do time reversal
signal scaling for me is simply correcting y scale so that is the factor a in your code

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!