How to use the FFT (Fast Fourier Transform) in Matlab
<p>I'm just learning Matlab and the fast fourier transform algorithm.</p>

<p>As a first step I tried to duplicate this example: <a href="https://en.wikipedia.org/wiki/Fourier_transform#Example" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Fourier_transform#Example</a></p>

<p>I use the following code:</p>

<pre><code>t = -6:0.01:6;
s = cos(2 * pi * 3 * t) .* exp(-pi * t.^2);
figure(1);
plot(t, s);
xlim([-2 2]);
r = fft(s);
figure(2);
plot(t, abs(r));
</code></pre>

<p>And I obtained the following picture:</p>

<p><strong>Figure 2:</strong></p>

<p><a href="https://i.stack.imgur.com/ntA2x.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ntA2x.jpg" alt="Figure 2"></a></p>

<p>Figure 1 is OK, but Figure 2 is not. I see one of the problem is that in Figure 2 I should plot vector r <i>against</i> frequency, not against time. Another problem in Figure 2 is the scale in the Y-axis.</p>

<p>Thus, I have 2 questions in order to duplicate the example:</p>

<ol>
<li>How can I obtain the frequency domain (X-axis in Figure 2)?</li>
<li>How should I scale vector r (Y-axis in Figure 2)?</li>
</ol>