compute the frequencies and amplitudes of the first seven fourier coefficients of a rectified half-wave sine in matlab
main.m
% Define the parametersA = 1; % Amplitude of the sine wavef = 1; % Frequency of the sine waveFs = 1000; % Sampling frequencyt = 0:1/Fs:1; % Time vectorrectified_sine = A * abs(sin(2*pi*f*t)); % Rectified half-wave sine signal% Compute the Fourier TransformN = length(rectified_sine); % Length of the signalY = fft(rectified_sine)/N; % Normalize the FFT resultsfrequencies = 0:Fs/N:Fs*(N-1)/N; % Frequency vector% Extract the first seven Fourier coefficientsnCoefficients = 7;
coefficients = Y(1:nCoefficients+1);
% Calculate frequencies and amplitudes of the coefficientsfrequencies_coeff = (0:nCoefficients)*(Fs/N); % Frequencies of the coefficientsamplitudes_coeff = abs(coefficients); % Amplitudes of the coefficients% Display the frequencies and amplitudesdisp('Frequencies of the first seven Fourier coefficients:');
disp(frequencies_coeff);
disp('Amplitudes of the first seven Fourier coefficients:');
disp(amplitudes_coeff);
961 chars
26 lines
This code calculates the frequencies and amplitudes of the first seven Fourier coefficients of a rectified half-wave sine in MATLAB.