# Using fft() in Matlab

I have a function defined like: $$x(t)=2e^{-\frac{r}{2}t}\sin\left(\frac{1}{2}\sqrt{16\pi^2-r^2}\cdot t\right)\left(\frac{\Theta(t)}{\sqrt{16\pi^2-r^2}}\right)$$ Where $$\Theta(t)$$ is the Heaviside Theta funcion. If I perform the Fourier Transform of x(t) I have: $$X(\omega)=\frac{2 \sqrt{\frac{32 \pi -\frac{1}{2 \pi }}{16 \pi ^2-\frac{1}{4}}}}{-4 \omega^2-2 i \omega+16 \pi ^2}$$ Now I define on Matlab $$t=linspace(0,10,2^8)$$, and $$y=fft(x(t))$$ and try to plot the analytical $$X(\omega)$$ with the coefficient by fft but but they are differnt. Can someone suggest me a good way to do?

Here is my code :

  x=@(t)2*e.^(-r/2*t).*sin(1/2*sqrt(16*pi^2-r.^2).*t).*...
(1*heaviside(t))./(sqrt(16*pi^2-r.^2));
e=exp(1); M=1; K=4*pi^2; C=1/2;
om=sqrt(4*K-C^2)/2; t=linspace(0,10,2^7);
punti=x(t); N=length(punti); FFT=fft(punti);
pseudoperiodo=2*pi/om;
dw=(2*pi)/pseudoperiodo;
N=length(punti); FFT=FFT/N; % calculate coefficient
w=dw*[[0:N/2],-[N/2-1:-1:1]]';
figure
plot(w(1:N/2+1),abs(FFT(1:N/2+1)),'o')
figure
G=tf(1,[M C K]); bode(G)

• You are going to have provide more details about how they are different and your source code so that others can reproduce the problem. – AnonSubmitter85 Nov 6 '18 at 23:38
• x=@(t)2*e.^(-r/2*t).*sin(1/2*sqrt(16*pi^2-r.^2).*t).*(1*heaviside(t))./(sqrt(16*pi^2-r.^2)); e=exp(1); M=1; K=4*pi^2; C=1/2; om=sqrt(4*K-C^2)/2; t=linspace(0,10,2^7); punti=x(t); N=length(punti); FFT=fft(punti); pseudoperiodo=2*pi/om; dw=(2*pi)/pseudoperiodo; N=length(punti); FFT=FFT/N; % calculate coefficient w=dw*[[0:N/2],-[N/2-1:-1:1]]'; figure plot(w(1:N/2+1),abs(FFT(1:N/2+1)),'o') figure G=tf(1,[M C K]); bode(G) – Alessio Bocci Nov 6 '18 at 23:45
• I am sorry, but that is unreadable. Please edit your question and make sure it formatted so that others can read it without much effort. You are much more likely to get help that way. – AnonSubmitter85 Nov 7 '18 at 1:16
• I have taken the liberty to include your code into your question for an improved readability. – Jean Marie Nov 15 '18 at 13:26