Path: news.mathworks.com!not-for-mail
From: "Chen Sagiv" <chensagivron@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Does Matlab do FFT correctly ?
Date: Fri, 2 May 2008 22:15:06 +0000 (UTC)
Organization: Sagiv Enterprises
Lines: 90
Message-ID: <fvg3pa$slk$1@fred.mathworks.com>
References: <fvfs3j$bnf$1@fred.mathworks.com> <fvg2pb$73p$1@fred.mathworks.com>
Reply-To: "Chen Sagiv" <chensagivron@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 1209766506 29364 172.30.248.37 (2 May 2008 22:15:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 2 May 2008 22:15:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 805005
Xref: news.mathworks.com comp.soft-sys.matlab:466365


Dear Ken,

Thanks for your friendly answer. 
I am wondering what are the implications of your input on 
real life signals and images. 

I am looking at the Fourier phase of signals and images. 
Now, when I calculate the fft of say, an images, will I get 
the correct phase, or do I have to do some tricks ? 

I am not sure.

Best,

Chen 

"Ken Garrard" <ken_garrardAT@ncsuDOT.edu> wrote in message 
<fvg2pb$73p$1@fred.mathworks.com>...
> "Chen Sagiv" <chensagivron@gmail.com> wrote in message 
> <fvfs3j$bnf$1@fred.mathworks.com>...
> > Hi all,
> > 
> > We all know that the DFT of a square pulse is a sinc. 
> > 
> > Let's try it:
> > 
> > % First we define the square pulse
> > x=-1:0.01:1;
> > f=zeros(size(x));
> > f(x>-0.5 & x<0.5)=1;
> > figure ; plot(x,f); 
> > 
> > % Now let's view its Fourier transform:
> > 
> > figure ; plot(real(fftshift(fft(f))));
> > figure ; plot(imag(fftshift(fft(f))));
> > 
> > % Hey, the imaginary part is NOT zero
> > % a remedy: 
> > figure ; plot(real(fftshift(fft(ifftshift(f)))));
> > figure ; plot(imag(fftshift(fft(ifftshift(f)))));
> > 
> > So, it seems that Matlab does correct FFT to signals 
that 
> > are not centered about 0, but we have to ifftshift them 
> > first. 
> > 
> > Is that a known "feature" of Matlab ? I will be glad to 
> get 
> > a clarification ! 
> > 
> > Best,
> > 
> > Chen Sagiv
> > 
> 
> Chen,
> 
> Matlab does do the FFT and IFFT correctly.  The problem 
> with your example is that your square pulse is not 
> perfectly symmetric.  It is symmetric around zero but 
since 
> the total number of data points is odd, there has to be 
one 
> more point at -1 than +1 or the other way around.
> 
> Try generating data from -1 to (+1-stepsize) as follows,
> 
> ---
> % First we define the square pulse
> x=-1:0.01:(1-0.01);      % NOTE the change.
> f=zeros(size(x));
> f(x>-0.5 & x<0.5)=1;
> figure ; plot(x,f); 
> 
> % Now let's view its Fourier transform:
> 
> figure ; plot(real(fftshift(fft(f))));
> figure ; plot(imag(fftshift(fft(f))));
> ---
> 
> Now the imaginary parts are very close to zero.  The same 
> sort of behaviour happens with a sine wave that starts at 
> zero and ends at zero; you don't get the expected result 
> because the signal has a one point "glitch" if you repeat 
> it to + and - infinity.
> 
> Ken
>