Path: news.mathworks.com!not-for-mail
From: "Bruce " <italianasa84@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: ratio of fft's
Date: Tue, 20 May 2008 18:00:25 +0000 (UTC)
Organization: NASA
Lines: 41
Message-ID: <g0v3jp$27s$1@fred.mathworks.com>
Reply-To: "Bruce " <italianasa84@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1211306425 2300 172.30.248.37 (20 May 2008 18:00:25 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 20 May 2008 18:00:25 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 774179
Xref: news.mathworks.com comp.soft-sys.matlab:469524


A simple divison, on paper, of two fft's proves that the
ratio of the fourier transform of two sine waves with the
same frequency gives exp(-j*phi) where phi is the phase
shift between the two. Therefore if you take
angle(exp(-j*phi)) you should get phi, which is a constant.
Why in matlab do you not get a constant?? Where do those
spikes come from?

% start of code. press spacebar to continue shifting.
clear all; close all; clc;
Fs = 4000; % sampling frequency
T = 1/Fs;  % sample time
L = 4000; %length of signal
t = (0:L-1)*T;  % time vector
NFFT = 2^nextpow2(L); % Next power of 2 from length of y

y1 =  sin(2*pi*10*t).* hamming(length(t))'; 
Y1 = fft(y1,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2);
loops = 1;
phi = 0;
% y2 = shifted sine wave
y2 =  sin(2*pi*10*t + phi).*hamming(length(t))'; 
Y2 = fft(y2,NFFT);

while(loops < 10000);
    phi = loops*pi/360;
    y2 =  sin(2*pi*10*t + phi) .* hamming(length(t))'; 
    Y2 = fft(y2,NFFT);
    
    subplot(1,2,1);
    plot(Fs*t,y1); hold on; plot(Fs*t,y2,'g'); hold off;
    
    subplot(1,2,2);    ratio = unwrap(angle(Y2./Y1));
    plot(ratio); axis([0, length(ratio), -5, 5]);
    text(500,4, ['degree shift: ',
num2str(rem(rad2deg(phi),360))]);
    
    loops = loops + 1;
    pause();
end