From: Wayne King on 29 Jul 2010 10:50 "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2s2kp$7ec$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2pmf8$sqv$1(a)fred.mathworks.com>... > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2pkg1$hh8$1(a)fred.mathworks.com>... > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2p662$5da$1(a)fred.mathworks.com>... > > > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2p4p0$437$1(a)fred.mathworks.com>... > > > > > > > > > > Hello, > > > > > I am working on the data of magnetic fields.I need to obtain the cross phase between two time series. also i would like to know > > > > > How to dynamic cross phase spectrum between two signals using matlab > > > > > > > > Hi Jayashree, > > > > > > > > In the Signal Processing Toolbox, cpsd() returns the (complex-valued) cross-spectrum of two stationary time series. You can obtain the relative phase information between the two time series as the inverse tangent of the negative of the quadrature spectrum (imaginary part of the cross-spectrum) divided by the co-spectrum (real part of the cross spectrum). > > > > > > > > Hope that helps, > > > > Wayne > > > hello Wayne > > > > > > Thanks for that information. > > > i have tried the following Matlab code. can you suggest if my code is right??? > > > secondly, this gives me a static plot. what if i need a dynamic plot with similar crossphase information. > > > > > > clc > > > clear all > > > > > > t=(0:99)/100; > > > x1=sin(2*pi*t)+cos((pi*t)/2); > > > x2=cos(2*pi*t)+cos(5*pi*t+pi/2); > > > [pxy,f]=cpsd(x1,x2,[],[],128,100); > > > cr=atan2(imag(pxy),real(pxy)); > > > plot(f,cr) > > > > > > > > > Looking forward to your reply, > > > > > > Thank you > > > > > > Jayashree > > > > Hi Jayashree, I apologize that I don't have time at the moment to delve into your example (I'll try to look at it in a bit), but consider this one: > > > > Fs = 1000; > > t = 0:(1/Fs):1-(1/Fs); > > x = cos(2*pi*100*t)+randn(size(t)); > > % note the relative phase difference between the x and y > > y = cos(2*pi*100*t-pi/4)+randn(size(t)); > > [Pxy,F] = cpsd(x,y,200,50,200,Fs); > > plot(F,abs(Pxy)); > > [~,index] = max(abs(Pxy)); > > Ph = atan2(-imag(Pxy),real(Pxy)); > > plot(F,Ph); > > % note the value of Ph(index) > > Ph(index) > > > > For me the answer is -0.7948 very close to the true -pi/4. Obviously, the use of randn() will not produce the exact value for you, but you should see that it is close. > > > > Wayne > > > hi > > thanks for the reply. It was informative. the plot that i obtain from there is the static plot. can you suggest some method to obtain the dynamic spectra of the same. > > Thank you, > Jayashree Hi, Can you define what you mean by "dynamic" spectrum? Are you referring to a time-frequency analysis where the input signal is segmented and spectral estimates are produced for each segment in order to display spectral changes for nonstationary processes? (such as the spectrogram for example). Wayne
From: jayashree bulusu on 29 Jul 2010 12:06 "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2s4fh$8n6$1(a)fred.mathworks.com>... > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2s2kp$7ec$1(a)fred.mathworks.com>... > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2pmf8$sqv$1(a)fred.mathworks.com>... > > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2pkg1$hh8$1(a)fred.mathworks.com>... > > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2p662$5da$1(a)fred.mathworks.com>... > > > > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2p4p0$437$1(a)fred.mathworks.com>... > > > > > > > > > > > > Hello, > > > > > > I am working on the data of magnetic fields.I need to obtain the cross phase between two time series. also i would like to know > > > > > > How to dynamic cross phase spectrum between two signals using matlab > > > > > > > > > > Hi Jayashree, > > > > > > > > > > In the Signal Processing Toolbox, cpsd() returns the (complex-valued) cross-spectrum of two stationary time series. You can obtain the relative phase information between the two time series as the inverse tangent of the negative of the quadrature spectrum (imaginary part of the cross-spectrum) divided by the co-spectrum (real part of the cross spectrum). > > > > > > > > > > Hope that helps, > > > > > Wayne > > > > hello Wayne > > > > > > > > Thanks for that information. > > > > i have tried the following Matlab code. can you suggest if my code is right??? > > > > secondly, this gives me a static plot. what if i need a dynamic plot with similar crossphase information. > > > > > > > > clc > > > > clear all > > > > > > > > t=(0:99)/100; > > > > x1=sin(2*pi*t)+cos((pi*t)/2); > > > > x2=cos(2*pi*t)+cos(5*pi*t+pi/2); > > > > [pxy,f]=cpsd(x1,x2,[],[],128,100); > > > > cr=atan2(imag(pxy),real(pxy)); > > > > plot(f,cr) > > > > > > > > > > > > Looking forward to your reply, > > > > > > > > Thank you > > > > > > > > Jayashree > > > > > > Hi Jayashree, I apologize that I don't have time at the moment to delve into your example (I'll try to look at it in a bit), but consider this one: > > > > > > Fs = 1000; > > > t = 0:(1/Fs):1-(1/Fs); > > > x = cos(2*pi*100*t)+randn(size(t)); > > > % note the relative phase difference between the x and y > > > y = cos(2*pi*100*t-pi/4)+randn(size(t)); > > > [Pxy,F] = cpsd(x,y,200,50,200,Fs); > > > plot(F,abs(Pxy)); > > > [~,index] = max(abs(Pxy)); > > > Ph = atan2(-imag(Pxy),real(Pxy)); > > > plot(F,Ph); > > > % note the value of Ph(index) > > > Ph(index) > > > > > > For me the answer is -0.7948 very close to the true -pi/4. Obviously, the use of randn() will not produce the exact value for you, but you should see that it is close. > > > > > > Wayne > > > > > > hi > > > > thanks for the reply. It was informative. the plot that i obtain from there is the static plot. can you suggest some method to obtain the dynamic spectra of the same. > > > > Thank you, > > Jayashree > > Hi, Can you define what you mean by "dynamic" spectrum? Are you referring to a time-frequency analysis where the input signal is segmented and spectral estimates are produced for each segment in order to display spectral changes for nonstationary processes? (such as the spectrogram for example). > > Wayne Hi, What you have said is right to a certain extent. By Dynamic spectra i mean time -frequency analysis of the input signal to obtain the spectral changes in the non stationary processes. As in case of spectrogram we obtain power spectrum over the frequency and time range, in a similar fashion i need to obtain the cross spectral power and phase difference in terms of time and frequency . The difference of dynamic cross phase spectrum from the spectrogram is that the former contains the phase difference between two signals over a range of frequency at a given time, with the time function being shifted or in other words the input signal is segmented, where as the spectrogram contains the power spectrum over a range of frequencies at a given time. Spectrogram deals with a single signal where as the dynamic cross phase spectrum is obtained from the cross spectra of two different signal. The output of the dynamic cross phase spectra is same as that of the spectrogram with the difference being instead of auto correlated power it is the cross correlated power and phase difference that is being plotted. I hope i could make my problem statement clear. Any information regarding the same is of worth. Looking forward to reply. Thanking you, Jayashree
From: Wayne King on 29 Jul 2010 12:39 "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2s8tc$224$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2s4fh$8n6$1(a)fred.mathworks.com>... > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2s2kp$7ec$1(a)fred.mathworks.com>... > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2pmf8$sqv$1(a)fred.mathworks.com>... > > > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2pkg1$hh8$1(a)fred.mathworks.com>... > > > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2p662$5da$1(a)fred.mathworks.com>... > > > > > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2p4p0$437$1(a)fred.mathworks.com>... > > > > > > > > > > > > > > Hello, > > > > > > > I am working on the data of magnetic fields.I need to obtain the cross phase between two time series. also i would like to know > > > > > > > How to dynamic cross phase spectrum between two signals using matlab > > > > > > > > > > > > Hi Jayashree, > > > > > > > > > > > > In the Signal Processing Toolbox, cpsd() returns the (complex-valued) cross-spectrum of two stationary time series. You can obtain the relative phase information between the two time series as the inverse tangent of the negative of the quadrature spectrum (imaginary part of the cross-spectrum) divided by the co-spectrum (real part of the cross spectrum). > > > > > > > > > > > > Hope that helps, > > > > > > Wayne > > > > > hello Wayne > > > > > > > > > > Thanks for that information. > > > > > i have tried the following Matlab code. can you suggest if my code is right??? > > > > > secondly, this gives me a static plot. what if i need a dynamic plot with similar crossphase information. > > > > > > > > > > clc > > > > > clear all > > > > > > > > > > t=(0:99)/100; > > > > > x1=sin(2*pi*t)+cos((pi*t)/2); > > > > > x2=cos(2*pi*t)+cos(5*pi*t+pi/2); > > > > > [pxy,f]=cpsd(x1,x2,[],[],128,100); > > > > > cr=atan2(imag(pxy),real(pxy)); > > > > > plot(f,cr) > > > > > > > > > > > > > > > Looking forward to your reply, > > > > > > > > > > Thank you > > > > > > > > > > Jayashree > > > > > > > > Hi Jayashree, I apologize that I don't have time at the moment to delve into your example (I'll try to look at it in a bit), but consider this one: > > > > > > > > Fs = 1000; > > > > t = 0:(1/Fs):1-(1/Fs); > > > > x = cos(2*pi*100*t)+randn(size(t)); > > > > % note the relative phase difference between the x and y > > > > y = cos(2*pi*100*t-pi/4)+randn(size(t)); > > > > [Pxy,F] = cpsd(x,y,200,50,200,Fs); > > > > plot(F,abs(Pxy)); > > > > [~,index] = max(abs(Pxy)); > > > > Ph = atan2(-imag(Pxy),real(Pxy)); > > > > plot(F,Ph); > > > > % note the value of Ph(index) > > > > Ph(index) > > > > > > > > For me the answer is -0.7948 very close to the true -pi/4. Obviously, the use of randn() will not produce the exact value for you, but you should see that it is close. > > > > > > > > Wayne > > > > > > > > > hi > > > > > > thanks for the reply. It was informative. the plot that i obtain from there is the static plot. can you suggest some method to obtain the dynamic spectra of the same. > > > > > > Thank you, > > > Jayashree > > > > Hi, Can you define what you mean by "dynamic" spectrum? Are you referring to a time-frequency analysis where the input signal is segmented and spectral estimates are produced for each segment in order to display spectral changes for nonstationary processes? (such as the spectrogram for example). > > > > Wayne > > Hi, > > What you have said is right to a certain extent. By Dynamic spectra i mean time -frequency analysis of the input signal to obtain the spectral changes in the non stationary processes. > > As in case of spectrogram we obtain power spectrum over the frequency and time range, in a similar fashion i need to obtain the cross spectral power and phase difference in terms of time and frequency . > > The difference of dynamic cross phase spectrum from the spectrogram is that the former contains the phase difference between two signals over a range of frequency at a given time, with the time function being shifted or in other words the input signal is segmented, where as the spectrogram contains the power spectrum over a range of frequencies at a given time. > > Spectrogram deals with a single signal where as the dynamic cross phase spectrum is obtained from the cross spectra of two different signal. > > The output of the dynamic cross phase spectra is same as that of the spectrogram with the difference being instead of auto correlated power it is the cross correlated power and phase difference that is being plotted. > > I hope i could make my problem statement clear. > > Any information regarding the same is of worth. > > Looking forward to reply. > > Thanking you, > Jayashree Hi Jayashree, I understand what the spectrogram is. I was just drawing an analogy. The short-time Fourier transform gives a time-frequency picture and you want a similar one with the cross spectrum. I understand. You can certainly use cpsd() as the core function in a routine that computes the cross spectrum of two time-varying inputs. Just segment your time series X and Y, compute the cross spectrum of those segments, and save them in a matrix. You can have each column of the matrix represent the cross spectrum of one segment. You'll probably want to overlap your segments (I'm not taking about the overlap that is done as part of the Welch analysis), so if you decide on segments of length 500, you probably don't want to step 500 points so that your segments are disjoint. If you have the R2010b pre-release of the Wavelet Toolbox software, there is a new function called wcoher() that computes the wavelet coherence between two nonstationary time series. If you use a complex-valued analyzing wavelet, you can extract relative phase information. Write back if you elect to use cpsd() and get stuck. Wayne
From: jayashree bulusu on 29 Jul 2010 13:02 "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2pmf8$sqv$1(a)fred.mathworks.com>... > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2pkg1$hh8$1(a)fred.mathworks.com>... > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2p662$5da$1(a)fred.mathworks.com>... > > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2p4p0$437$1(a)fred.mathworks.com>... > > > > > > > > Hello, > > > > I am working on the data of magnetic fields.I need to obtain the cross phase between two time series. also i would like to know > > > > How to dynamic cross phase spectrum between two signals using matlab > > > > > > Hi Jayashree, > > > > > > In the Signal Processing Toolbox, cpsd() returns the (complex-valued) cross-spectrum of two stationary time series. You can obtain the relative phase information between the two time series as the inverse tangent of the negative of the quadrature spectrum (imaginary part of the cross-spectrum) divided by the co-spectrum (real part of the cross spectrum). > > > > > > Hope that helps, > > > Wayne > > hello Wayne > > > > Thanks for that information. > > i have tried the following Matlab code. can you suggest if my code is right??? > > secondly, this gives me a static plot. what if i need a dynamic plot with similar crossphase information. > > > > clc > > clear all > > > > t=(0:99)/100; > > x1=sin(2*pi*t)+cos((pi*t)/2); > > x2=cos(2*pi*t)+cos(5*pi*t+pi/2); > > [pxy,f]=cpsd(x1,x2,[],[],128,100); > > cr=atan2(imag(pxy),real(pxy)); > > plot(f,cr) > > > > > > Looking forward to your reply, > > > > Thank you > > > > Jayashree > > Hi Jayashree, I apologize that I don't have time at the moment to delve into your example (I'll try to look at it in a bit), but consider this one: > > Fs = 1000; > t = 0:(1/Fs):1-(1/Fs); > x = cos(2*pi*100*t)+randn(size(t)); > % note the relative phase difference between the x and y > y = cos(2*pi*100*t-pi/4)+randn(size(t)); > [Pxy,F] = cpsd(x,y,200,50,200,Fs); > plot(F,abs(Pxy)); > [~,index] = max(abs(Pxy)); > Ph = atan2(-imag(Pxy),real(Pxy)); > plot(F,Ph); > % note the value of Ph(index) > Ph(index) > > For me the answer is -0.7948 very close to the true -pi/4. Obviously, the use of randn() will not produce the exact value for you, but you should see that it is close. > > Wayne hi thanks for the reply. It was informative. the plot that i obtain from there is the static plot. can you suggest some method to obtain the dynamic spectra of the same. Thank you, Jayashree
From: jayashree bulusu on 29 Jul 2010 13:05
"Wayne King" <wmkingty(a)gmail.com> wrote in message <i2sar8$754$1(a)fred.mathworks.com>... > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2s8tc$224$1(a)fred.mathworks.com>... > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2s4fh$8n6$1(a)fred.mathworks.com>... > > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2s2kp$7ec$1(a)fred.mathworks.com>... > > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2pmf8$sqv$1(a)fred.mathworks.com>... > > > > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2pkg1$hh8$1(a)fred.mathworks.com>... > > > > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2p662$5da$1(a)fred.mathworks.com>... > > > > > > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2p4p0$437$1(a)fred.mathworks.com>... > > > > > > > > > > > > > > > > Hello, > > > > > > > > I am working on the data of magnetic fields.I need to obtain the cross phase between two time series. also i would like to know > > > > > > > > How to dynamic cross phase spectrum between two signals using matlab > > > > > > > > > > > > > > Hi Jayashree, > > > > > > > > > > > > > > In the Signal Processing Toolbox, cpsd() returns the (complex-valued) cross-spectrum of two stationary time series. You can obtain the relative phase information between the two time series as the inverse tangent of the negative of the quadrature spectrum (imaginary part of the cross-spectrum) divided by the co-spectrum (real part of the cross spectrum). > > > > > > > > > > > > > > Hope that helps, > > > > > > > Wayne > > > > > > hello Wayne > > > > > > > > > > > > Thanks for that information. > > > > > > i have tried the following Matlab code. can you suggest if my code is right??? > > > > > > secondly, this gives me a static plot. what if i need a dynamic plot with similar crossphase information. > > > > > > > > > > > > clc > > > > > > clear all > > > > > > > > > > > > t=(0:99)/100; > > > > > > x1=sin(2*pi*t)+cos((pi*t)/2); > > > > > > x2=cos(2*pi*t)+cos(5*pi*t+pi/2); > > > > > > [pxy,f]=cpsd(x1,x2,[],[],128,100); > > > > > > cr=atan2(imag(pxy),real(pxy)); > > > > > > plot(f,cr) > > > > > > > > > > > > > > > > > > Looking forward to your reply, > > > > > > > > > > > > Thank you > > > > > > > > > > > > Jayashree > > > > > > > > > > Hi Jayashree, I apologize that I don't have time at the moment to delve into your example (I'll try to look at it in a bit), but consider this one: > > > > > > > > > > Fs = 1000; > > > > > t = 0:(1/Fs):1-(1/Fs); > > > > > x = cos(2*pi*100*t)+randn(size(t)); > > > > > % note the relative phase difference between the x and y > > > > > y = cos(2*pi*100*t-pi/4)+randn(size(t)); > > > > > [Pxy,F] = cpsd(x,y,200,50,200,Fs); > > > > > plot(F,abs(Pxy)); > > > > > [~,index] = max(abs(Pxy)); > > > > > Ph = atan2(-imag(Pxy),real(Pxy)); > > > > > plot(F,Ph); > > > > > % note the value of Ph(index) > > > > > Ph(index) > > > > > > > > > > For me the answer is -0.7948 very close to the true -pi/4. Obviously, the use of randn() will not produce the exact value for you, but you should see that it is close. > > > > > > > > > > Wayne > > > > > > > > > > > > hi > > > > > > > > thanks for the reply. It was informative. the plot that i obtain from there is the static plot. can you suggest some method to obtain the dynamic spectra of the same. > > > > > > > > Thank you, > > > > Jayashree > > > > > > Hi, Can you define what you mean by "dynamic" spectrum? Are you referring to a time-frequency analysis where the input signal is segmented and spectral estimates are produced for each segment in order to display spectral changes for nonstationary processes? (such as the spectrogram for example). > > > > > > Wayne > > > > Hi, > > > > What you have said is right to a certain extent. By Dynamic spectra i mean time -frequency analysis of the input signal to obtain the spectral changes in the non stationary processes. > > > > As in case of spectrogram we obtain power spectrum over the frequency and time range, in a similar fashion i need to obtain the cross spectral power and phase difference in terms of time and frequency . > > > > The difference of dynamic cross phase spectrum from the spectrogram is that the former contains the phase difference between two signals over a range of frequency at a given time, with the time function being shifted or in other words the input signal is segmented, where as the spectrogram contains the power spectrum over a range of frequencies at a given time. > > > > Spectrogram deals with a single signal where as the dynamic cross phase spectrum is obtained from the cross spectra of two different signal. > > > > The output of the dynamic cross phase spectra is same as that of the spectrogram with the difference being instead of auto correlated power it is the cross correlated power and phase difference that is being plotted. > > > > I hope i could make my problem statement clear. > > > > Any information regarding the same is of worth. > > > > Looking forward to reply. > > > > Thanking you, > > Jayashree > > Hi Jayashree, I understand what the spectrogram is. I was just drawing an analogy. The short-time Fourier transform gives a time-frequency picture and you want a similar one with the cross spectrum. I understand. > > You can certainly use cpsd() as the core function in a routine that computes the cross spectrum of two time-varying inputs. Just segment your time series X and Y, compute the cross spectrum of those segments, and save them in a matrix. You can have each column of the matrix represent the cross spectrum of one segment. > > You'll probably want to overlap your segments (I'm not taking about the overlap that is done as part of the Welch analysis), so if you decide on segments of length 500, you probably don't want to step 500 points so that your segments are disjoint. > > If you have the R2010b pre-release of the Wavelet Toolbox software, there is a new function called wcoher() that computes the wavelet coherence between two nonstationary time series. If you use a complex-valued analyzing wavelet, you can extract relative phase information. > > Write back if you elect to use cpsd() and get stuck. > > Wayne Hi, Thank you for the valuable information. I will try using the cpsd() for the same. If there is some query i shall let you know. Thank you once again. |