How do you centre your plot at '0' on the X-axis after performing a Fourier transform?
30 次查看(过去 30 天)
显示 更早的评论
I have a generated signal which I perform an fft on as well as zero-padding it with 5000 zeros. The problem I have is that the resulting plot is centered at 2500 (i.e. half of 5000).
Is it possible for me to shift my plot 2500 spaces to left on my X-axis so that the plot is centered on 0?
0 个评论
回答(1 个)
Dr. Seis
2012-7-16
编辑:Dr. Seis
2012-7-16
fftshift might be what you are looking for. Does this example help?
dt = 0.1; % Fs = 1/dt;
N = 16;
t = (0:N-1)*dt;
g = randn(size(t));
Nyq = 1/2/dt;
df = 1/N/dt;
f = -Nyq : df : Nyq-df;
G = fftshift(fft(g));
figure; plot(f,G);
[EDIT]
f1 = -3; % minimum frequency
f2 = 3; % maximum frequency
idx = f1 < f & f < f2;
figure; plot(f(idx), G(idx));
2 个评论
Dr. Seis
2012-7-16
编辑:Dr. Seis
2012-7-16
Why not specify a range using logicals... continuing my example above:
f1 = -3; % minimum frequency
f2 = 3; % maximum frequency
idx = f1 < f & f < f2;
figure; plot(f(idx), G(idx));
Note: Your "N" will be based on the number you pad up to (i.e., 200000) for determining what "f" is for your data.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!