0% found this document useful (0 votes)
4 views9 pages

Formatted MATLAB Lab

Uploaded by

aryanphras
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

Formatted MATLAB Lab

Uploaded by

aryanphras
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Name: Aryan

Roll No: 23BEC022

Name Aryan , Roll No 23BEC022

MATLAB CODE:
1 To generate a sine wave and sample the sine wave .

clc

clear;

close all;

f = 5;

t = -1:0.001:1;

a = sin(2*pi*f*t);

subplot(2,1,1)

plot(t, a, 'LineWidth', 1.5);

xlabel("Time")

ylabel("Amplitude")

title("Sine Wave")

Ts = 0.005;

n = -1:Ts:1;

ys = sin(2*pi*f*n);

subplot(2,1,2)

stem(n,ys);

xlabel("Time")

ylabel("Amplitude")

title("Sampled Sine Wave")


Name: Aryan
Roll No: 23BEC022

2 To generate and Unit Step Signal and then Sample it .

clc;

clear;

close all;

Ts = 5;

t = -100:1:100;

for k = 1:length(t)

if t(k) >= 0

y(k) = 1;

else

y(k) = 0;

end

end
Name: Aryan
Roll No: 23BEC022
subplot(2,1,1)

plot(t, y);

xlabel('Continuous Time Axis');

ylabel('Amplitude');

title('Continuous-Time Unit Step');

n = -20:Ts:20;

ys = (n >= 0);

subplot(2,1,2)

stem(n, ys, 'filled');

xlabel('Discrete Time Axis');

ylabel('Amplitude');

title('Discrete-Time Unit Step');

grid on;

3 To generate a exponential signal and then sample it .


Name: Aryan
Roll No: 23BEC022
clc

clear;

close all;

f = 5;

t = -1:0.001:1;

a = exp(-t);

subplot(2,1,1)

plot(t, a, 'LineWidth', 1.5);

xlabel("Time")

ylabel("Amplitude")

title("Exponential Function")

Ts = 0.005;

n = -1:Ts:1;

ys = exp(-n);

subplot(2,1,2)

stem(n,ys);

xlabel("Time")

ylabel("Amplitude")

title("Sampled Exponential Function ")


Name: Aryan
Roll No: 23BEC022

4 To generate a Ramp Function and sample it.

clc;

clear;

close all;

Ts = 5;

t = -100:1:100;

for k = 1:length(t)

if t(k) >= 0

y(k) = t(k);

else

y(k) = 0;

end

end

subplot(2,1,1)

plot(t, y);
Name: Aryan
Roll No: 23BEC022
xlabel('Continuous Time Axis');

ylabel('Amplitude');

title('Continuous-Time Ramp Signal');

n = -100:Ts:100;

for k = 1:length(n)

if n(k) >= 0

ys(k) = n(k);

else

ys(k) = 0;

end

end

subplot(2,1,2)

stem(n, ys, 'filled');

xlabel('Discrete Time Axis');

ylabel('Amplitude');

title('Discrete-Time Ramp Signal');

grid on;
Name: Aryan
Roll No: 23BEC022

5 To generate a cosine wave and sample it.

clc

clear;

close all;

f = 5;

t = -1:0.001:1;

a = cos(2*pi*f*t);

subplot(2,1,1)

plot(t, a, 'LineWidth', 1.5);

xlabel("Time")

ylabel("Amplitude")

title("Cosine Function")

Ts = 0.005;

n = -1:Ts:1;

ys = cos(2*pi*f*n);
Name: Aryan
Roll No: 23BEC022
subplot(2,1,2)

stem(n,ys);

xlabel("Time")

ylabel("Amplitude")

title("Sampled Cosine Function ")

6 To plot a Unit Impulse Function

clc;

clear;

close all;

x = -10:10;

for i = 1:21

if x(i)==0

y(i)=1;
Name: Aryan
Roll No: 23BEC022
else

y(i)=0;

end

end

subplot(2,1,1)

stem(x,y)

xlabel("Time Axis")

ylabel("Amplitude")

title("Unit Impulse Function")

You might also like