Professional Documents
Culture Documents
Assignment 2: Answer
Assignment 2: Answer
Assignment 2A
Question 1.
Answer:
MATLAB Code:
25
lms (records)
Assignment 2B
Question 1.
Answer:
MATLAB Code :
clc
close all
clear all
%% Initialising transfer function parameters
zeta = 0.2;
wn = 1;
t = linspace(0,30,1000);
wd = wn*sqrt(1-zeta^2);
% initialisng output signal array
c = zeros(1,1000);
% initialisng envelope arrays
Low_env = zeros(1,1000);
Up_env = zeros(1,1000);
% function for signal and envelopes
for i = 1: length(t)
c(i) = 1 - (exp(-zeta*wn*t(i))/sqrt(1-zeta^2))*sin(wd*t(i) +
atan(sqrt(1-zeta^2)/zeta));
low_env(i) = 1 - (exp(-zeta*wn*t(i))/sqrt(1-zeta^2));
up_env(i) = 1 + (exp(-zeta*wn*t(i))/sqrt(1-zeta^2));
end
%% PLOTTING SIGNAL AND ENVELOPES
plot(t,c,'.-c')
xlabel('Time(t) in seconds')
ylabel('c(t) (unitless magnitude)')
title('Time response with exponential envelopes')
hold on;
plot(t,low_env,'--m')
hold on;
plot(t,up_env,'--m')
OUTPUT:
Question 2.
Answer:
MATLAB Code:
clear all
close all
clc
%% transfer function parameters
wn=1;
t = linspace(0,30,1000);
zeta=[0, 0.2, 0.4, 0.6, 0.8, 1.0];
wd = 0;
% initialize output signal array
c = zeros(6,1000);
% function for signal in time domain and with varying values of zeta
for j=1:length(zeta)
for i = 1: length(t)
wd = wn*sqrt(1-zeta(j)^2);
c(j,i)=1 -(exp(-zeta(j)*wn*t(i))/sqrt(1-zeta(j)^2))*sin(wd*t(i) +
atan(sqrt(1-zeta(j)^2)/zeta(j)));
end
end
%%plotting signals for different z values
plot(t,c)
xlabel('Time(t) in seconds')
ylabel('c(t)')
title('Time responses (unitless magnitude)')
legend('zeta = 0.0' ,'zeta = 0.2', 'zeta = 0.4', 'zeta = 0.6', 'zeta = 0.8'
,'zeta = 1.0');
Question 3.
Answer:
MATLAB Code for Part 1 and Part 2:
clear all;
close all;
clc
num = [1];
%% random values of r, l and c
R=10+(50-10)*rand();
L=5+(30-5)*rand();
C=0.1+(1-0.1)*rand();
% transfer function denominator coefficients
den = [1 R/L 1/L*C];
% transfer function
g = tf (num,den)
t = feedback(g,1);
%plotting step and impulse responses
step(t,'m');
hold on;
impulse(t,'k');
legend('Step Response', 'Impulse Response')
MATLAB Code for part 3:
function alltime(c)
%% INITIALISING Time PARAMETER
t = linspace(0,30,1000);
%% FINDING RISE TIME
tmin=1000;
tmax=1000;
for i = 1:length(t)
if c(i)>=0 %% 0% OF FINAL VALUE
if i<tmin
tmin=i;
end
end
if c(i)>=c(1000) %% 100% OF FINAL VALUE
if i<tmax
tmax=i;
end
end
end
%% FINDING PEAK TIME
Tp=0;
for i=1:length(t)
if c(i)==max(c) %% MAX VALUE
Tp=i;
end
end
tr=t(tmax)-t(tmin);
tp=t(Tp);
%% FINDING MAX OVERSHOOT
max_overshoot=max(c)-c(length(c));
%% FINDING SETTLING TIME
ts=0;
for i =1:length(t)
if c(i)>1.02*c(1000) || c(i)<0.98*c(1000)
ts=i;
end
end
tsettling=t(ts+1);
disp('Rise Time')
disp(tr)
disp('Peak Time')
disp(tp)
disp('Max Overshoot')
disp(max_overshoot)
disp('Settling Time')
disp(tsettling)
end
New to MATLAB? See resources for G ettin St rted.
>> time_response(c)
Rise Time
Peat Time
3.2132
Settling
Time
19.7898
Question 4.
Answer:
Simulink circuit:
Transfer function and Random number generator parameters:
Output :
We can also do in matlab without simulink ,
Matlab code :
clc;
clear all;
sys = tf([1],[1 3 2]); % transfer function
t = (0:0.01:10); % time vector
x = 10*heaviside(t); % input
noise = 0.2*(rand(1,size(t,2))-0.5); % noise of 2%
r = noise+x; % noise was added to system
subplot(2,1,1) % first plot of subplot
plot(t,r) % ploting the input signal
title('Input Signal') % title
ylim([0 12]) % limit of y axis
subplot(2,1,2) % 2nd plot
lsim(sys,r,t) % lsim plots response of system w.r.t an arbitary signal