How do you centre your plot at '0' on the X-axis after performing a Fourier transform?

41 views (last 30 days)
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?

Answers (1)

Dr. Seis
Dr. Seis on 16 Jul 2012
Edited: Dr. Seis on 16 Jul 2012
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 Comments
Matt
Matt on 16 Jul 2012
I have used abs(fftshift(fft(x))) but that just gives me my plot at the middle of all my values including the zero's. In your example you do not zero pad. I need to use many zero's in my case...
Lamda1 = .003;
N = pi./Lamda1;
Step1 = .03;
A4 = [-N/2:Step1:(N/2)-Step1];
R4 = zeros(size(A4));
R4 = (0.5 + (0.5)*((1 - (A4.^2)).^2));
R4 = 10*log10(R4);
A4 = asin(A4);
figure (10); plot(A4,R4)
FD4 = fft(R4, 200000) / N;
%figure (11); plot(abs(FD4));
figure (12); plot(abs(fftshift(FD4)))
Dr. Seis
Dr. Seis on 16 Jul 2012
Edited: Dr. Seis on 16 Jul 2012
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.

Sign in to comment.

Categories

Find more on Graphics Object Identification in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!