Discrete Fourier Transform to find phase shift - Mathematica

In summary: FFT.If we generalize it a little, so thatf_1(t) = a_1\cos(\omega t + d_1)f_2(t) = a_2\cos(\omega t + d_2)Is there a way to get the relative amplitude a_1/a_2 from this method?No, the amplitude is only given for the dominant frequency.
  • #1
NeoDevin
334
2
If I use the following code in Mathematica

Code:
f1[t_] := Cos[w t + d1]; f2[t_] := Cos[w t + d2];
data1 = Table[f1[t], {t,1,10000}]; data2 = Table[f2[t], {t,1,10000}];
ft1 = Fourier[data1]; ft2 = Fourier[data2];

To take the Fourier transform of two data sets, how can I use the resulting data to determine the difference d2-d1?
 
Physics news on Phys.org
  • #2
Thread moved from Calculus to EE for a bit.

I'm not sure I understand what you are wanting to do. Are you trying to get some information about the phase shifts in the initial datasets after you take a Fourier transform of the datasets? Seems like a standard FT would not preserve that information...
 
  • #3
That's exactly what I'm trying to do. I'm just using the test functions for now, once I figure it out, I will have two data sets, which (should) have the same dominant frequencies, but I need to find out the phase shift between them.
 
  • #4
Does the FT in Mathematica give you complex data? If there is phase shift information, it seems like it would have to be in the complex domain of the FT output... (I'm no expert in FT stuff, BTW)
 
  • #5
Yes the output is complex, but it produces a range of frequencies, not just the dominant one. Should I just take the maximum (magnitude) of each transform, and divide them to find the phase shift?
 
  • #6
NeoDevin said:
Yes the output is complex, but it produces a range of frequencies, not just the dominant one. Should I just take the maximum (magnitude) of each transform, and divide them to find the phase shift?

Magnitudes don't help with phase information. Look at the Re and I am components at the dominant frequency, and compare those to the phase shift in your original data. Do the Re and I am components correspond to the original phase shift? Like, if you put in a 45 degree phase shift (PI/4) in the original sine wave data, do you get an FT where the complex components at that frequency show the PI/4 phase shift from Re to I am (or whichever direction it rotates)?
 
  • #7
i wouldn't even bother with the Fourier Transform. but if neither f1[.] or f2[.] are a known sinusoid (both are measured), then i might bother with the Hilbert Transform. but let's say that the parameters of f1[.] are known. if you can generate (from the paramenters):

[tex] f_1(t) = \cos(\omega t + d_1) [/tex]

(why not set d1 to 0?) then you can also generate (from the same parameters)

[tex] g_1(t) = \sin(\omega t + d_1) [/tex]

now, if you cannot generate f1(.) (and thus not g1(.)), and are given f1 as data, then you need to Hilbert transform f1 to get g1. from f1 and g1, you cross-correlate these against f2 and you will get relative amplitudes of the components of f2 that is in-phase with f1 and g1. from those two relative amplitudes, apply the complex arg and you have your phase difference. explicitly

[tex] A = \sum_n f_1[n] f_2[n] w[n] [/tex]

[tex] B = \sum_n g_1[n] f_2[n] w[n] [/tex]

where w[n] is a suitable window function of your choice.

[tex] d_2-d_1 = \arg\{A+iB\} = \arctan\left( \frac{B}{A} \right) [/tex]

the latter equality is true only if A>0. you need to use the atan2(B,A) function to put it in the correct quadrant.
 
  • #8
I think you will be better off using cross correlation than the FFT. For example:

ListCorrelate[data1,data2,1]

will give you a list with peaks at the locations corresponding to the shifts required to "match" the two signals.
 
  • #9
rbj,
From my experimentation, your method gives [itex]d_1 - d_2[/itex], but other than that, it's perfect, thanks.

If we generalize it a little, so that

[tex]f_1(t) = a_1\cos(\omega t + d_1)[/tex]
[tex]f_2(t) = a_2\cos(\omega t + d_2)[/tex]

Is there a way to get the relative amplitude [itex]a_1/a_2[/itex] from this method?
 
  • #10
NeoDevin said:
rbj,
From my experimentation, your method gives [itex]d_1 - d_2[/itex], but other than that, it's perfect, thanks.

yeah, other than the fact that it was meant to work in opposite world where "up" is down, "left" is right, "positive" is negative, "right" equals wrong (but i thought it equalled left), "good" is evil. whatever. other than that, it's perfect. :rolleyes:

If we generalize it a little, so that

[tex]f_1(t) = a_1\cos(\omega t + d_1)[/tex]
[tex]f_2(t) = a_2\cos(\omega t + d_2)[/tex]

Is there a way to get the relative amplitude [itex]a_1/a_2[/itex] from this method?

the same simple way you would measure magnitude gain of a filter. rectify, smooth, and divide. or you can square, smooth, divide, and square root. or you can Hilbert transform both. for each quadrature pair, square each and add, no need to smooth, divide, and square root. i dunno.
 

1. What is the Discrete Fourier Transform (DFT)?

The Discrete Fourier Transform (DFT) is a mathematical tool used to analyze the frequency components of a discrete signal. It converts a signal from its original representation in the time domain to a representation in the frequency domain.

2. How is the DFT used to find phase shift?

The DFT can be used to find the phase shift between two signals by analyzing the frequency components of each signal. The phase shift can be determined by calculating the difference between the phases of the corresponding frequency components in the two signals.

3. What is the difference between the DFT and the Fast Fourier Transform (FFT)?

The DFT and the FFT are both mathematical algorithms used to calculate the frequency components of a signal. The main difference between them is that the FFT is a more efficient version of the DFT, with a faster computation time.

4. Can Mathematica perform a DFT to find phase shift?

Yes, Mathematica has built-in functions such as Fourier and FourierTransform that can perform DFT calculations, including finding phase shifts between signals.

5. What are some potential applications of using DFT to find phase shift?

DFT can be applied in various fields such as signal processing, image processing, and audio analysis. It can be used to analyze the frequency components of signals and detect any changes or phase shifts, which can be useful in identifying patterns and anomalies in data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
8K
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
7K
Back
Top