4 views (last 30 days)

I have this set of 8 signals, I am trying to find the peaks of each signal with respect to time and also I want to find the phase shift of Oscillator 2 to Oscillator 8 with respect to Oscillator 1 signal. Thanks in advance.

I have also attached the Data.mat file.

Bjorn Gustavsson
on 29 Jun 2020

If you had regularly sampled data (it doesn't seem so) this would best be done with spectrogram. That would give you the spectrogram of the function (i.e. the short-time-Fourier-transform). From that you should take the angle of the fundamental component as the phase-shift between the signals. In principal you could do it with the regular fft as well, but your signal seems to be a bit varying with time.

However, you might have to address the time-variation of your sampling first.

Otherwise this is how I'd do it:

[S1,F1,T1] = spectrogram(data(2,:),hanning(1024),216,[],Fs);

[S2,F2,T2] = spectrogram(data(3,:),hanning(1024),216,[],Fs);

subplot(3,1,1)

pcolor(T1,F1,log10(abs(S1))),shading flat

subplot(3,1,2)

pcolor(T2,F2,log10(abs(S2))),shading flat

subplot(3,1,2)

pcolor(T1,F1,angle(S1.*conj(S2))),shading flat

From that you'd have to start to identify the fundamental frequency of your signals, and then take the corresponding phase-shift.

HTH

Bjorn Gustavsson
on 2 Jul 2020

You need to do a couple of things before you get to your answer. First, before you get to any type of Fourier-transforming you need to look at your sample-times (I'll have to assume that is the first row of your data):

figure

subplot(3,1,1)

plot(data(1,:))

subplot(3,1,3)

hist(data(1,:),200)

hist(diff(data(1,:)),200)

hist(diff(data(1,:)),100)

hist(diff(data(1,:)),200)

subplot(3,1,2)

plot(diff(data(1,:)))

plot(diff(data(1,:)),'.')

So there you see that you have unevenly sample-intervalls. That's one task to resolve.

Then we should have a closer look at the signals (always look at the signal before analysing away):

figure

subplot(2,1,1)

plot(data(1,:),data(2:3,:))

subplot(2,1,2)

plot(data(1,:),data([2,4],:))

If you zoom in on the beginning of these plots, you'll notice that there is an "onset-time" of ~2e-5 time-units. Then you'll see that there is some change of the shift between the signals around 3e-4 - 4.5e-4 time-units.

Since you don't have regularly sampled time-series you cannot use fft-analysis straight off, but since you seem to have sufficiently high sampling rate it should be possible to interpolate your signals to a regular sequence.

t = linspace(data(1,1),data(1,end),2*numel(data(1,:)));

data2 = interp1(data(1,:),data','pchip')';

Then since you have time-varying time-shift between the signals you shouldn't Fourier-transform the entire data-set - that will not give you all information of interest. That's where the short-time-Fourier-transform comes to the rescue, that is the function spectrogram:

clf

Ts = mean(diff(t));

[S1,F1,T1] = spectrogram(data2(2,:),4*1024,1024,[],1/Ts);

[S2,F2,T2] = spectrogram(data2(3,:),4*1024,1024,[],1/Ts);

[S3,F3,T3] = spectrogram(data2(4,:),4*1024,1024,[],1/Ts);

subplot(3,2,1)

pcolor(T1,F1,log10(abs(S2))),shading flat,caxis([-2 3.5]),

ax = axis;

axis([ax(1:2),2e4 5e6])

set(gca,'YScale','log')

colormap(jet)

try

freezeColors

catch

% Useful tool on FEX

end

subplot(3,2,3)

pcolor(T1,F1,log10(abs(S2))),shading flat,caxis([-2 3.5]),

axis([ax(1:2),2e4 5e6])

set(gca,'YScale','log')

try

freezeColors

catch

% Useful tool on FEX

end

subplot(3,2,5)

pcolor(T3,F3,log10(abs(S3))),shading flat,caxis([-2 3.5]),

axis([ax(1:2),2e4 5e6])

set(gca,'YScale','log')

try

freezeColors

catch

% Useful tool on FEX

end

subplot(3,2,2)

pcolor(T3,F3,angle(S1.*conj(S2))),shading flat,caxis([-1 1]*pi),

axis([ax(1:2),2e4 5e6])

set(gca,'YScale','log')

colormap(hsv)

colorbar

subplot(3,2,4)

pcolor(T3,F3,angle(S1.*conj(S3))),shading flat,caxis([-1 1]*pi),

axis([ax(1:2),2e4 5e6])

set(gca,'YScale','log')

colorbar

subplot(3,2,6)

pcolor(T3,F3,angle(S2.*conj(S3))),shading flat,caxis([-1 1]*pi),

axis([ax(1:2),2e4 5e6])

set(gca,'YScale','log')

colorbar

There in the left column you have the PSD of the 2nd 3rtd and 4th rows in data2 and in the right column you have the cross-phases of the 3 combinations. From there you can extract the frequencies of the amplitude-peaks and the corresponding frequency-shifts. As you see the frequencies vary with time, as does the cross-phase between the 1st and second as well as the 2nd and 3rd, from ~0 to ~pi (at around 0.4e-3 time-units).

This is how you find phase-shifts, but since the spectra of your signals varies with time, you should also have a look at the time-shifts between peaks and minimas, both of the signals and their slopes.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/556330-how-to-find-peaks-of-the-given-signal-and-find-the-phase-shift-with-respect-to-the-oscillator-1-sign#comment_917083

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/556330-how-to-find-peaks-of-the-given-signal-and-find-the-phase-shift-with-respect-to-the-oscillator-1-sign#comment_917083

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/556330-how-to-find-peaks-of-the-given-signal-and-find-the-phase-shift-with-respect-to-the-oscillator-1-sign#comment_917086

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/556330-how-to-find-peaks-of-the-given-signal-and-find-the-phase-shift-with-respect-to-the-oscillator-1-sign#comment_917086

Sign in to comment.