From: dbd on
On Jun 24, 8:40 am, "fisico32" <marcoscipioni1(a)n_o_s_p_a_m.gmail.com>
wrote:
>
> ...
> 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.

This A is symmetric but not DFT-even so it has nonzero imaginary part
in the frequency domain.
"fftshift" will not change thst.

> Instead, if A[0 1 2 3 3 2 1] things work out well and fft(A) has
> imag(fft(A))=0.
>

This A is DFT-even.

To see what that means, read the second section in harris' paper:
http://www.utdallas.edu/~cpb021000/EE%204361/Great%20DSP%20Papers/Harris%20on%20Windows.pdf

> 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:
> ...

Wrong, see above. Read the reference. Ask new questions.

You persist in trying to apply continuous/infinite domain concepts to
the discrete/finite domain in ways that do not work.

"Insanity: doing the same thing over and over again and expecting
different results."
Albert Einstein, (attributed)

Dale B. Dalrymple
From: Greg Heath on
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) )))

% See my explanation of the shift functions in
%
% http://groups.google.com/group/comp.soft-sys.matlab/msg/ecedcba94094f742

close all, clear all, clc, p = 0

mu = 0; % mean
sigma2 = .2; % variance
sd = sqrt(sigma2); % std deviation
x = mu-30:0.02:mu+30; % location of points
g = 1*exp(-0.5*(x-mu).^2/sigma2);

p = p+1,figure(p)
plot(x,g)

N = length(x) % 3001 is odd
dx = x(2)-x(1) % 0.02
dk = 1/(N*dx)
kb = dk*[-(N-1)/2 : (N-1)/2];
Gb = fftshift(fft(ifftshift(g))); % defined over a bipolar interval
rGb = real(Gb);
iGb = imag(Gb);
aGb = abs(Gb);
pGb = angle(Gb);
minmaxiGb = minmax(iGb) % -1.0914e-014 6.0254e-014

p=p+1,figure(p)
subplot(221)
plot(kb,rGb)
subplot(222)
plot(kb,iGb)
subplot(223)
plot(kb,aGb)
subplot(224)
plot(kb,pGb)

% Snapshot

ind = find(aGb > max(aGb)/100);
minmaxind = minmax(ind) % [ 1437 1565]
kbint = kb(ind); % Snapshot interval

p=p+1,figure(p)
subplot(221)
plot(kbint,rGb(ind))
subplot(222)
plot(kbint,iGb(ind))
subplot(223)
plot(kbint,aGb(ind))
subplot(224)
plot(kbint,pGb(ind))


% Hope this helps.
%
% Greg
From: Greg Heath on

% See my explanation of the shift functions in
%
% http://groups.google.com/group/comp.soft-sys.matlab/msg/ecedcba94094f742

close all, clear all, clc, p = 0

mu=0; % mean
sigma2=.2; % variance
sd = sqrt(sigma2); % std deviation
x = mu-30:0.02:mu+30; % location of points
g = 1*exp(-0.5*(x-mu).^2/sigma2);

p=p+1,figure(p)
plot(x,g)

N = length(x) % 3001 is odd
dx = x(2)-x(1) % 0.02
dk = 1/(N*dx)
kb = dk*[-(N-1)/2 : (N-1)/2];
Gb = fftshift(fft(ifftshift(g))); % defined over a bipolar interval
rGb = real(Gb);
iGb = imag(Gb);
aGb = abs(Gb);
pGb = angle(Gb);
minmaxiGb = minmax(iGb) % -1.0914e-014 6.0254e-014

p=p+1,figure(p)
subplot(221)
plot(kb,rGb)
subplot(222)
plot(kb,iGb)
subplot(223)
plot(kb,aGb)
subplot(224)
plot(kb,pGb)

% Snapshot

ind = find(aGb > max(aGb)/100);
minmaxind = minmax(ind) % [ 1437 1565]
kbint = kb(ind);

p=p+1,figure(p)
subplot(221)
plot(kbint,rGb(ind))
subplot(222)
plot(kbint,iGb(ind))
subplot(223)
plot(kbint,aGb(ind))
subplot(224)
plot(kbint,pGb(ind))


% Hope this helps.
%
% Greg