Hand written DFT vs MATLAB FFT has flipped conjugates?
I think your problem might be in this line:

FFTSpectrum = fft(sampledsignal,N)';


Note that in MATLAB, ' is the complex conjugate transpose. Use .' to transpose a matrix without applying the complex conjugation.