half wave rectifier in matlab

To implement a simple half-wave rectifier in MATLAB, you can follow these steps:

  1. Define the input sinusoidal signal with amplitude A, frequency f, and time period T
A = 5; % amplitude of input signal
f = 50; % frequency of input signal
T = 1/f; % time period of input signal
t = 0:T/100:2*T; % time vector for simulation
x = A*sin(2*pi*f*t); % input signal
192 chars
6 lines
  1. Implement a diode model that will rectify the input signal by allowing currents only in one direction (positive half cycles)
Von = 0.6; % diode turn-on voltage
Rf = 1e6; % diode forward resistance
y = zeros(size(x)); % initialize output signal
for i = 1:length(x)
    if x(i) > Von
        y(i) = x(i) - Von;
    end
end
196 chars
9 lines
  1. Plot the input and output signals using MATLAB's plot function
figure;
subplot(2,1,1);
plot(t,x);
xlabel('Time (s)');
ylabel('Input Amplitude (V)');
title('Input Signal');
grid on;
subplot(2,1,2);
plot(t,y);
xlabel('Time (s)');
ylabel('Output Amplitude (V)');
title('Output Signal (Half-wave Rectified)');
grid on;
252 chars
14 lines

You can also implement a half-wave rectifier using Simulink by modelling the diode as a rectifier block and providing the input signal to it.

gistlibby LogSnag