create a half-wave sine in time and in frequency without usage fft in matlab

To create a half-wave sine wave in time domain without using FFT in MATLAB, you can directly generate the waveform using the sine function and then set the negative values to 0. Here's an example code snippet:

main.m
% Time domain representation
Fs = 1000; % Sampling frequency
t = 0:1/Fs:1; % Time vector from 0 to 1 second

% Generate half-wave sine wave
f = 5; % Frequency of the sine wave
half_wave_sine = sin(2*pi*f*t);
half_wave_sine(half_wave_sine < 0) = 0; % Set negative values to 0

% Plot the half-wave sine wave
plot(t, half_wave_sine);
xlabel('Time (s)');
ylabel('Amplitude');
title('Half-Wave Sine Wave in Time Domain');
418 chars
15 lines

To obtain the frequency domain representation without using FFT, you can calculate the Fourier transform of the half-wave sine wave using the formula for Fourier transform of sine wave. First, calculate the Fourier coefficients manually, and then plot the magnitude of these coefficients.

main.m
% Frequency domain representation
N = length(half_wave_sine);
k = 0:N-1; % Index for Fourier coefficients
frequencies = k*(Fs/N); % Frequency axis

% Calculate Fourier coefficients manually for half-wave sine wave
A_k = (2/N)*abs(sinc(pi*f*(k/N))); % Magnitude of Fourier coefficients

% Plot the magnitude of the Fourier coefficients
figure;
stem(frequencies, A_k);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Frequency Spectrum of Half-Wave Sine Wave');
466 chars
15 lines

By following these steps, you can create a half-wave sine wave in both time and frequency domains without using FFT in MATLAB.

related categories

gistlibby LogSnag