plot the fourier transform of a 1000 point sine wave at 200hz in matlab in matlab

To plot the Fourier transform of a 1000 point sine wave at 200 Hz in Matlab, you can follow these steps:

  1. Generate the sine wave data:
main.m
fs = 2000;  % sampling frequency
t = 0:1/fs:0.5;  % time vector
x = sin(2*pi*200*t);  % 1000-point sine wave at 200 Hz
119 chars
4 lines

Here, fs is the sampling frequency, t is the time vector of 0.5 seconds with a step size of 1/fs, and x is the 1000-point sine wave at 200 Hz.

  1. Compute the single-sided Fourier transform of the signal using the fft function:
main.m
N = length(x);  % length of the signal
X = fft(x)/N;  % Fourier coefficients with normalization
f = fs*(0:(N/2))/N;  % frequency vector
136 chars
4 lines

Here, N is the length of the signal, X is the Fourier coefficients with normalization factor of N, and f is the frequency vector with values up to the Nyquist frequency.

  1. Plot the magnitude of the Fourier transform:
main.m
plot(f, 2*abs(X(1:N/2+1)));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
75 chars
4 lines

Here, we plot the magnitude of the Fourier coefficients up to the Nyquist frequency. The 2* factor is because the Fourier coefficients correspond to the amplitude of the sine wave, and we want to plot the magnitude of the complex coefficients.

The final code would look like this:

main.m
fs = 2000;  % sampling frequency
t = 0:1/fs:0.5;  % time vector
x = sin(2*pi*200*t);  % 1000-point sine wave at 200 Hz

N = length(x);  % length of the signal
X = fft(x)/N;  % Fourier coefficients with normalization
f = fs*(0:(N/2))/N;  % frequency vector

plot(f, 2*abs(X(1:N/2+1)));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
332 chars
12 lines

This will plot a single peak at 200 Hz with a magnitude of 0.5.

gistlibby LogSnag