plot the first seven fourier coefficients versus frequency of a rectified 50hz sine wave in matlab
main.m
% Define the parametersf = 50; % frequency of the sine wavefs = 1000; % sampling frequencyt = 0:1/fs:1; % time vectorx = abs(sin(2*pi*f*t)); % rectified 50 Hz sine wave% Compute the Fourier TransformN = length(x); % length of the signalX = fft(x)/N; % compute the Fourier Transform and normalize% Frequencies vectorfrequencies = linspace(0, fs, N);
% Plot the first seven Fourier coefficients versus frequencyfigure;
stem(frequencies(1:7), abs(X(1:7)));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('First seven Fourier coefficients of a rectified 50Hz sine wave');
587 chars
20 lines
This code will plot the first seven Fourier coefficients versus frequency for a rectified 50Hz sine wave sampled at 1000Hz in MATLAB.