compute the frequencies and amplitudes of the first seven fourier coefficients of a rectified half-wave 50hz sine in matlab

main.m
% Define the parameters
f = 50; % Frequency in Hz
t = 0:0.0001:1; % Time vector from 0 to 1 second
x = abs(sin(2*pi*f*t)); % Rectified half-wave 50Hz sine wave

% Perform Fourier Transform
N = length(x); % Length of the signal
X = fft(x)/N; % Normalize the FFT

% Find frequencies and amplitudes of the first seven Fourier coefficients
frequencies = (0:N-1)*(1/(N))*(1/(t(2)-t(1))); % Frequency vector
amplitudes = 2*abs(X(1:N/2+1)); % Compute the amplitude of the FFT

% Extract the first seven coefficients
first_seven_frequencies = frequencies(1:7);
first_seven_amplitudes = amplitudes(1:7);
595 chars
17 lines

This code calculates the frequencies and amplitudes of the first seven Fourier coefficients of a rectified half-wave 50Hz sine wave in MATLAB.

gistlibby LogSnag