SS Codes Graphs
SS Codes Graphs
close all;
clear all;
t = -10:0.01:10;
%impulse
imp_s = t == 0;
figure(1);
subplot(2,2,1);
plot(t,imp_s);
title("Impulse Signal");
xlabel("time");
ylabel("del(t)");
%step signal
step_s = t>=0;
figure(1);
subplot(2,2,2);
plot(t,step_s);
title("Unit Step");
xlabel("time");
ylabel("u(t)");
%ramp
ramp_s = t.*(t>=0);
figure(1);
subplot(2,2,3);
plot(t,ramp_s);
title("Ramp Signal");
xlabel("time");
ylabel("r(t)");
%signum
sig_s = -1.*(1.*t<=0) + (1.*t>=0);
figure(1);
subplot(2,2,4);
plot(t,sig_s);
title("Signum Signal");
xlabel("time");
ylabel("sgn(t)");
%exponential positive
exp_s = exp(t);
figure(2);
subplot(2,2,1);
plot(t,exp_s);
title("Postive Exponential Signal");
xlabel("time");
ylabel("exp(t)");
%exponential negative
exp_s = exp(-t);
figure(2);
subplot(2,2,2);
plot(t,exp_s);
title("Negative Exponential Signal");
xlabel("time");
ylabel("exp(-t)");
%sin function
sin_s = sin(t);
figure(2);
subplot(2,2,3);
plot(t,sin_s);
title("Sin Signal");
xlabel("time");
ylabel("sin(t)");
%sinc function
sinc_s = sin(pi*t)./(pi*t);
figure(2);
subplot(2,2,4);
plot(t,sinc_s);
title("Sinc Signal");
xlabel("time");
ylabel("sinc(t)");
close all;
clc;
%t = 0: 0.01: 6.28;
t = 0:0.01:1;
A = 2;
F = 4;
func = A*cos(2*pi*F*t + 60);
%oversampling
subplot(311);
plot(t,func);
title("Oversampling");
xlabel("time");
ylabel("x(t)");
fs = 3 * F;
ts = 1/fs;
n1 = 0 : ts : (fs*ts);
func2 = A*cos(2*pi*F*n1 + 60);
subplot(312);
stem(n1,func2,'r');
xlabel("time");
ylabel("x[n]");
t1 = linspace(0,max(n1),(max(n1/0.001)));
ya = interp1(n1,func2,t1,'spline');
subplot(313);
plot(t1,ya);
xlabel("time");
ylabel("x(t)");
figure;
%Undersampling
subplot(311)
plot(t,func);
title("Undersampling");
xlabel("time");
ylabel("x(t)");
fs = 1.5 * F;
ts = 1/fs;
n1 = 0 : ts : (fs*ts);
func3 = A*cos(2*pi*F*n1 + 60);
subplot(312);
stem(n1,func3,'g');
xlabel("time");
ylabel("x[n]");
t2 = linspace(0,max(n1),(max(n1/0.001)));
ya1 = interp1(n1,func3,t2,'spline');
subplot(313);
plot(t1,ya1);
xlabel("time");
ylabel("x(t)");
figure;
%proper sampling
subplot(311)
plot(t,func);
title("Proper sampling");
xlabel("time");
ylabel("x(t)");
fs = 2 * F;
ts = 1/fs;
n1 = 0 : ts : (fs*ts);
func4 = A*cos(2*pi*F*n1 + 60);
subplot(312);
stem(n1,func4,'y');
xlabel("time");
ylabel("x[n]");
t3 = linspace(0,max(n1),(max(n1/0.001)));
ya2 = interp1(n1,func4,t3,'spline');
subplot(313);
plot(t3,ya2);
xlabel("time");
ylabel("x(t)");
clc;
close all;
clear all;
n = -10:1:10;
%impulse
imp_s = n == 0;
figure(1);
subplot(2,2,1);
stem(n,imp_s);
title("Impulse Signal");
xlabel("time");
ylabel("del(n)");
%step signal
step_s = n>=0;
figure(1);
subplot(2,2,2);
stem(n,step_s);
title("Unit Step");
xlabel("time");
ylabel("u(n)");
%ramp
ramp_s = n.*(n>=0);
figure(1);
subplot(2,2,3);
stem(n,ramp_s);
title("Ramp Signal");
xlabel("time");
ylabel("r(n)");
%signum
sig_s = -1.*(1.*n<=0) + (1.*n>=0);
figure(1);
subplot(2,2,4);
stem(n,sig_s);
title("Signum Signal");
xlabel("time");
ylabel("sgn(n)");
%exponential positive
exp_s = exp(n);
figure(2);
subplot(2,2,1);
stem(n,exp_s);
title("Postive Exponential Signal");
xlabel("time");
ylabel("exp(n)");
%exponential negative
exp_s = exp(-n);
figure(2);
subplot(2,2,2);
stem(n,exp_s);
title("Negative Exponential Signal");
xlabel("time");
ylabel("exp(-n)");
%sin function
sin_s = sin(n);
figure(2);
subplot(2,2,3);
stem(n,sin_s);
title("Sin Signal");
xlabel("time");
ylabel("sin(n)");
%sinc function
sinc_s = sin(n)./(n);
figure(2);
subplot(2,2,4);
stem(n,sinc_s);
title("Sinc Signal");
xlabel("time");
ylabel("sinc(n)");
clc;
close all;
n = -10:1:10;
%og signal
ramp_s = n.*(n>=0);
subplot(331);
stem(n,ramp_s);
title("r[n]");
xlabel("n");
ylabel("r(n)");
%time reversal
ramp_s = -1.*n.*(n<=0);
subplot(334);
stem(n,ramp_s);
title("r[-n]");
xlabel("n");
ylabel("r(-n)");
ans_func = conv(x,h);
subplot(4,1,1);
stem(x);
ylabel("x(n)");
xlabel("n");
subplot(4,1,2);
stem(h);
ylabel("h(n)");
xlabel("n");
subplot(4,1,3);
stem(answ);
title("Convolution using loop");
ylabel("y(n)");
xlabel("n");
subplot(4,1,4);
stem(ans_func);
title("Convolution using in-built function");
ylabel("y(n)");
xlabel("n");
% FR of rect pulse
%generate the rectangle pulse
t = -5:0.001:5;
L = length(t);
for i = 1 : L
if t(i) >= -2 && t(i) <=2
x(i)= 1;
else
x(i)= 0;
end
end
subplot(411);
plot(t,x);
title("Rectangular Pulse")
xlabel('Time');
ylabel('Amplitude');
t = -2:0.001:2;
k = 0;
for f = -5:0.001:5
k = k+1;
X(k) = trapz(t,exp((-1i)*2*pi*f*t));
end
f = -5:0.001:5;
subplot(412);
plot(f,X);
title("Amplitude Spectrum")
xlabel('Freq');
ylabel('Amplitude');
subplot(411);
plot(t,y1);
title("Sin Function")
xlabel('time');
ylabel('Amplitude');
t = -5:0.001:5;
k = 0;
for f = -5:0.001:5
k = k+1;
X(k) = trapz(y1,exp((-1i)*2*pi*f*t));
end
f = -5:0.001:5;
subplot(412);
plot(f,X);
title("Amplitude Spectrum")
xlabel('Freq');
ylabel('Amplitude');
fc = 2;
y1 = cos(2*pi*fc*t);
subplot(411);
plot(t,y1);
title("Cos Function")
xlabel('time');
ylabel('Amplitude');
t = -5:0.001:5;
k = 0;
for f = -5:0.001:5
k = k+1;
X(k) = trapz(y1,exp((-1i)*2*pi*f*t));
end
f = -5:0.001:5;
subplot(412);
plot(f,X);
title("Amplitude Spectrum")
xlabel('Freq');
ylabel('Amplitude');