Input functions and using lsim for sin input???
Show older comments
I am trying to plot the response of a RC low pass circuit with input 10Vsin with frequency 100Hz and the input signal needs to have a duration of 0.1s but the plot needs to be from 0:10. Heres my code, I cannot figure out what I am doing wrong
%% Problem 2a
%RC Low Pass Filter
%Vin = 10sin(wt)
%R = 4700 ohms
%C = 47 nano-farad
%fc = 720.8Hertz
%TF[Vout/Vin] =[1/(RCs + 1)]
%Plot Vout
R = 4700;
C = 47*10^-9;
w = 2*pi*100;
t1 = 0:0.001:0.1;
t2 = 0.101:0.001:10;
u1 = 10*sin(w*t1);
u2 = 0;
t = [t1 t2];
u = [u1 u2];
num = [1];
den = [R*C 1];
sys = tf(num,den);
Vo = lsim(sys,u,t);
figure;
plot(t,Vo)
Answers (1)
Sulaymon Eshkabilov
on 20 May 2019
Here is the fixed code:
R = 4700;
C = 47*10^-9;
w = 2*pi*100;
dt = 1e-5; % Smaller sampling time is needed
t1 = 0:dt:0.1;
t2 = 0.1+dt:dt:10;
u1 = 10*sin(w*t1);
u2 = zeros(size(t2)); % Length of u2 has to be equal to t2
t = [t1 t2];
u = [u1 u2];
num = [1];
den = [R*C 1];
sys = tf(num,den);
Vo = lsim(sys,u,t);
figure;
plot(t,u, 'r-o', t, Vo, 'b-'), grid on
legend('Input signal (excitation)',' System Response')
xlim([0, 0.5])
2 Comments
mnbaig94
on 28 Nov 2020
Can you please explain this part? Why you did t1,t2 and u1,u2?
Why not just u1 as input?
u1 = 10*sin(w*t1);
u2 = zeros(size(t2)); % Length of u2 has to be equal to t2
t = [t1 t2];
u = [u1 u2];
Sulaymon Eshkabilov
on 28 Nov 2020
That was part of your exercise to have u composed of u1 and u2. If zero padding part of your signal is unnecessary, then you can use u1 instead of u in:
Vo = lsim(sys,u1,t1);
Categories
Find more on MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!