Input functions and using lsim for sin input???
조회 수: 5 (최근 30일)
이전 댓글 표시
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)
댓글 수: 0
답변 (1개)
Sulaymon Eshkabilov
2019년 5월 20일
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
mnbaig94
2020년 11월 28일
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
2020년 11월 28일
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);
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!