clc;
clear all;
close all;
% RC parameters
R = 10; % Resistance (Ohms)
C = 0.1; % Capacitance (F)
tau = R*C; % Time constant
disp(['Time Constant (tau) = ', num2str(tau)]);
% Transfer Function of RC circuit
num = [1];
den = [R*C 1];
sys = tau(num, den);
% Time vector
t = 0:0.001:2;
% Square wave input
u = square(2*pi*f*t); % frequency = 2 Hz
% Time response
y = lsim(sys, u, t);
% Plot
figure;
subplot(2,1,1);
plot(t,u);
title('Square Wave Input');
xlabel('Time (sec)');
ylabel('Input');
subplot(2,1,2);
plot(t,y);
title('Voltage Response of RC Circuit');
xlabel('Time (sec)');
ylabel('Vc (V)');
To embed this project on your website, copy the following code and paste it into your website's HTML: