Why is the amplitude of my signal after the FFT process not as i expected ?

7 views (last 30 days)
Hi Experts,
I have created my own sine wave and converted it into a WAV file. After I use the FFT process and plot my result, I do not understand why my amplitude is so large almost 50 (when i was expecting an amplitude of 1) and why my spikes are not at 10KHz. (From the plot the spike is around 10Hz and 90Hz not 10KHz). Can you please explain to me why this is so and if it is possible, could you please suggest a solution. Also if it is possible could you please tell me how to only show one spike at 10KHz. Thank you in advance.
Here is my code and resulting plots :-
clear all;
%create sinewave
f=10000; %setting the frequency
a=1; % setting the amplitude
fs=100000; % setting the sampling frequency (100 times the frequency i.e. nyquist rate at least 2 times)
ts=1/fs; % setting the sampling time
t = 0:ts:0.001; % the 0 is the start time, 1/10000 is the sampling frequency and the period of 1 sec 101 points (0 - 1 in steps of 1/10000)
y=a*sin(2*pi*f*t); % creating the sine wave
plot(y);
grid on; % putting the grid on
filename = '10k_wav.wav'; %creating wav file
audiowrite('10k_wav.wav',y,fs,'BitsPerSample',8); %write data to file
%sound(y, Fs); % play file
fftresult = fft(y); %fft to transform the original signal into frequency domain
%plot amplitude
figure(2);
plot(abs(fftresult));
title('10K_wav.wav');
xlabel ('Hz');
ylabel('Magnitude');
grid on;

Accepted Answer

Star Strider
Star Strider on 17 Nov 2015
You need to normalise the Fourier transform by the length of the vector. See the R2015a documentation for fft for details.
  3 Comments
Noel Sharpe
Noel Sharpe on 17 Nov 2015
Okay I took your answer and applied it to my code. I have now obtained the frequency spike at 10k, but my magnitude is now gone all the way up to 5000?
why does this happen ? here is my code :-
clear all;
%create sinewave
f=10000; %setting the frequency
a=1; % setting the amplitude
fs=100000; % setting the sampling frequency (100 times the frequency i.e. nyquist rate at least 2 times)
ts=1/fs; % setting the sampling time
t=0:ts:0.1; % the 0 is the start time, 1/10000 is the sampling frequency and the period of 0.1 sec 10001 points (0 - 1 in steps of 1/10000)
y=a*sin(2*pi*f*t); % creating the sine wave
plot(y);
grid on; % putting the grid on
filename = '10k_wav.wav'; %creating wav file
audiowrite('10k_wav.wav',y,fs,'BitsPerSample',8); %write data to file
n = length(y); % Length of FFT (samples)
fftres = fft(y,n); % fft of 10K with no sumber of samples
fftres = fftres(1:1:n/2); % using only 1/2 samples
ampl = abs(fftres);% getting the amplitude
f1 = (0:n/2-1)*fs/n; % setting the range of samples 0 to (10001/2)+1 multiplied by 100000/10001 = 0 to 50,010 samples (x - axis)
figure(2);
plot(f1,ampl);
title('10K_wav.wav');
xlabel ('Hz');
ylabel('Magnitude');
grid on;
Thanks for the help.
Star Strider
Star Strider on 17 Nov 2015
My pleasure!
Change the ‘fftres’ line to this:
fftres = fft(y,n)*2/n; % fft of 10K with n number of samples
and you’re good!
The factor of 2 is necessary because you’re seeing only half the full fft. Dividing by ‘n’ normalises the fft. (This is not an error, but necessary if you want to be able to correctly interpret the one-sided fft.)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!