From: fisico32 on 24 Jun 2010 00:46 Hello forum, I can easily calculate the fft of a 1D Gaussian function, which is a real, even function. In theory, Its FFT should be real (zero imaginary part). Instead the simulation shows an imaginary part definitely not zero and oscillating...Why? where is my mistake? Here my brief matlab code: mu=0; %mean sigma2=.2; %variance sd = sqrt(sigma2); % std deviation x = mu-30:0.02:mu+30; % location of points at which x is calculated g = 1*exp(-0.5*(x-mu).^2/sigma2); plot(fftshift(imag( fft(g) )))
From: glen herrmannsfeldt on 24 Jun 2010 01:38 fisico32 <marcoscipioni1(a)n_o_s_p_a_m.gmail.com> wrote: > I can easily calculate the fft of a 1D Gaussian function, which is a real, > even function. In theory, Its FFT should be real (zero imaginary part). > Instead the simulation shows an imaginary part definitely not zero and > oscillating...Why? where is my mistake? > Here my brief matlab code: Where is the zero (center of mass) of your Gaussian? The first point of the FFT input is usually zero, so you want it centered (remember it is periodic) around that. -- glen
From: fisico32 on 24 Jun 2010 11:40 >fisico32 <marcoscipioni1(a)n_o_s_p_a_m.gmail.com> wrote: > >> I can easily calculate the fft of a 1D Gaussian function, which is a real, >> even function. In theory, Its FFT should be real (zero imaginary part). >> Instead the simulation shows an imaginary part definitely not zero and >> oscillating...Why? where is my mistake? > >> Here my brief matlab code: > >Where is the zero (center of mass) of your Gaussian? > >The first point of the FFT input is usually zero, so you >want it centered (remember it is periodic) around that. > >-- glen > Hello Glen, just to confirm your suggestions: I tried A=[1 2 3 3 2 1], where N=6(even number) and fft(A) has a nonzero imaginary part. Instead, if A[0 1 2 3 3 2 1] things work out well and fft(A) has imag(fft(A))=0. I guess, as a rule of thumb, for a sequence to be even it needs to have an odd number of entries and the evenness determination must start from the second entry: In matlab, where array indices start a n=1, we would need to have A(2)=A(7) To check if a sequence is even (in matlab) we need to verify the equation A=[0 1 2 3 3 2 1]; N=length(A); for n=2:N p(n)=f(n); g(n)=f(N-n+2); end if p==g disp 'The statement is even', else disp 'The statement is not even', end
From: Mikolaj on 24 Jun 2010 17:13 On 24-06-2010 @ 06:46:52 fisico32 <marcoscipioni1(a)n_o_s_p_a_m.gmail.com> wrote: > Hello forum, > > I can easily calculate the fft of a 1D Gaussian function, which is a > real, > even function. In theory, Its FFT should be real (zero imaginary part). > Instead the simulation shows an imaginary part definitely not zero and > oscillating...Why? where is my mistake? > > Here my brief matlab code: > > mu=0; %mean > sigma2=.2; %variance > sd = sqrt(sigma2); % std deviation > x = mu-30:0.02:mu+30; % location of points at which x is calculated > g = 1*exp(-0.5*(x-mu).^2/sigma2); > plot(fftshift(imag( fft(g) ))) http://www.math.upenn.edu/~cle/m584/matlab/ws_hilbert.html -- Mikolaj
From: robert bristow-johnson on 24 Jun 2010 17:17 On Jun 24, 12:46 am, "fisico32" <marcoscipioni1(a)n_o_s_p_a_m.gmail.com> wrote: > Hello forum, > > I can easily calculate the fft of a 1D Gaussian function, which is a real, > even function. In theory, Its FFT should be real (zero imaginary part). > Instead the simulation shows an imaginary part definitely not zero and > oscillating...Why? where is my mistake? > > Here my brief matlab code: > > mu=0; %mean > sigma2=.2; %variance > sd = sqrt(sigma2); % std deviation > x = mu-30:0.02:mu+30; % location of points at which x is calculated > g = 1*exp(-0.5*(x-mu).^2/sigma2); > plot(fftshift(imag( fft(g) ))) you might want to read that bit about fftshift(). you want to swap the halves of g so that the center of the gaussian pulse is at g[0] (for those of us who use the existing convention of notation) or g(1) (the MATLAB convention for the zeroeth bin). r b-j
|
Next
|
Last
Pages: 1 2 Prev: Reply stategy - was [Re: Use of MATLAB fftshift] Next: Kalman fiter for accelerometer |