From: jayashree bulusu on 30 Jul 2010 02:39 "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2sccb$hp2$1(a)fred.mathworks.com>... > "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.. Hi Is there any analogous command for spectrogram in case of cross correlation?? Thank you.
From: jayashree bulusu on 6 Aug 2010 06:33 "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2ts27$ifl$1(a)fred.mathworks.com>... > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2sccb$hp2$1(a)fred.mathworks.com>... > > "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.. > Hi > > Is there any analogous command for spectrogram in case of cross correlation?? > > Thank you. Hi I have used the cpsd function to obtain the cross power spectrum between two signals and then i have obtained the cross phase between the two over time as well as frequency. Thus i obtain a dynamic cross phase plot. Below i have given the Matlab code for the same. But the resolution is not good. Can you suggest me some method to increase the resolution. also if you could check the matlab code ..then that would be great. clc clear all Fs = 1000; t = 0:(1/Fs):1-(1/Fs); l=length(t); x=4*sin(2*pi*t)+rand(size(t)); y=sin(2*pi*t-pi/4)+rand(size(t)); nfft=64; k=fix( (1000-(nfft/2)) / (nfft-(nfft/2)) ); c=mod(length(x),k); if c~=0 wl=(length(x)-c)/k; else wl=(length(x))/k; end for i=0:1:k-1 xx = x(i*wl+1:(i+1)*wl); yy = y(i*wl+1:(i+1)*wl); [Pxy,F]= cpsd(xx,yy,20,10,64,Fs); crp=angle(Pxy); phase(:,i+1)=crp; f(:,i+1)=F; pxy(:,i+1)=Pxy; end T=(1:wl:length(x)-c); figure surf(T,f(:,1),10*log(phase*180/pi)),'Edgecolor','none'); view(0,90);. looking forward to your reply. thank you.
From: Wayne King on 6 Aug 2010 07:03
"jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i3gocv$qod$1(a)fred.mathworks.com>... > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2ts27$ifl$1(a)fred.mathworks.com>... > > "jayashree bulusu" <bulusujayashree(a)gmail.com> wrote in message <i2sccb$hp2$1(a)fred.mathworks.com>... > > > "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.. > > Hi > > > > Is there any analogous command for spectrogram in case of cross correlation?? > > > > Thank you. > > > > > Hi > I have used the cpsd function to obtain the cross power spectrum between two signals and then i have obtained the cross phase between the two over time as well as frequency. Thus i obtain a dynamic cross phase plot. Below i have given the Matlab code for the same. But the resolution is not good. Can you suggest me some method to increase the resolution. also if you could check the matlab code ..then that would be great. > > clc > clear all > Fs = 1000; > t = 0:(1/Fs):1-(1/Fs); > l=length(t); > x=4*sin(2*pi*t)+rand(size(t)); > y=sin(2*pi*t-pi/4)+rand(size(t)); > nfft=64; > k=fix( (1000-(nfft/2)) / (nfft-(nfft/2)) ); > c=mod(length(x),k); > if c~=0 > wl=(length(x)-c)/k; > else > wl=(length(x))/k; > end > > for i=0:1:k-1 > xx = x(i*wl+1:(i+1)*wl); > yy = y(i*wl+1:(i+1)*wl); > > > [Pxy,F]= cpsd(xx,yy,20,10,64,Fs); > crp=angle(Pxy); > phase(:,i+1)=crp; > f(:,i+1)=F; > pxy(:,i+1)=Pxy; > end > > > > T=(1:wl:length(x)-c); > > > figure > surf(T,f(:,1),10*log(phase*180/pi)),'Edgecolor','none'); > view(0,90);. > > > > looking forward to your reply. > thank you. Hi Jayashree, Without getting into the details of your example, I think one immediate problem is you have two signals that are only one second in length sampled at 1000 Hz with frequencies of just 1 Hz. These signals are only completing one period over the time interval. There is no time-varying behavior (except their periodicity). Presumably, if you are attempting to do a time-varying cross spectrum, you expect the frequency content of your time series to change over the duration of the data acquisition. In your case, the frequency content of your signals does not change at all. I think you should take some time to work on simulations where the frequency content of the signals changes in some prescribed way over the duration of the recording. Wayne Wayne |