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)