Message Boards Message Boards

0
|
20074 Views
|
8 Replies
|
9 Total Likes
View groups...
Share
Share this post:

Equivalent to Matlab fftshift in Mathematica

Posted 11 years ago
Hi,

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,

Richard.
POSTED BY: Richard Shadbolt
8 Replies

RotateRight is an equivalent to Matlab fftshift.

img=Import["ExampleData/lena.tif"];
d=ImageData[img,Interleaving->False][[2]];
{nRow,nCol}=ImageDimensions[img];
fw=Fourier[d,FourierParameters->{1,1}];
fw = RotateRight[fw,Floor[({nCol,nRow}-1)/2]]; (*center,i.e.fftshift like*)
(*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]]

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
 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]]

output

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
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,

Richard.
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
I never used ImagePeriodogram and did not know about it. Thanks for the link, will look at it.
POSTED BY: Nasser M. Abbasi

Hi Piotr,

Apologies for such a late reply - thanks.

Regards,

Richard.

POSTED BY: Richard Shadbolt

A little bit late but nevertheless:

FourierShift[a_] := RotateRight[a, Quotient[Dimensions@a - 1, 2]]
POSTED BY: Robert Nowak
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract