create an half-wave sine in time and in frequency with fourier coefficients in matlab

main.m
% Time domain - half-wave sine signal
fs = 1000; % Sampling frequency
t = 0:1/fs:1; % Time vector from 0 to 1 second
x = sin(2*pi*5*t).*(sin(2*pi*5*t) > 0);

% Frequency domain - Fourier coefficients
N = 50; % Number of Fourier coefficients
coefficients = zeros(1, N);

for n = 1:N
    coefficients(n) = integral(@(t) sin(2*pi*5*t).*(sin(2*pi*5*t) > 0).*exp(-1i*2*pi*n*t), 0, 1);
end

disp(coefficients);
405 chars
15 lines

gistlibby LogSnag