0
|
18565 Views
|
8 Replies
|
9 Total Likes
View groups...
Share
GROUPS:

# Equivalent to Matlab fftshift in Mathematica

Posted 10 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.
8 Replies
Sort By:
Posted 1 year ago
 A little bit late but nevertheless: FourierShift[a_] := RotateRight[a, Quotient[Dimensions@a - 1, 2]] 
Posted 10 years ago
 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 8 years ago
 Hi Piotr,Apologies for such a late reply - thanks. Regards,Richard.
Posted 10 years ago
 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 10 years ago
 I do not think it is entirely true. I did not check all the functions but ImagePeriodogram seems to do the shift automatically.
Posted 10 years ago
 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 10 years ago
 Isn't similar result obtained with ImagePeriodogram ? Also see PeriodogramArray and Periodogram  and Spectrogram  and SpectrogramArray .
Posted 10 years ago
 I never used ImagePeriodogram and did not know about it. Thanks for the link, will look at it.