What's the purpose of doing fftshift twice?

30 vues (au cours des 30 derniers jours)
Mark Golberg
Mark Golberg le 9 Juin 2016
Commenté : Jan le 24 Fév 2017
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 commentaires
Walter Roberson
Walter Roberson le 9 Juin 2016
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 le 9 Juin 2016
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.

Connectez-vous pour commenter.

Réponse acceptée

John BG
John BG le 9 Juin 2016
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 commentaire
Jan
Jan le 24 Fév 2017
John BG has accepted this answer by his own. It is not clear, if it helps the OP.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 9 Juin 2016
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.

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by