How to use FFTshift to produce a 0 frequency centered plot
31 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yian Chen
el 28 de Sept. de 2021
Respondida: Ashutosh Singh Baghel
el 18 de Oct. de 2021
Here is my plot, but I don't know why the right plot is shifted after using FFTshift function, how can I solve this problem?
fs = 250;
t = (0:1/fs:(0.1-.5/fs)); % [0, 0.1)
g = sin(2*pi*50*t)+0.3;
plot(t, g,'-o'),
title('g(t) = sin(2 * pi * 50 * t)+0.3' );
xlabel('time/s');
ylabel('g(t) ');
grid on
n = length(g);
L = 25;
Y = fft(g);
f = fs*(0:L-1)/L;
G = fftshift(Y);
fshift = (-n/2:n/2-1)*(fs/n); % zero-centered frequency range
powershift = abs(G).^2/n; % zero-centered power
figure
plot(fshift,powershift,'-o') % zero-centered plot which have shifts
grid on
figure
plot(f, abs(Y),'-o'), % correct frequency plot
xlabel 'Frequency (Hz)';
ylabel 'Magnitude';
title('Magnitude Plot');
grid on
2 comentarios
Star Strider
el 28 de Sept. de 2021
What precisely is the problem?
The right plot looks to be the appropriate result after using fftshift.
What were you expecting?
.
Respuesta aceptada
Ashutosh Singh Baghel
el 18 de Oct. de 2021
Hi Yian,
I understand your curves and data values are true, yet the plot is shifted left by "-5". Please try to update the starting and final value of 'fshift' to,
fs = 250;
t = (0:1/fs:(0.1-.5/fs)); % [0, 0.1)
g = sin(2*pi*50*t)+0.3;
n = length(g);
L = 25;
Y = fft(g);
f = fs*(0:L-1)/L;
G1 = abs(Y);
G = fftshift(Y);
fshift = (-(n+1)/2+1:(n)/2)*(fs/n) % zero-centered frequency range
powershift = abs(G).^2/n; % zero-centered power
figure
plot(fshift(1:end),powershift(1:end),'-o');% zero-centered plot which have shifts
grid on
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spectral Measurements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!