# How to find peaks of the given signal and find the phase shift with respect to the Oscillator 1 signal?

4 views (last 30 days)
Jaykumar Vaidya on 29 Jun 2020
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. Jaykumar Vaidya on 29 Jun 2020
I have progressed that I can find the peaks of each signal by using
[pks,locs,widths,proms] = findpeaks(data(i,:),data(1,:),'MinPeakHeight',1.7)
But then every signal has different length vector for peaks. I don't understand if I can use sampling here.
KSSV on 29 Jun 2020

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)
subplot(3,1,2)
subplot(3,1,2)
From that you'd have to start to identify the fundamental frequency of your signals, and then take the corresponding phase-shift.
HTH

Jaykumar Vaidya on 29 Jun 2020
Okay let me try this. Though, just to tell you that I do have the FFT data of all these signals. These are the signals generated by a electronic simulator and I got the FFT data of these signals too. I can change the time duration for which I want the FFT data too. Below is the FFT data snapshot. Can I use it by any means? It gives the fundamental frequency and the harmonics
This is the new time domain data and the figure. Data file is attached too.   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)
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)
axis([ax(1:2),2e4 5e6])
set(gca,'YScale','log')
try
freezeColors
catch
% Useful tool on FEX
end
subplot(3,2,5)
axis([ax(1:2),2e4 5e6])
set(gca,'YScale','log')
try
freezeColors
catch
% Useful tool on FEX
end
subplot(3,2,2)
axis([ax(1:2),2e4 5e6])
set(gca,'YScale','log')
colormap(hsv)
colorbar
subplot(3,2,4)
axis([ax(1:2),2e4 5e6])
set(gca,'YScale','log')
colorbar
subplot(3,2,6)
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.