MATLAB: Is the amplitude of the signal after the FFT process not as i expected

amplitudedigital signal processingfftMATLABsignal processing

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;

Best Answer

You need to normalise the Fourier transform by the length of the vector. See the R2015a documentation for fft for details.