Synchronization 3 vectors with different length and frequency

Hi all, I am interested to understand how the synchronization works. I am searching for a solution and I saw more resolutive tools like crosscorrelation and other stuff. Till now I used interp1 and resample but I am not sure if my tecnique is correct.
I have three output signals A, B,C coming from 3 devices that are recording an event. The signals come with different sizes because the acquisitions started in different moments. Furthermore, the signal have 3 differents sample rates f_A[10^2] < f_B[10^2] < f_C[10^4].
The aim is to isolate the proper event for each signal (this means that I need the coordinate of start and end correlated to each length and frequency of each signal, i guess).
The condition is that I am able to identify the right frame of start and end event only from the signal B. I am quiete struggling to find the correct indices for vector A and C because i am not sure about how I am trying to solve it.
Data:
A=randn(1234,1);
B=randn(123456,1);
C=randn(123456789,1);
fsA=70;
fsB=150;
fsC=1800;
From B I reach 2 indices valid for B:
%output from B
.
.
output_B=[start finish];
From B I have to reach 2 indices valid for A. Can you tell me if theoretically is it reasonable?
%output from A
B=resample(B,fsB,fsA); % to sample B to the same frequency of A
B = (interp1(linspace(0,1,length(B)), B, (linspace(0,1,length(A)))))'; % to make equal length
.
.
output=[start finish]; %output valid for A
From B I have to reach 2 indices valid for C. And I am not sure if this is possible because of the Nyquist law (how can I solve it?) :
%output from C
B=resample(B,fsB,fsC); % to sample B to the same frequency of C
B = (interp1(linspace(0,1,length(B)), B, (linspace(0,1,length(C)))))'; % to make equal length
.
.
output=[start finish]; %output valid for C
I would like to understand how it has to be done because also the documentation and the various cases as upsample and downsampple creates in me some confusion.
Thanks in advance to everyboy who can help me.

8 Comments

Why not just use the
y = resample(x,tx,fs)
form of resample to directly return the interpolated/decimated signal at the desired timepoints and sample frequency?
This was posted as a Comment to a different thread originally. I requested that it be poosted as a new Question, since it was not relevant to the previous thread.
My previous Comment:
With respect to resampling signals, use the resample function. It is the best option for any sort of signal processing. I always suggest that resampling should be from a faster to a slower sampling frequency, since doing the opposite creates data where no data previously existed. So resample all the other data to match the signal with the slowest sampling frequency.
I am not certain what constitutes an ‘event’, however using the findsignal function would likely be worth exploring.
@dpb In your opinion could it be like this:
%output from A
Bnew=resample(B,[0:1/fsA:length(A)/fsA],fsA); % to sample B to the same frequency of A
.
.
output=[start finish]; %output valid for A
Can I do the same for C where fsC>fsB?
In some way the new question for @Star Strider is the same. Considering that you accept to resample and the interpolate like I ve done, how can I solve the aliasing in the last case?
%output from C fsC>>fsB
Cnew=resample(C,fsC,fsB); % to sample C to the same frequency of B
Cnew = (interp1(linspace(0,1,length(Cnew)), Cnew, (linspace(0,1,length(B)))))'; % to make equal length
.
.
outputB=[start finish]; %output valid for C but without real indices and frequency
ant then? later the outputB has to be correlated to the original size and sample rate of C.
Anyway thanks both for your interest.
Attach some real data that is representative for somebody to poke at.
If you do as @Star Strider suggests, there is no aliasing; you're downsampling to the lowest sample rate.
If you have a beginning and end time of the signal, that is computable to the time of the other signals by simply using the time interval and sample frequency -- or, if you've previously resampled to the same frequency, they're all the same set of points already and nothing else is needed.
I think you're over-thinking the problem here.
@dpb There is no aliasing till when I have to convert the indices outputB (related to fsB<fsC ant to the length of B) to the indices related now to the original length and sample rate of C. For sure I feel some confusion on it.
In order to have a little bit example, I give you A,B,C. You can find easily the beginning and end events because at some point an interval of one starts and stops. The sample rates are 70,200,1000.
Again, if this is correct because I considered to downsample, how can I have the right indices related to C?
%output from C fsC>>fsB
Cnew=resample(C,fsC,fsB); % to sample C to the same frequency of B
Cnew = (interp1(linspace(0,1,length(Cnew)), Cnew, (linspace(0,1,length(B)))))'; % to make equal length
.
.
outputB=[start finish]; %output not completed valid for C ( without real indices and frequency )
First thing is where is the time base for each -- you say they start at different times, but until you match up the beginning time offset from the last to be started to the other two, there's nothing to correlate any of the three together.
Keep only data within the overlapping absolute time -- that's simply converting the sample times to datetime and using logical addressing to keep those withi times between the origin and the end.
If you now isolate the time of the event of interest from the B signal, you will have the absolute times associated with it; now select only that data from A and C within that absolute time window.
Now you've got the data of interest at original sample rates and haven't had to do any up/down sampling at all so far.
If it's desired, you can now resample() those time traces to a common time base.
Ill-placed Answer from @DjangoTango pasted here in line as Comment by @dpb
@dpb Thank you, I think I understood you but not completely maybe. I ask you a little bit more patience. In my case I have not the right datetime of which each device started to record. I create it doing only:
timeA=0:1/fsA:(length(A)/fsA)-1
timeB=0:1/fsB:(length(B)/fsB)-1
timeC=0:1/fsC:(length(C)/fsC)-1
Am I talking of something that can not be done?
In that case, "Yes, we have no bananas today!"
If you do not have a trigger time for each (even a trigger delay would do, absolute clock time is immaterial and can be arbitrary), unless there is some way one can isolate a known to be simultaneous feature inside the waveforms themselves it's not possible to align the three.
If there were some known hardware latency that is inherent in the data acquisition setup that could be substituted instead or if the second and third are triggered from the first, then one could search for the trigger level crossing and assume that, but somehow will have to have that information to align the three, yes.
ADDENDUM:
Later thought -- I suppose if the three are started asynchronously, they're also stopped asynchronously? If you were lucky and the collection stopped simultaneously, then you could align from the end instead of the beginning. That would seem to be very unlikely to be the case, but when searching for a port in a storm...

Sign in to comment.

Answers (0)

Asked:

on 2 Jun 2022

Edited:

dpb
on 3 Jun 2022

Community Treasure Hunt

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

Start Hunting!