|
On Jun 18, 5:44 pm, "Carlos Adrian Vargas Aguilera"
<nubeobsc...@hotmail.com> wrote:
> % Some tips about FFTSHIFT and IFFTSHIFT
> %
> %
> % Let X be data from an EVEN/ODD FUNCTION
> % including the MAXIMUM/ZERO reference
> % element, respectively; with either even
> % or odd length.
> %
> % In MATLAB, the vector X may have this
> % reference element in the middle (as
> % usually) like in
.> % >> [0 1 2 3 2 1] % even length (*)
.> % >> [1 2 3 2 1] % odd length
Your first example for an even length array has the 'DFT-even'
property. That is that a real vector fft's to a real vector, a useful
property. The correct odd lenth array to also have this property is [0
1 2 2 1]. It would be a better example.
For a description of why see the second page, left column
On the use of windows for harmonic analysis with the discrete Fourier
transform
Harris, F.J.
Proceedings of the IEEE
Volume 66, Issue 1, Jan. 1978 Page(s): 51 - 83
http://web.mit.edu/xiphmont/Public/windows.pdf
> % or at the first element like in
> % >> [3 2 1 0 1 2] % even length
> % >> [3 2 1 1 2] % odd length
> %
> % (*) Note that when the reference is in
> % the middle and the length is even,
> % MATLAB sets the extra element in
> % the first part rather than in the
> % last one like in [1 2 3 2 1 0].
> %
> % Examples of middle referenced even/odd
> % functions in MATLAB are XCORR, WINDOW
> % (**), etc.; and the most used first
> % element reference even/odd function is
> % the FFT.
> %
> % (**) Note that B=XCORR(X) has always
> % odd length (2*length(X)-1), just
> % like W=WINDOW('triang',2*N+1). So,
> % to get even length use B(end)=[]
> % and/or W(end)=[].
.> % WINDOW('triang',2*N) has even
.> % elements but does not include the
.> % reference element so IS NOT a valid
.> % EVEN FUNCTION.
Call for a window size of 2*N-1 and insert a zero at the front to get
a proper fft window. For the individual window functions use the
'periodic' flag as in
hann(6,'periodic')
ans =
0
0.2500
0.7500
1.0000
0.7500
0.2500
fft(hann(6,'periodic'))
ans =
3.0000
-1.5000
0.0000
-0.0000
0.0000
-1.5000
and
hann(5,'periodic')
ans =
0
0.3455
0.9045
0.9045
0.3455
fft(hann(5,'periodic'))
ans =
2.5000
-1.2500
0.0000
0.0000
-1.2500
> %
> % Sometimes is needed to change the
> % reference from the middle to the first
> % element, and viceversa which is done
> % with IFFTSHIFT and FFTSHIFT,
> % respectively.
>
> % Here some examples that explains what
> % "respectively" means.
> %
> % From FIRST to MIDDLE EVEN use FFTSHIFT because:
> % >> fftshift([3 2 1 0 1 2])
> % >> ans = [0 1 2 3 2 1] % GOOD
> % >> fftshift([3 2 1 1 2])
> % >> ans = [1 2 3 2 1] % GOOD
> % >> ifftshift([3 2 1 0 1 2])
> % >> ans = [0 1 2 3 2 1] % GOOD
> % >> ifftshift([3 2 1 1 2])
> % >> ans = [1 1 2 3 2] % BAD when X is odd!!!
> %
> % From MIDDLE to FIRST EVEN use IFFTSHIFT because:
> % >> fftshift([0 1 2 3 2 1])
> % >> ans = [3 2 1 0 1 2] % GOOD
> % >> fftshift([1 2 3 2 1])
> % >> ans = [2 1 1 2 3] % BAD when X is odd!!!
> % >> ifftshift([0 1 2 3 2 1])
> % >> ans = [3 2 1 0 1 2] % GOOD
> % >> ifftshift([1 2 3 2 1])
> % >> ans = [3 2 1 1 2] % GOOD
> %
> % Same conclusion with the ODD vectors:
> % [-3 -2 -1 0 1 2] and [-2 -1 0 1 2] % MIDDLE
> % [0 1 2 -3 -2 -1] and [0 1 2 -2 -1] % FIRST REFERENCED
> %
> % So, I guess it doesn't matter the time/frequency
> % space you are dealing with but
> % 1) the vector to be obtained from an EVEN/ODD
> % function
> % 2) to include the reference element, and
> % 3) the user to know what he wants.
> % The length of the vector does not matter.
> %
> % Do you agree?
> %
> % Carlos Vargas
Dale B. Dalrymple
|