Hi eunbae,
The code is pretty close. The fft of a real signal has positive and negative frequencies, and what you are seeing at the right end of the frequency plot is just the negative frequencies. After [1] using the fftshift function to swap halves of the array and [2] making a frequency grid with 0 in the center, you get the plot in fig. 2 which better displays positive and negative frequency contributiions.
The amplitudes for pos and neg frequency have the same absolute value, so what people do for plotting purposes is double the size of the positive amplitudes and throw away the negative amplitudes. Except the first point in the array, which is frequency 0, is not doubled.
Not having your signal file I made up some data. The example assumes tha N is even.
Fs = 48000;
N = 30*Fs;
ts=1/Fs;
t=0:ts:N*ts-ts;
data = .8*sin(2*pi*200*t).*exp(-1.5*t);
Fdat=abs(fft(data)/N);
F_shift=(0:Fs/N:Fs-Fs/N)-Fs/2;
Fdat_shift=fftshift(Fdat);
figure(2)
plot(F_shift,Fdat_shift);
xlim([-500 500])
N=length(data);
ts=1/Fs;
t=0:ts:N*ts-ts;
F=0:Fs/N:Fs-Fs/N;
Fdat=abs(fft(data)/N);
F = F(1:N/2);
Fdat=Fdat(1:N/2);
Fdat(2:end) = 2*Fdat(2:end);
figure(1)
subplot(1,2,1)
plot(t,data);
xlabel('time[sec]')
ylabel('Amplitude')
title('1st pipe sound')
subplot(1,2,2)
plot(F,Fdat)
xlabel('Frequency')
ylabel('Amplitude')
title('1st sound fft result')
xlim([0 500])
Best Answer