half-wave rectified sine in matlab

main.m
% Generate a sine wave signal
t = 0:0.01:2*pi;
f = 1;
x = sin(2*pi*f*t);

% Half-wave rectify the sine wave signal
y = x;
y(y<0) = 0;

% Plot the original and half-wave rectified signals
figure;
subplot(2,1,1);
plot(t, x);
title('Original Sine Wave Signal');
xlabel('Time');
ylabel('Amplitude');

subplot(2,1,2);
plot(t, y);
title('Half-Wave Rectified Sine Wave Signal');
xlabel('Time');
ylabel('Amplitude');
409 chars
23 lines

This code generates a sine wave signal, then performs half-wave rectification on the signal, and finally plots the original and half-wave rectified signals.

related categories

gistlibby LogSnag