What to do for the right FFT in Matlab (two peaks and incorrect amplitude)? This is the FFT I'm using. But two peaks (did not expect the one in the beginning) are occurring and the amplitude is not as specified (expecting a value of 2). Any help is much appreciated!

Amp = 2;
freqHz = 10000;
fsHz = freqHz*2+1;
dt = 1/fsHz;

sine = Amp*sin(2*pi*freqHz*(0:dt:1-dt));

transform = fft(sine,fsHz)/fsHz;
magTransform = abs(transform);

faxis = linspace(0,fsHz/2,fsHz);
plot(faxis,fftshift(magTransform));
xlabel('Frequency')
The somehow symeetric aspect of the complex DFT might be misleading, so in the past I shared a simple Matlab function FFTR.m for real signals only, that might yield the result you'd expect ($2$ magnitude at peak frequency):



as long as you don't try bordeline endeavours. That requires a little normalization and a special care at DC and Nyquist. The code could be:

% Signal definition
Amp = 2;
freqHz = 10000;
fsHz = freqHz*2+1;
dt = 1/fsHz;
sine = Amp*sin(2*pi*freqHz*(0:dt:1-dt));

% Graphic part
[fftR,fftAxe] = FFTR(sine',dt);
plot(fftAxe,fftR,'o-');
xlabel('Frequency')
ylabel('Magnitude')