Message Boards Message Boards

8 Replies
9 Total Likes
View groups...
Share this post:

Equivalent to Matlab fftshift in Mathematica

Posted 10 years ago

I am progressing through a book on software defined radio and the examples are using Matlab. 

One of the functions is fftshift which creates the fft spectrum symmetrically about the 0Hz axis, instead of only positive frequency results.

I have used the FourierParameters directive in an attempt to create similar, but this does not seem to be working. 

Hence can someone please confirm that FourierParameters will yield the required results?. 

Thanks and regards,

POSTED BY: Richard Shadbolt
8 Replies

A little bit late but nevertheless:

FourierShift[a_] := RotateRight[a, Quotient[Dimensions@a - 1, 2]]
POSTED BY: Robert Nowak

RotateRight is an equivalent to Matlab fftshift.

fw = RotateRight[fw,Floor[({nCol,nRow}-1)/2]]; (*center,i.e.fftshift like*)
(*adjust for better viewing as needed*)
Labeled[Image[abs/Max[abs],ImageSize->300],Style["Magnitude spectrum",18]]
Labeled[Image[arg/Max[arg],ImageSize->300],Style["Phase spectrum",18]]

If you only need a magnitude spectrum, then ImagePeriodogram has an Alignment option that determines the location of the zero frequency term.

POSTED BY: Piotr Wendykier

Hi Piotr,

Apologies for such a late reply - thanks.



POSTED BY: Richard Shadbolt
Hi All,

Thanks for the guidance.

Essentially to obtain the negative and positive spectrum is a manual shifting of the information, as opposed to using FourierParameters to implement.

Thanks and regards,

POSTED BY: Richard Shadbolt
I do not think it is entirely true. I did not check all the functions but ImagePeriodogram seems to do the shift automatically.
POSTED BY: Sam Carrettie
 img = Import["ExampleData/lena.tif"];
 data = ImageData[img];
 d = data[[All, All, 2]];
 {nRow, nCol, nChannel} = Dimensions[data]
 d = d*(-1)^Table[i + j, {i, nRow}, {j, nCol}];  (*center, i.e. fftshift like *)
 fw = Fourier[d, FourierParameters -> {1, 1}];
 (*adjust for better viewing as needed*)
fudgeFactor = 100;
abs = fudgeFactor*Log[1 + Abs@fw];
Labeled[Image[abs/Max[abs], ImageSize -> 300], Style["Magnitude spectrum", 18]]
arg = Arg@fw;
Labeled[Image[arg/Max[arg], ImageSize -> 300], Style["Phase spectrum", 18]]


POSTED BY: Nasser M. Abbasi
Isn't similar result obtained with ImagePeriodogram ?

Also see PeriodogramArray and Periodogram  and Spectrogram  and SpectrogramArray .  
POSTED BY: Sam Carrettie
I never used ImagePeriodogram and did not know about it. Thanks for the link, will look at it.
POSTED BY: Nasser M. Abbasi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract