Hello, I am trying to get the phase difference of two signals. They are at the same frequency. One thing I could not understand is that the absolute phase value of each signal changes with the sample size but the phase difference between the two signals keeps the same. I am not so sure whether the unwrap function makes any difference here. Also,do I need use window for the FFT processing? Thanks, Jade %%%sampling freq clear all fo=10.23*10^6; %%%sampling_resolution(s) %res=100; fs=100.5*10^6; %%%duration=10048/fs duration=0.9999*10^(-4); %duration=10*10^(-4); t = 0:1/fs:duration-1/fs; tp=1*10^(-8); theta0=0; x1 = sin(2*pi*fo*t+theta0); x2 = sin(2*pi*fo*(t+tp)+theta0); s1=x1; s2=x2; s11=s1; y1 =fft(s11); N=length(y1); y = y1*2/N; m = abs(y); m(1)=m(1)/2; TTT=round(mod(fo,fs)*N/fs+1); y(TTT) theta11=unwrap(angle(y(TTT))); theta12=(angle(y(TTT))); s12=s2; y2 =fft(s12); N=length(y2); y = y2*2/N; m = abs(y); m(1)=m(1)/2; TTT=round(mod(fo,fs)*N/fs+1); y(TTT) theta21=unwrap(angle(y(TTT))); theta22=(angle(y(TTT))); (theta21-theta11)/2/pi/fo
phase difference of two signals
Started by ●October 11, 2007
Reply by ●October 11, 20072007-10-11
yunqiyunluo@gmail.com wrote:> Hello, > > I am trying to get the phase difference of two signals. > They are at the same frequency. > One thing I could not understand is that the absolute phase value of > each signal > changes with the sample size but the phase difference between the two > signals > keeps the same. I am not so sure whether the unwrap function makes any > difference here.Let's get the basics down first. What do you mean by absolute phase? Do you have some sort of reference? Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply by ●October 11, 20072007-10-11
On Oct 11, 11:52 am, Jerry Avins <j...@ieee.org> wrote:> yunqiyun...@gmail.com wrote: > > Hello, > > > I am trying to get the phase difference of two signals. > > They are at the same frequency. > > One thing I could not understand is that the absolute phase value of > > each signal > > changes with the sample size but the phase difference between the two > > signals > > keeps the same. I am not so sure whether the unwrap function makes any > > difference here. > > Let's get the basics down first. What do you mean by absolute phase? Do > you have some sort of reference? > > Jerry > -- > Engineering is the art of making what you want from things you can get. > =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF==AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF I thought an sin wave is normally assumed to have a phase value of 0 if the initial point is zero (sin(2*pi*f+0))? So why the angle function gives different phase values with the sample size N of the FFT? Thanks, Jade
Reply by ●October 11, 20072007-10-11
On Oct 12, 8:50 am, yunqiyun...@gmail.com wrote:> On Oct 11, 11:52 am, Jerry Avins <j...@ieee.org> wrote: > > > > > yunqiyun...@gmail.com wrote: > > > Hello, > > > > I am trying to get the phase difference of two signals. > > > They are at the same frequency. > > > One thing I could not understand is that the absolute phase value of > > > each signal > > > changes with the sample size but the phase difference between the two > > > signals > > > keeps the same. I am not so sure whether the unwrap function makes any > > > difference here. > > > Let's get the basics down first. What do you mean by absolute phase? Do > > you have some sort of reference? > > > Jerry > > -- > > Engineering is the art of making what you want from things you can get. > > =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF==AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF> > I thought an sin wave is normally assumed to have a phase value of 0 > if the initial point is zero > (sin(2*pi*f+0))? So why the angle function gives different phase > values with the sample size N of the FFT? > > Thanks, > JadeIf the signals are noise-free you could look for zero-crossings of course. Hardy
Reply by ●October 11, 20072007-10-11
On Oct 11, 12:50 pm, yunqiyun...@gmail.com wrote:> On Oct 11, 11:52 am, Jerry Avins <j...@ieee.org> wrote: > > yunqiyun...@gmail.com wrote: > > > I am trying to get the phase difference of two signals. > > > They are at the same frequency. > > > One thing I could not understand is that the absolute phase value of > > > each signal > > > changes with the sample size but the phase difference between the two > > > signals > > > keeps the same. I am not so sure whether the unwrap function makes any > > > difference here. > > > Let's get the basics down first. What do you mean by absolute phase? Do > > you have some sort of reference? > > > Jerry...> > I thought an sin wave is normally assumed to have a phase value of 0 > if the initial point is zero > (sin(2*pi*f+0))? So why the angle function gives different phase > values with the sample size N of the FFT?If you reference a fixed frequency sinusoid to the beginning of an FFT frame and gradually increase the frame length, the sinusoid will become non-periodic in the FFT aperture, and the fractional remainder will cause the correlation against the nearest FFT basis vectors to have a "phase error", due to the contribution of this fractional sinusoidal cycle remainder at the right or far end of the window. If you reference your fixed frequency sinusoid to the center of an FFT aperture, and keep it there as you change the frame length, the the even/oddness ratio will remain constant, and thus there will be no apparent "phase error", because the fractional cycles on both ends will cancel out. This is why phase interpolation should only be done when the FFT phase is (re)referenced to the center of the data window. e.g. put sample 0 in the middle, not on the left side or beginning, or take the conjugate of every other one of the DFT/FFT results. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Reply by ●October 11, 20072007-10-11
On Oct 11, 3:50 pm, yunqiyun...@gmail.com wrote:> > I thought an sin wave is normally assumed to have a phase value of 0 > if the initial point is zero > (sin(2*pi*f+0))? So why the angle function gives different phase > values with the sample size N of the FFT?Jade, do you have any known restriction or range limit the phase difference (like, can you assume it's always from 0 to pi/2 or from -pi/2 to +pi/ 2)? is one signal always "leading" the other? also, how do you know they are the same frequency. are they both derived from the same driving sinusoid? two trig identities to keep in mind: sin(wt + phi) * cos(wt) = (1/2)*( sin(phi) + sin(2wt + phi) ) sin(wt + phi) * sin(wt) = (1/2)*( cos(phi) - cos(2wt + phi) ) consider that the first term is a DC value, the second term a high frequency value which can be eliminated with low-pass filtering. if you know both sin(phi) and cos(phi) you know, to within an additive term that is a multiple of 2*pi, exactly what phi is. this could be restated as: y(t) * Hilbert{x(t)} = (1/2)*( sin(phi) + sin(2wt + phi) ) y(t) * x(t) = (1/2)*( cos(phi) - cos(2wt + phi) ) phi = arg{ LPF{y(t)*x(t)} + j*LPF{y(t)*Hilbert{x(t)}} } where arg{ u + j*v } = atan2(u, v) in most math libraries, including MATLAB, C, or Fortran and LPF{..} is a low-pass filtering operation that sufficiently eliminates the high frequency term, and Hilbert{..} is the Hilbert transform. a practical Hilbert transformer has a known delay to it and that same delay must also be applied to x(t) in the term that does not have the Hilbert transform. then it looks like: phi = arg{ LPF{y(t)*x(t-T)} + j*LPF{y(t)*x_h(t-T)} } where x_h(t-T) = Hilbert{x(t)} delayed by T and (obviously) x(t-T) is x(t) delayed by T. this is robust and, depending on the low-pass filter, is quite immune to noise. a lower cutoff frequency of the LPF results in more noise immunity but slower response if the phase difference changes. r b-j
Reply by ●October 11, 20072007-10-11
On Oct 11, 2:52 pm, "Ron N." <rhnlo...@yahoo.com> wrote:> On Oct 11, 12:50 pm, yunqiyun...@gmail.com wrote: > > > > > On Oct 11, 11:52 am, Jerry Avins <j...@ieee.org> wrote: > > > yunqiyun...@gmail.com wrote: > > > > I am trying to get the phase difference of two signals. > > > > They are at the same frequency. > > > > One thing I could not understand is that the absolute phase value of > > > > each signal > > > > changes with the sample size but the phase difference between the two > > > > signals > > > > keeps the same. I am not so sure whether the unwrap function makes any > > > > difference here. > > > > Let's get the basics down first. What do you mean by absolute phase? Do > > > you have some sort of reference? > > > > Jerry > ... > > > I thought an sin wave is normally assumed to have a phase value of 0 > > if the initial point is zero > > (sin(2*pi*f+0))? So why the angle function gives different phase > > values with the sample size N of the FFT? > > If you reference a fixed frequency sinusoid to the > beginning of an FFT frame and gradually increase the > frame length, the sinusoid will become non-periodic in > the FFT aperture, and the fractional remainder will > cause the correlation against the nearest FFT basis > vectors to have a "phase error", due to the contribution > of this fractional sinusoidal cycle remainder at the > right or far end of the window. > > If you reference your fixed frequency sinusoid to the > center of an FFT aperture, and keep it there as you change > the frame length, the the even/oddness ratio will remain > constant, and thus there will be no apparent "phase > error", because the fractional cycles on both ends > will cancel out. > > This is why phase interpolation should only be done > when the FFT phase is (re)referenced to the center of > the data window. e.g. put sample 0 in the middle, not > on the left side or beginning, or take the conjugate > of every other one of the DFT/FFT results. > > IMHO. YMMV. > -- > rhn A.T nicholson d.0.t C-o-MHello Ron, Thanks for mentioning the phase continuity requirement using FFT. If the FFT phase is still referenced to the left side, can this phase error be canceled out by using windowing? Thanks, Jade
Reply by ●October 11, 20072007-10-11
On Oct 11, 4:32 pm, yunqiyun...@gmail.com wrote:> On Oct 11, 2:52 pm, "Ron N." <rhnlo...@yahoo.com> wrote: > > > > > On Oct 11, 12:50 pm, yunqiyun...@gmail.com wrote: > > > > On Oct 11, 11:52 am, Jerry Avins <j...@ieee.org> wrote: > > > > yunqiyun...@gmail.com wrote: > > > > > I am trying to get the phase difference of two signals. > > > > > They are at the same frequency. > > > > > One thing I could not understand is that the absolute phase value of > > > > > each signal > > > > > changes with the sample size but the phase difference between the two > > > > > signals > > > > > keeps the same. I am not so sure whether the unwrap function makes any > > > > > difference here. > > > > > Let's get the basics down first. What do you mean by absolute phase? Do > > > > you have some sort of reference? > > > > > Jerry > > ... > > > > I thought an sin wave is normally assumed to have a phase value of 0 > > > if the initial point is zero > > > (sin(2*pi*f+0))? So why the angle function gives different phase > > > values with the sample size N of the FFT? > > > If you reference a fixed frequency sinusoid to the > > beginning of an FFT frame and gradually increase the > > frame length, the sinusoid will become non-periodic in > > the FFT aperture, and the fractional remainder will > > cause the correlation against the nearest FFT basis > > vectors to have a "phase error", due to the contribution > > of this fractional sinusoidal cycle remainder at the > > right or far end of the window. > > > If you reference your fixed frequency sinusoid to the > > center of an FFT aperture, and keep it there as you change > > the frame length, the the even/oddness ratio will remain > > constant, and thus there will be no apparent "phase > > error", because the fractional cycles on both ends > > will cancel out. > > > This is why phase interpolation should only be done > > when the FFT phase is (re)referenced to the center of > > the data window. e.g. put sample 0 in the middle, not > > on the left side or beginning, or take the conjugate > > of every other one of the DFT/FFT results. > > > IMHO. YMMV. > > -- > > rhn A.T nicholson d.0.t C-o-M > > Hello Ron, > > Thanks for mentioning the phase continuity requirement using FFT. > If the FFT phase is still referenced to the left side, can this phase > error > be canceled out by using windowing?No matter how you (non-trivially) window around the center of an FFT aperture, then the even/oddness of a fixed period sinusoid referenced to the beginning or end can still change as the FFT length independently changes. This means that the nearest bin phase(s) of an FFT may not stay constant. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Reply by ●October 11, 20072007-10-11
"Ron N." <rhnlogic@yahoo.com> writes:> <good stuff about FFTs snipped>Is the idea of applying an FFT here rather than simple correlation that you can exploit the efficiency of frequency-domain filtering by modeling the correlation as a matched filter? -- % Randy Yates % "So now it's getting late, %% Fuquay-Varina, NC % and those who hesitate %%% 919-577-9882 % got no one..." %%%% <yates@ieee.org> % 'Waterfall', *Face The Music*, ELO http://www.digitalsignallabs.com
Reply by ●October 11, 20072007-10-11
yunqiyunluo@gmail.com wrote:> On Oct 11, 11:52 am, Jerry Avins <j...@ieee.org> wrote: >> yunqiyun...@gmail.com wrote: >>> Hello, >>> I am trying to get the phase difference of two signals. >>> They are at the same frequency. >>> One thing I could not understand is that the absolute phase value of >>> each signal >>> changes with the sample size but the phase difference between the two >>> signals >>> keeps the same. I am not so sure whether the unwrap function makes any >>> difference here. >> Let's get the basics down first. What do you mean by absolute phase? Do >> you have some sort of reference? >> >> Jerry >> -- >> Engineering is the art of making what you want from things you can get. >> ����������������������������������������������������������������������� > > I thought an sin wave is normally assumed to have a phase value of 0 > if the initial point is zeroThat depends on when you first look at it.> (sin(2*pi*f+0))? So why the angle function gives different phase > values with the sample size N of the FFT?Because you start sampling at different times relative to the zero crossing. Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯






