Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news.glorb.com!postnews.google.com!k37g2000hsf.googlegroups.com!not-for-mail
From: Greg Heath <heath@alumni.brown.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: fft sign?
Date: Mon, 5 May 2008 06:32:22 -0700 (PDT)
Organization: http://groups.google.com
Lines: 90
Message-ID: <bf333f78-468d-44a8-b3a2-107890666708@k37g2000hsf.googlegroups.com>
References: <fv7gge$a1d$1@fred.mathworks.com>
NNTP-Posting-Host: 69.141.173.117
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1209994342 6477 127.0.0.1 (5 May 2008 13:32:22 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 5 May 2008 13:32:22 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: k37g2000hsf.googlegroups.com; posting-host=69.141.173.117; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; 
Xref: news.mathworks.com comp.soft-sys.matlab:466682


On Apr 29, 11:57 am, "h xu" <quabla...@gmx.de> wrote:
> i've written a small and simple script to test the
> fft-function of matlab that transformates exp(i*n*pi/xmax *
> x) from xmin=-xmax to xmax. that should result in a
> kronecker delta with positive amplitude with value 1... but
> for some reason the amplitude is negative for odd n,... why
> is that?
>
> xmin=-5;

xmin~=0 makes phase interpretation difficult

> xmax = 5;
>
> N= 2^8;

Too high; Try the 10 separate trials N = 3:12

> dx = (xmax-xmin)/N;

Incorrect. See below

> x = linspace(xmin,xmax,N);
>
> y= exp(3* i*pi/xmax *x);

Weird function. Try an FFT basis function. See below

-----SNIP

close all, clear, clc, j=0

N = 8            % Instructive to look at ALL of N=3:12
xmin = -5
xmax =  5
dx = (xmax-xmin)/(N-1)
X  = N*dx                   % FFT imposed period = 10+dx

x = linspace(xmin,xmax,N)'; % OK (just changed to column)
x = xmin + dx*(0:N-1)'         % Alternate form

df = 1/X                    % frequency spacing
f = df*(0:N-1)';

% The FFT basis functions are exp(2*pi*i*f(n)*x)

f0 = (N/4)*df            % Half of the Nyquist frequency

y = exp(2*pi*i*f0*x);

z = zeros(size(x));
j=j+1,figure(j)

subplot(2,2,1), hold on
plot(x,z,'k')
plot(x,real(y))
subplot(2,2,2), hold on
plot(x,z,'k')
plot(x,imag(y))
subplot(2,2,3), hold on
plot(x,abs(y))
axis([xmin xmax 0 2])
subplot(2,2,4), hold on
plot(x,z,'k')
plot(x,angle(y))

Y  = dx*fft(y);
y0 = df*Y;               % Rescaling to the size of y

j=j+1,figure(j)
subplot(2,2,1), hold on
plot(f,z,'k')
plot(f,real(y0))
subplot(2,2,2), hold on
plot(f,z,'k')
plot(f,imag(y0))
subplot(2,2,3), hold on
plot(f,abs(y0))
% axis([0 max(f) 0 1.1*max(abs(Y))])
% axis([0 max(f) 0 1.1*max(abs(Y))])
subplot(2,2,4), hold on
plot(f,z,'k')
plot(f,angle(y0))

Hope this helps.

Greg