Thank you very much for all the replies so far. I have found that my
calculation by hand gives correct result so there is some problem
probably in the simulation thoug I am using very straight forward
matlab expressions. There is no option to attach files here. I a
load('new1') %Channel 1 data with noise diode on
load('new2') %Channel 2 data with noise diode on
load('new3') %Channel 1 data with noise diode off
load('new4') %Channel 2 with noise diode off
xon1 = new1(:,2);
xon = xon1(1:24576); %number of spectra = multiple of 1024
xoff1= new3(:,2);
xoff = xoff1(1:24576);
yon1 = new2(:,2);
yon = yon1(1:24576);
yoff1 = new4(:,2);
yoff = yoff1(1:24576);
xonfft1= fft(xon(1:1024),1024);
xonfft2= fft(xon(1025:2048),1024);
xonfft3= fft(xon(2049:3072),1024);
xonfft4= fft(xon(3073:4096),1024);
xonfft5= fft(xon(4097:5120),1024);
xonfft6= fft(xon(5121:6144),1024);
xonfft7= fft(xon(6145:7168),1024);
xonfft8= fft(xon(7169:8192),1024);
xonfft9= fft(xon(8193:9216),1024);
xonfft10= fft(xon(9217:10240),1024);
xonfft11= fft(xon(10241:11264),1024);
xonfft12= fft(xon(11265:12288),1024);
xonfft13= fft(xon(12289:13312),1024);
xonfft14= fft(xon(13313:14336),1024);
xonfft15= fft(xon(14337:15360),1024);
xonfft16= fft(xon(15361:16384),1024);
xonfft17= fft(xon(16385:17408),1024);
xonfft18= fft(xon(17409:18432),1024);
xonfft19= fft(xon(18433:19456),1024);
xonfft20= fft(xon(19457:20480),1024);
xonfft21= fft(xon(20481:21504),1024);
xonfft22= fft(xon(21505:22528),1024);
xonfft23= fft(xon(22529:23552),1024);
xonfft24= fft(xon(23553:24576),1024);
xofffft1= fft(xoff(1:1024),1024);
xofffft2= fft(xoff(1025:2048),1024);
xofffft3= fft(xoff(2049:3072),1024);
xofffft4= fft(xoff(3073:4096),1024);
xofffft5= fft(xoff(4097:5120),1024);
xofffft6= fft(xoff(5121:6144),1024);
xofffft7= fft(xoff(6145:7168),1024);
xofffft8= fft(xoff(7169:8192),1024);
xofffft9= fft(xoff(8193:9216),1024);
xofffft10= fft(xoff(9217:10240),1024);
xofffft11= fft(xoff(10241:11264),1024);
xofffft12= fft(xoff(11265:12288),1024);
xofffft13= fft(xoff(12289:13312),1024);
xofffft14= fft(xoff(13313:14336),1024);
xofffft15= fft(xoff(14337:15360),1024);
xofffft16= fft(xoff(15361:16384),1024);
xofffft17= fft(xoff(16385:17408),1024);
xofffft18= fft(xoff(17409:18432),1024);
xofffft19= fft(xoff(18433:19456),1024);
xofffft20= fft(xoff(19457:20480),1024);
xofffft21= fft(xoff(20481:21504),1024);
xofffft22= fft(xoff(21505:22528),1024);
xofffft23= fft(xoff(22529:23552),1024);
xofffft24= fft(xoff(23553:24576),1024);
yonfft1= fft(yon(1:1024),1024);
yonfft2= fft(yon(1025:2048),1024);
yonfft3= fft(yon(2049:3072),1024);
yonfft4= fft(yon(3073:4096),1024);
yonfft5= fft(yon(4097:5120),1024);
yonfft6= fft(yon(5121:6144),1024);
yonfft7= fft(yon(6145:7168),1024);
yonfft8= fft(yon(7169:8192),1024);
yonfft9= fft(yon(8193:9216),1024);
yonfft10= fft(yon(9217:10240),1024);
yonfft11= fft(yon(10241:11264),1024);
yonfft12= fft(yon(11265:12288),1024);
yonfft13= fft(yon(12289:13312),1024);
yonfft14= fft(yon(13313:14336),1024);
yonfft15= fft(yon(14337:15360),1024);
yonfft16= fft(yon(15361:16384),1024);
yonfft17= fft(yon(16385:17408),1024);
yonfft18= fft(yon(17409:18432),1024);
yonfft19= fft(yon(18433:19456),1024);
yonfft20= fft(yon(19457:20480),1024);
yonfft21= fft(yon(20481:21504),1024);
yonfft22= fft(yon(21505:22528),1024);
yonfft23= fft(yon(22529:23552),1024);
yonfft24= fft(yon(23553:24576),1024);
yofffft1= fft(yoff(1:1024),1024);
yofffft2= fft(yoff(1025:2048),1024);
yofffft3= fft(yoff(2049:3072),1024);
yofffft4= fft(yoff(3073:4096),1024);
yofffft5= fft(yoff(4097:5120),1024);
yofffft6= fft(yoff(5121:6144),1024);
yofffft7= fft(yoff(6145:7168),1024);
yofffft8= fft(yoff(7169:8192),1024);
yofffft9= fft(yoff(8193:9216),1024);
yofffft10= fft(yoff(9217:10240),1024);
yofffft11= fft(yoff(10241:11264),1024);
yofffft12= fft(yoff(11265:12288),1024);
yofffft13= fft(yoff(12289:13312),1024);
yofffft14= fft(yoff(13313:14336),1024);
yofffft15= fft(yoff(14337:15360),1024);
yofffft16= fft(yoff(15361:16384),1024);
yofffft17= fft(yoff(16385:17408),1024);
yofffft18= fft(yoff(17409:18432),1024);
yofffft19= fft(yoff(18433:19456),1024);
yofffft20= fft(yoff(19457:20480),1024);
yofffft21= fft(yoff(20481:21504),1024);
yofffft22= fft(yoff(21505:22528),1024);
yofffft23= fft(yoff(22529:23552),1024);
yofffft24= fft(yoff(23553:24576),1024);
zffton1 = xonfft1 .* conj(yonfft1);
zffton2 = xonfft2 .* conj(yonfft2);
zffton3 = xonfft3 .* conj(yonfft3);
zffton4 = xonfft4 .* conj(yonfft4);
zffton5 = xonfft5 .* conj(yonfft5);
zffton6 = xonfft6 .* conj(yonfft6);
zffton7 = xonfft7 .* conj(yonfft7);
zffton8 = xonfft8 .* conj(yonfft8);
zffton9 = xonfft9 .* conj(yonfft9);
zffton10 = xonfft10 .* conj(yonfft10);
zffton11 = xonfft11 .* conj(yonfft11);
zffton12 = xonfft12 .* conj(yonfft12);
zffton13 = xonfft13 .* conj(yonfft13);
zffton14 = xonfft14 .* conj(yonfft14);
zffton15 = xonfft15 .* conj(yonfft15);
zffton16 = xonfft16 .* conj(yonfft16);
zffton17 = xonfft17 .* conj(yonfft17);
zffton18 = xonfft18 .* conj(yonfft18);
zffton19 = xonfft19 .* conj(yonfft19);
zffton20 = xonfft20 .* conj(yonfft20);
zffton21 = xonfft21 .* conj(yonfft21);
zffton22 = xonfft22 .* conj(yonfft22);
zffton23 = xonfft23 .* conj(yonfft23);
zffton24 = xonfft24 .* conj(yonfft24);
zffton = zffton1 + zffton2 + zffton3 + zffton4 + zffton5 + zffton6 +
zffton7 + zffton8 + zffton9 + zffton10 + zffton11 + zffton12 +
zffton13 + zffton14 + zffton15 + zffton16 + zffton17 + zffton18 +
zffton19 + zffton20 + zffton21 + zffton22 + zffton23 + zffton24;
zfftoff1 = xofffft1 .* conj(yofffft1);
zfftoff2 = xofffft2 .* conj(yofffft2);
zfftoff3 = xofffft3 .* conj(yofffft3);
zfftoff4 = xofffft4 .* conj(yofffft4);
zfftoff5 = xofffft5 .* conj(yofffft5);
zfftoff6 = xofffft6 .* conj(yofffft6);
zfftoff7 = xofffft7 .* conj(yofffft7);
zfftoff8 = xofffft8 .* conj(yofffft8);
zfftoff9 = xofffft9 .* conj(yofffft9);
zfftoff10 = xofffft10 .* conj(yofffft10);
zfftoff11 = xofffft11 .* conj(yofffft11);
zfftoff12 = xofffft12 .* conj(yofffft12);
zfftoff13 = xofffft13 .* conj(yofffft13);
zfftoff14 = xofffft14 .* conj(yofffft14);
zfftoff15 = xofffft15 .* conj(yofffft15);
zfftoff16 = xofffft16 .* conj(yofffft16);
zfftoff17 = xofffft17 .* conj(yofffft17);
zfftoff18 = xofffft18 .* conj(yofffft18);
zfftoff19 = xofffft19 .* conj(yofffft19);
zfftoff20 = xofffft20 .* conj(yofffft20);
zfftoff21 = xofffft21 .* conj(yofffft21);
zfftoff22 = xofffft22 .* conj(yofffft22);
zfftoff23 = xofffft23 .* conj(yofffft23);
zfftoff24 = xofffft24 .* conj(yofffft24);
zfftoff = zfftoff1 + zfftoff2 + zfftoff3 + zfftoff4 + zfftoff5 +
zfftoff6 + zfftoff7 + zfftoff8 + zfftoff9 + zfftoff10 + zfftoff11 +
zfftoff12 + zfftoff13 + zfftoff14 + zfftoff15 + zfftoff16 + zfftoff17
+ zfftoff18 + zfftoff19 + zfftoff20 + zfftoff21 + zfftoff22 +
zfftoff23 + zfftoff24;
zfft = zffton - zfftoff;
plot(1:1024,angle(zfftoff))
xlabel('N','FontSize',16)
ylabel('phase','FontSize',16)
title('\it{phase vs frequency for noise diode off}','FontSize',16)
figure
plot(1:1024,angle(zffton))
xlabel('N','FontSize',16)
ylabel('phase','FontSize',16)
title('\it{phase vs frequency for noise diode on}','FontSize',16)
figure
plot(1:1024,angle(zfft))
xlabel('N','FontSize',16)
ylabel('phase','FontSize',16)
title('\it{phase vs frequency for noise diode on - noise diode
off}','FontSize',16)
for i = 1:1024
p2(i)=angle(xonfft1(i)-yonfft1(i))-angle(zfft(i));
if p2(i) > pi
p2(i) = p2(i)-2*pi;
elseif p2(i) < -pi
p2(i) = p2(i)+2*pi;
end
end
figure
plot(1:1024, p2)
the plot should give 0 result with minor fluctuations if any as I am
getting by calculating myself. There is some problem with the code as
if I try to plot acos(cos(zfft))-angle(zfft) , that doesn't yield 0. I
am not attaching the data files. The phase difference between the on
states(off states here contribute negligibly) in any one spectrum out
of 24 is approximately equal to the phase difference that we obtain in
zfft(accumulated spectra). What is wrong in the code?
phase difference between two channels
Started by ●May 28, 2008
Reply by ●May 29, 20082008-05-29
Reply by ●May 31, 20082008-05-31
On May 29, 12:39�am, "Impoliticus" <swis...@uiuc.edu> wrote:> >I want to find the phase difference between two channels(x and y) due > >to instrumental effects. For that I am passing a signal from a noise > >generator through the two channels. Then I switch off the noise > >generator and note the outputs from the two channels. Subtraction of > >the noise-off signal from the noise-on signal should remove any other > >spurious signals so I get only the signal from the noise generator at > >the output of the two channels. cross correlating the two channels now > >would mean (xon - xoff)* conj(yon-yoff) in the frequency domain which > >will yield the phase difference. However since it is a real time > >problem, I have xon and yon at a time and not the off states so I can > >perform a correlation like xon*conj(yon) and �xoff*conj(yoff) and > >subtract them. In the previous case I get two additional > >multiplication terms i,e xon*conj(yoff) and xoff*conj(yoff). Since > >these are uncorrelated, I should get same result but my simulation > >shows different results when I plot the phases for the two cases. What > >is wrong in the approach? How do I get better results? > > From what I gather, you're performing an FFT on data from two channels and > then performing Ch1 * conj(Ch2) for each FFT bin. �The result of the > multiplication should give a phasor from which you can estimate the phase > difference between the two channels. �Assuming your time delay is constant > across frequency, the phase difference should be the same for all bins > excluding any noise. �Averaging the phasor values across all the bins will > help if noise is causing problems. �Also, and maybe a dumb question, but > are you looking out for phase wrapping problems?- Hide quoted text - > > - Show quoted text -You are right in getting the problem. Well time delay is constant for one frequency and hence in the frequency domain that would just represent one constant line. The linear phase slope is obtained when we have many frequency components and we pass the signal through a band pass filter. The phase slope is a characteristic of the transfer function and not the signal. If the system is nonlinear then it will be different. I am wrapping up the phases before plotting. Phase difference will also be a linear function of frequency if we pass the noise signal through two linear systems. Phase difference is nothing but the phase of one signal taking the other as a reference. I found that after accumulation of the z spectra (xy*)of the signals if I take the FFT then that gives me a clear plot for the magnitude and phase so I have got the phase difference due of the system since the other fluctuations are not correlated and are cancleed out. sinusoidal signal would yield the phase difference for only one frequency whereas I need that for broadband calibration. I have a question. If we take an ensemble average of a random process then what would the phase mean there? One can say that averaging a random process would yield zero but we do have autocorrelation function of a random process that gives the spectral characteristics. But I don't know what the phase would mean in that case. Any idea?






