What's the purpose of doing fftshift twice?

30 次查看(过去 30 天)
Hello,
I have a signal in time domain (x).
Can someone please explain the difference between:
y1 = fftshift(fft(x));
y2 = fftshift(fft(fftshift(x)));
As I understood y2 is the better/more common approach. Why???
Thank you!!
  4 个评论
Walter Roberson
Walter Roberson 2016-6-9
y2 assumes that time 0 is in the middle of the array and shifts it to the beginning of the array, as needed for fft. That is possible but it is not common: people seldom want to deal with negative times. Having centered data is more common for some other kinds of data.
Adam
Adam 2016-6-9
y2 does not really make sense. fftshift is a frequency domain operation, applying it in the time domain does not make sense. See Walter's answer for more detail.

请先登录,再进行评论。

采纳的回答

John BG
John BG 2016-6-9
Mark
command fftshift is used to visualise the FFT within [-Fs/2 Fs/2] instead of [0 Fs] that is the interval that the FFT takes as default.
Let be the following signal:
dt=.01;
t=[0:dt:10];
x0=10*sin(t);
x=10*sin(t)+10*cos(t); % 2nd tone has phase shift equivalent to pi/4 rad
xd1=fftshift(x);
X=fft(x);
Xd=fft(xd1);
figure(1);plot([1:1:length(X)],abs(X),'b',[1:1:length(X)],fftshift(abs(X)),'g');grid on;
legend('|X|','fftshift(|X|)');
figure(2);plot([1:1:length(X)],angle(X),'b',[1:1:length(X)],fftshift(angle(X)),'g');grid on;
legend('arg(X)','fftshift(arg(X))');
If you apply a frequency operation directly on time domain, for this example you get the following:
figure(3);plot(t,x0,'b',t,x,'r');grid on
text(2.63,x0(find(t==2.63)),'\leftarrow 10*sin(t)','FontSize',14);
text(1.16,x(find(t==1.16)),'\leftarrow 10*sin(t)+10*cos(t)','FontSize',14);
figure(4);plot(t,x0,t,xd1);
text(5.38,x0(find(t==5.38)),'\leftarrow 10*sin(t)','FontSize',14);grid on;
text(2.41,xd1(find(t==2.41)),'\leftarrow fftshift(10*sin(t)+10*cos(t))','FontSize',14);
the typical phase imbalance oscilloscope also helps:
figure(5);plot(x0,x,x0,xd1);
As explained in MATLAB help, there is further phase cross-over when working with 2D signals
. If you find this answer of any help solving your question
please mark it as accepted answer,
thanks in advance
John
  1 个评论
Jan
Jan 2017-2-24
John BG has accepted this answer by his own. It is not clear, if it helps the OP.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2016-6-9
No, if your data is in the time domain, then using fftshift(x) before usng fft() would only be before the case where you had negative time represented in your data and time zero was at the middle of the data. The first version you gave is significantly more likely for time domain data: it assumes the data starts at time 0 and it shifts the result of the fft so as to center the plot in the frequency domain.
You only use fftshift() twice if the data you are using fft() or ifft() on is centered in the array.

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by