1

I have two periodic non-sinusoidal waveforms $WV1$ and $WV2$ (See Figure). I want to extract the fundamental components of these two (i.e. $WV1_{F0}$ and $WV2_{F0}$) and find the peak amplitudes and phase between fundamental components.

Here is a minimal code example generating waveforms. My actual waveforms are generated from a numerical data capture.

s1 = 
  1.5 Sin[ω0 t] + f31 Sin[3 ω0 t + θ3]  + f51 Sin[5 ω0 t + θ5] /. 
    {ω0 -> 2 π, f31 -> 0.2, θ3 -> π, f51 -> 0.3, θ5 -> 0};
s10 = 1.5 Sin[ω0 t] /. {ω0 -> 2 π};
s2 = Sin[ω0 t + ϕ2] + 
f32 Sin[3 ω0 t + θ3]  /. {ω0 -> 2 π, 
f32 -> 0.4, θ3 -> 0, ϕ2 -> π/3};
s20 = Sin[ω0 t + ϕ2] /. {ω0 -> 2 π, 
f32 -> 0.4, θ3 -> 0, ϕ2 -> π/3};
Plot[{s1, s2, s10, s20}, {t, 0, 2 (2 π)/ω0} /. {ω0 -> 2 π}, 
  PlotStyle -> {Red, Blue, {Red, Dashed}, {Blue, Dashed}}, 
  PlotLegends -> {"WV1", "WV2", "WV1F0", "WV2F0" }]

How can I do this using Mathematica?

enter image description here

Solution Based on @yarchik's comment and using the answer to this question:

 s1 = 
   Table[
     Sin[ω0 t] + f31 Sin[3 ω0 t + θ3]  + Sin[5 ω0 t + θ5] /. 
       {ω0 -> 2 π, f31 -> 0.2, θ3 -> π, f51 -> 0.3, θ5 -> 0}, 
     {t, -10, 10, 1/1000}];
 s2 = 
   Table[
     Sin[ω0 t + ϕ2] + Sin[3 ω0 t + θ3]  /. {ω0 -> 2 π,f32 -> 0.4, θ3 -> 0, ϕ2 -> π/3}, 
     {t, -10, 10,1/1000}];
 ffts1 = Fourier[s1, FourierParameters -> {-1, 1}];
 ffts2 = Fourier[s2, FourierParameters -> {-1, 1}];
 max = Max[Abs[ffts1]];
 pos = First[First[Position[Abs[ffts1], max]]];
 Abs[ffts2[[pos]]]/Abs[ffts1[[pos]]]
 Arg[ffts2[[pos]]] - Arg[ffts1[[pos]]]
 π/3. (*actual phase difference*)

So, my initial problem was solved.

Please let me know if there is anything wrong with my approach.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Pojj
  • 169
  • 5
  • 1
    Do a Fourier transformation on your signal. Translation (that is, delay) in the time domain is interpreted as complex phase shifts in the frequency domain and vice versa. – yarchik Nov 28 '19 at 12:19
  • 1
    Your data represents exactly two periods of the fondamental frequency. Does this corresponds to your real problem ? (if yes : it's simple, if no : it's a long story. There are problems due to the fact that there are very few periods in the data). – andre314 Nov 28 '19 at 17:37
  • @yarchik, Thanks, for the tip. It should be the way to go. I will give it a try – Pojj Nov 29 '19 at 11:44
  • @andre314, thanks, the figure was only for illustration. anyway, I will make sure I have sufficient periods. – Pojj Nov 29 '19 at 11:46
  • 1
    I'm not sure to have been clear. I mean : there are problems if there are very few periods and the number of periods is not whole number (= a integer, as opposed to a fractionnal number) – andre314 Nov 29 '19 at 15:31
  • @HenrikSchumacher, Just to clarify, why my question is closed even after I edited it with required additional information? My problem is more or less solved, just need to understand how this SE platform works. – Pojj Dec 09 '19 at 09:27

1 Answers1

1

yarchik's proposal (using the DFT and looking at the phase) is probably the right way to do this, but here is another way of locating the phase difference. Set up a simple problem where we know the answer:

a = Sin[2 Pi Range[100]/100];
b = Sin[2 Pi Range[100]/100 + 0.3];
ListPlot[{a, b}]

enter image description here

DTW (dynamic time warping) finds the best correspondence between the two signals a and b:

{n, m} = WarpingCorrespondence[a, b];

Locate the delay needed to line up the two signals, and plot to see them lined up:

delay = Length[Select[m, # == 1 &]];
ListPlot[{a[[delay ;; All]], b}]

enter image description here

bill s
  • 68,936
  • 4
  • 101
  • 191
  • Thanks for your answer, my actual signals have many harmonic components, and there can be very different harmonics content in two signals. Can your approach be still effective in such cases? I will try @yarchik's proposal and update here. – Pojj Nov 29 '19 at 11:50
  • 1
    Yes, the DTW gives the best alignment between any two signals. When the two signals are (approximately) the same but with a delay, as in your example, it should work fine to give the delay. The advantage of the DFT method is that it can give different delays for each harmonic. The advantage of the DTW is that it does not need lots of data nor does it matter what portion of a fundamental period is represented (these are the kinds of things @andre314 was warning about. – bill s Nov 29 '19 at 17:07
  • 1
    You can find an example of finding the phase difference with a DFT at this answer: https://mathematica.stackexchange.com/a/11050/1783 – bill s Dec 02 '19 at 23:23
  • Yes, Thanks. I have updated the question (with the solution) using your answer. – Pojj Dec 02 '19 at 23:32