Magnitude Spectrum, different magnitudes same amplitude When the following code is written,the resulting magnitude spectrum shows magnitude values represented by two peaks is different even though they have the same amplitude. why is that?

a fast reply  would be much appreciated

    Fs=250; %sampling frquency of 250Hz
i=0:1/250:4; %1000 data points
x1=sin(2*pi*7*i); %create sinusoidal wave with frequency=7Hz
x2=sin(2*pi*40*i);%create sinusoidal wave with frequency=40Hz
subplot(2,1,1);
plot(x1),xlabel('Sampling Points'),ylabel('Amplitude')
subplot(2,1,2);
plot(x2),xlabel('Sampling Points'),ylabel('Amplitude')

y=x1+x2; %combine two signals to one
figure, psd(y) %spectrum analysis

N=length(y); %legnth of y is attributed to N

%calculate real part of Discrete Fourier Transform
for m=1:N,
sumn=0;
    for n=1:N,
    sumn=sumn + y(n)*(cos (2*pi*(m-1)*(n-1)/N));
    end
dftreal(m)=sumn; 
end


%calculate imaginary part of Discrete Fourier Transform
for m=1:N,
sumn=0;
    for n=1:N,
    sumn=sumn + y(n)*(sin (2*pi*(m-1)*(n-1)/N));
    end
dftimag(m)=-sumn;
end


%obtaining magnitude spectrum using the obtained complex DFT values and
%plotting the spectrum
for m=1:N,
dftmag(m)=sqrt(dftreal(m)*dftreal(m)+dftimag(m)*dftimag(m));
end

%obtaining magnitude spectrum using the obtained complex DFT values and
figure, plot(dftmag),title('Magnitude Spectrum 1'),xlabel('Sampling Points'),ylabel('Magnitude')

%obtaining new Magnitude Spectrum based on fft
z=fft(y);
dftmag1=abs(z);

figure, plot(dftmag1),title('Magnitude Spectrum 2'),xlabel('Sampling Points'),ylabel('Magnitude')

%obtaining PSD of dftmag1
figure, psd(dftmag1)
To add a bit to the previous answers: the FFT result is "binned", not continuous.  A plot of an FFT result often fools people by being smooth for large enough FFT lengths.  But the result is really more like a bar chart for a sequence of bins, rather than a line graph.

And the bins are not rectangular in shape (in terms of frequency response).  The nearer a spectral frequency peak is to the center of an FFT bin, the more accurate the magnitude result.  You can get a list of your FFT's bin centers by multiplying sample_rate/length_of_FFT by integers from zero up to half the length.  If a frequency peak is not at the exact center of an FFT result bin, the magnitude gets split among multiple bins, which takes height away from the closest peak bin.

In your example, some of your frequencies were closer to bin centers than others.