Matlab Codes
Matlab Codes
clear all;
close all; %cos
subplot(3,3,5);
n=-5:1:10; stem(n,f)
for i=-5:1:10 title('Cosine sequence');
u=i+6; ylabel('Amplitude');
if (i==0) xlabel('n');
d(u)=1;
else
d(u)=0;
end
if (i<0)
st(u)=0;
rmp(u)=0;
else
st(u)=1;
rmp(u)=i;
end
e(u)=sin(i);
f(u)=cos(i);
end
%unit impulse
subplot(3,3,1)
stem(n,d)
title('Unit Impulse sequence');
ylabel('Amplitude');
xlabel('n');
%unit step
subplot(3,3,2);
stem(n,st);
title('Unit Step sequence');
ylabel('Amplitude');
xlabel('n');
%unit ramp
subplot(3,3,3);
stem(n,rmp)
title('Ramp sequence');
ylabel('Amplitude');
xlabel('n');
%sine
subplot(3,3,4);
stem(n,e)
title('Sine sequence');
ylabel('Amplitude');
clc; xlabel('n');
clear all; ylabel('Amplitude');
close all; subplot(2,2,2);
n=-10:1:10; stem(n,b1);
a=0.5; title('a=0.5 ; -1<=a<=0');
b=-0.5; xlabel('n');
c=-2; ylabel('Amplitude')
d=2; subplot(2,2,3);
for i=-10:1:10 stem(n,c1);
u=i+11; title('a=2 ; a>=1');
a1(u)=power(a,i); xlabel('n');
b1(u)=power(b,i); ylabel('Amplitude')
c1(u)=power(c,i); subplot(2,2,4);
d1(u)=power(d,i); stem(n,d1);
end title('a=-2 ; a<=-1');
subplot(2,2,1); xlabel('n');
stem(n,a1); ylabel('Amplitude')
title('a=0.5 ; 0<=a<=1');
clc;
clear all;
close all;
lb=-10;
ub=10;
step=1;
n=lb:step:ub;
s=2.*n.*((0.8).^n);
d=randi([1,10],[1,21]);
x=s+d;
p=downsample(x,2);
subplot(4,2,1);stem(n,s);
subplot(4,2,2);stem(n,d);
subplot(4,2,3);stem(n,x);
subplot(4,2,4);stem(p);
clc;
clear all;
close all;
lb=1;
ub=50;
step=1;
mean=20;
var=40;
n=lb:step:ub;
pi=3.14;
e=2.72;
for i=lb:step:ub
a(i)=(1./sqrt(2.*pi.*var));
b(i)=(-((i-mean).^2))/(2.*var);
c(i)=e.^b(i);
gauss(i)=a(i).*c(i);
end
rand=normrnd(mean,sqrt(var),1,50);
pdf=normpdf(n,mean,sqrt(var));
% stem(n,a);
subplot(3,1,1);stem(n,gauss);
subplot(3,1,2);stem(n,rand);
subplot(3,1,3);stem(n,pdf);