AdvaRes
Advanced Member level 4
Hi members,
In order to recongnize the differentes harmonics of a function I wrote a matlab script to calculate the DFT. In order to verfy that may script is correct I applyed this function to a simple sinus function.
Here is the code
Fe=8E9 %Sampling frequency
N=8 %8 samples
df=Fe/N %step
t=(1:N)/Fe %the range
f0=1E9 %Frequency
x=2*sin(2*pi*f0*t)+2
y=fft(x)
y2=fftshift
m=abs(y2)
Freq=(0:df:Fe-df)
figure(1),plot(t,x) %plot sinwave
figure(2),plot(y,m)%plot DFT
I was expecting something like shown in the following. Unfortunately matlab gives strange plots.
Is there something incorrect in the script ?
In order to recongnize the differentes harmonics of a function I wrote a matlab script to calculate the DFT. In order to verfy that may script is correct I applyed this function to a simple sinus function.
Here is the code
Fe=8E9 %Sampling frequency
N=8 %8 samples
df=Fe/N %step
t=(1:N)/Fe %the range
f0=1E9 %Frequency
x=2*sin(2*pi*f0*t)+2
y=fft(x)
y2=fftshift
m=abs(y2)
Freq=(0:df:Fe-df)
figure(1),plot(t,x) %plot sinwave
figure(2),plot(y,m)%plot DFT
I was expecting something like shown in the following. Unfortunately matlab gives strange plots.
Is there something incorrect in the script ?