Path: news.mathworks.com!not-for-mail From: "zoul " <joelsubash@gmail.com> Newsgroups: comp.soft-sys.matlab Subject: Sinusoidal phase difference issue. Date: Mon, 20 Jun 2011 16:09:04 +0000 (UTC) Organization: Aston University Lines: 32 Message-ID: <itnrb0$2ku$1@newscl01ah.mathworks.com> Reply-To: "zoul " <joelsubash@gmail.com> NNTP-Posting-Host: www-04-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1308586144 2718 172.30.248.35 (20 Jun 2011 16:09:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Mon, 20 Jun 2011 16:09:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2730781 Xref: news.mathworks.com comp.soft-sys.matlab:732812 Hey guys, Hope you doing alright. The following code calculates the phase difference between two sinusoids using correlation. t=[0:0.00001:4]; f = 1; s1 = sin(2*pi*f*t); s2 = sin(2*pi*f*(t-0.35)); % s1 lags s2 by 0.35s subplot(2,1,1); plot(t,s1,'r',t,s2,'b'); grid title('signals') % Now cross-correlate the two signals x = xcorr(s1,s2,'coeff'); tx=[-4:.00001:4]; subplot(2,1,2) plot(tx,x) grid % Determine the lag [mx,ix] = max(x); lag = tx(ix) hold on tm = [lag,lag]; mm = [-1,1]; plot(tm,mm,'k') hold off S = sprintf('Lag = %5.2f',lag); title(S) Everything seems to be fine as long as the frequency remains the same. But once I double the frequency(f) the phase(lag) estimate goes wrong. This suggests that there is a relation between phase difference introduced during signal generation and frequency, which to me seems wrong.Could someone explain what is happening?? cheers