MATLAB: Can somebody trace the error in this solution of spectrum

spectrum

I have found the frequency spectrum of signal x=(4+cos(1000*pi*t+pi/3)).*(sin(500*pi*t+pi/4))
There is slight difference in my hand calculation amplitude and amplitude by Matlab. By me, the amplitude at 250 Hz is 2 and by Matlab it is 1.8
My solution is attached here
The matlab code is here
Fs = 2000;
t = 0:1/Fs:1-(1/Fs);
x=(4+cos(1000*pi*t+pi/3)).*(sin(500*pi*t+pi/4));
%x=(4+cos(40*pi*t)).*(cos(200*pi*t-pi/2));
%x=cos(pi*t).*(sin(10*pi*t));
xdft = (1/length(x))*fft(x);
freq = -1000:(Fs/length(x)):1000-(Fs/length(x));
plot(freq,abs(fftshift(xdft)))
xlabel('Freq(Hz)-------->')
ylabel('Amplitude')
Kindly tell me abt my error
and more thing, if at two points, we have freq component, what happen to them, are they added or the lower one is merged in it

Best Answer

If a negative term appears associated with a single frequency, like say
-2*exp(1j*pi/4) that has no impact on magnitude that is just a pi phase shift.
-2*exp(1j*pi/4) = 2*exp(1j*pi/4-pi) % or +pi
remember exp(1j*pi) = exp(-1j*pi) = -1
where it did make a difference is when you had terms that had the same frequency because as you saw you ended with a magnitude you didn't expect.
Remember a magnitude is real-valued and non-negative.