plot the fourier transform of a 1000 point sine wave at 200hz with a sample rate of 10khz in matlab in matlab

To plot the Fourier Transform of a sine wave using Matlab, you can follow these steps:

  1. Generate a 1000 point sine wave at 200Hz with a sample rate of 10kHz using the following code:
main.m
Fs = 10000;                  % sample rate
f = 200;                      % frequency of sine wave
t = (0:999)/Fs;              % time vector
x = sin(2*pi*f*t);           % 1000 point sine wave 
194 chars
5 lines
  1. Use the fft function to compute the discrete Fourier transform of the signal.
main.m
N = length(x);
X = fft(x);
X_mag = abs(X/N);
freq = (0:N-1)*Fs/N;
66 chars
5 lines

The fft function returns a complex spectrum, so we calculate the magnitude of the spectrum using the abs function. The frequency axis is obtained by scaling the index of the FFT to the range of frequencies up to the Nyquist frequency Fs/2.

  1. Plot the magnitude of the Fourier Transform using the plot function.
main.m
plot(freq, X_mag)
xlabel('Frequency (Hz)')
ylabel('Magnitude')
63 chars
4 lines

This will give you a plot of the magnitude of the Fourier Transform of the sine wave, with a peak at the frequency of the sine wave (200Hz in this case).

Here's the complete code:

main.m
Fs = 10000;                  % sample rate
f = 200;                     % frequency of sine wave
t = (0:999)/Fs;              % time vector
x = sin(2*pi*f*t);           % 1000 point sine wave 

N = length(x);
X = fft(x);
X_mag = abs(X/N);
freq = (0:N-1)*Fs/N;

plot(freq, X_mag)
xlabel('Frequency (Hz)')
ylabel('Magnitude')
324 chars
14 lines

gistlibby LogSnag