create waveforms of current and voltage in matlab

main.m
% Create a time vector
t = 0:0.001:1; % Time from 0 to 1 second with a step of 0.001 seconds

% Create a sine wave for voltage
frequency = 50; % Frequency of the sine wave in Hz
amplitude = 220; % Amplitude of the sine wave in volts
voltage = amplitude * sin(2 * pi * frequency * t); % Calculation of the sine wave

% Create a square wave for current
dutyCycle = 50; % Duty cycle of the square wave (percentage)
current = amplitude * square(2 * pi * frequency * t, dutyCycle); % Calculation of the square wave

% Plot the voltage waveform
subplot(2, 1, 1);
plot(t, voltage);
title('Voltage Waveform');
xlabel('Time (s)');
ylabel('Voltage (V)');

% Plot the current waveform
subplot(2, 1, 2);
plot(t, current);
title('Current Waveform');
xlabel('Time (s)');
ylabel('Current (A)');
780 chars
26 lines

This MATLAB code creates a sine wave for voltage and a square wave for current with a frequency of 50 Hz and an amplitude of 220 volts. It then plots these two waveforms on separate subplots.

related categories

gistlibby LogSnag