Вы находитесь на странице: 1из 22

Periodic signals:

clc;
clearall;
closeall;
t=0:0.001:1;
x=sin(2*pi*2*t);
y=sawtooth(2*pi*2*t);
z=square(2*pi*2*t);
u= sawtooth(2*pi*2*t,0.5)
figure(1);
plot(t,x,t,y,t,z,t,u);
legend(sin,sawtooth,square,taingular)
a=-5:0.01:5;
b=sinc(a);
figure(2)
plot(a,b)

APeriodic signals:
clc
clearall;
closeall;
t=-5:5;
x=[t==0];
figure(1)
stem(t,x);
y=[t>0];
figure(2)
stem(t,y)
z=t.*y;
figure(3);
stem(t,z)

clc,
close all;
clear all;
t=0:0.001:1;
L=length(t);

f1=1;
f2=3;
x1=sin(2*pi*f1*t);
x2=sin(2*pi*f2*t);
figure;
subplot(3,2,1);
plot(t,x1,'b',t,x2,'r');
title('the signals x1(t) and x2(t)');
x3=x1+x2;
subplot(3,2,2);
plot(t,x3);
title('the sum of x1(t) and x2(t)');
x4=x1.*x2;
subplot(3,2,3);
plot(t,x4);
title('the multiplication of x1(t) and x2(t)');
t=-1:0.001:0;
x5=sin(2*pi*f1*(-t));
x6=sin(2*pi*f2*(-t));
subplot(3,2,4);
plot(t,x5,'b',t,x6,'r');
title('the folding of x1(t)and x2(t)');
x7=[zeros(1,200),x2(1:(L-200))];
subplot(3,2,5);
plot(t,x7);
title('the shifting of x1(t)and x2(t)');
x8=x2.^2;
subplot(3,2,6);

plot(t,x8);
title('the squaring of x1(t)and x2(t)');

Real and imaginary parts of signal and sequences


clc;
close all;
clear all;
n=0:10;
z=exp(j*n);
a=real(z)
b=imag(z)
subplot(3,2,1)
stem(n,z)
subplot(3,2,2)
plot(n,a)
subplot(3,2,3)
plot(n,b)
t=0:0.01:10;
k=exp(j*2*pi*t)
subplot(3,2,4)
plot(k)
l=real(k)
m=imag(k)
subplot(3,2,5)
plot(t,l)
subplot(3,2,6)
plot(t,m)

Even and odd parts of signal and sequences

clc;
clear all;
close all;
n=0:0.1:1;
x=cos(2*pi*n)+sin(2*pi*n);
x_folding=fliplr(x);
xeven=(x+x_folding)/2;
xodd=(x-x_folding)/2;
subplot(3,2,1)
stem(n,x);
subplot(3,2,2)
stem(n,xeven);
subplot(3,2,3)
stem(n,xodd);
k=0:10;
l=length(k)
y=rand(1,l);

y_folding=fliplr(y);
yeven=(y+y_folding)/2;
yodd=(y-y_folding)/2;
subplot(3,2,4)
stem(y);
subplot(3,2,5)
stem(yeven);
subplot(3,2,6)
stem(yodd);

clc;
clear all;
close all;
x=[1 3 5 7 9];
y=[12 5 8 0 4];
z=conv(x,y);
n=length(x)+length(y)-1
subplot(2,1,1);
stem(z)

t=0:0.01:1;
k=sin(t);
m=cos(t);
n=conv(k,m);
subplot(2,1,2);
plot(n);

clc;
clear all;
close all;
t=0:0.01:1;
x=sin(2*pi*2*t);
y=cos(2*pi*10*t);
k=xcorr(x);
m=xcorr(x,y);
subplot(2,2,1)
plot(t,x);
subplot(2,2,2)
plot(t,y);
subplot(2,2,3)
plot(k);
subplot(2,2,4)

plot(m);

clc;
close all;
clear all;
x1 = input('enter the value for first input');
x2 = input('enter the value for second input');
a1 = input('enter weighting value for first input a1= ');
a2 = input('enter weighting value for second input a2= ');
f = menu('Chose a function','cos(x)','2*x(n)') % to chose which function
if f == 1 % defined system function y = cos(x)
y1 = a1*cos(x1) + a2*cos(x2);
y2 = cos((a1*x1)+(a2*x2));
if y1==y2
disp('y = cos(x) is linear system')
else
disp('y = cos(x) is non-linear system')
end
else% defined system function y = 2*x

y1 = a1*2*x1 + a2*2*x2;
y2 = 2*((a1*x1)+(a2*x2));
if y1==y2
disp('y = 2*x is linear system')
else
disp('y = 2*x is non-linear system')
end
end

enter the value for first input3


enter the value for second input3
enter weighting value for first input a1= 2
enter weighting value for second input a2= 3

f=

y = 2*x is linear system

clc;
close all;
clear all;
x = input('enter input applied to the system')
p= input('enter the time at which the input arrived')
m = input('enter the time instant at which you want to calculate output')
k= m-p
x(p)=x;
f = menu('Chose a function','cos(x)','n*x(n)') % to chose which function
if f == 1 % defined system function y(n) = cos(x(n))
y1 = cos(x(p))
y2 = cos(x(m-k))
if y1 == y2
disp('The given system y(n) = cos(x(n)) is Time invarient')
else
disp('The given system y(n) = cos(x(n)) is Time varient')
end
else% defined system function y(n) = n x(n)
y1 = p*x(p)
y2 = m*x(m-k)
if y1 == y2
disp('The given system y(n) = n*x(n) is Time invarient')
else

disp('The given system y(n) = n*x(n) is Time varient')


end
end

enter input applied to the system3


x =
3
enter the time at which the input arrived3
p =
3
enter the time instant at which you want to calculate output3
m =
3
k =
0
f =
2
y1 =
9
y2 =
9
The given system y(n) = n*x(n) is Time invarient

clc;
clear all;

close all;
b=[5 1];
a=[2 1];
n=0:10
x=n==0
y=filter(b,a,x);
subplot(2,2,1)
stem(n,y);
title('impulse response');
xlabel('n');ylabel('y(n)');
z=n>0
k=filter(b,a,z);
subplot(2,2,2)
stem(n,k);
title('step response');
xlabel('n');ylabel('k(n)')
t=0:0.1:2*pi;
x1=sin(t);
m=filter(b,a,x1);
subplot(2,2,3)
stem(t,m);
title('sin response');
xlabel('n');ylabel('m(n)');
subplot(2,2,4)
zplane(b,a)

clc;
clear all;
close all;
N=input('enter the no. of signals to reconstruct=');
n_har=input('enter the no. of harmonics in each signal=');
t=-1:0.001:1;
omega_0=2*pi;
for k=1:N
x=0.5;
for n=1:2:n_har(k)
b_n=2/(n*pi);
x=x+b_n*sin(n*omega_0*t);
end
subplot(N,1,k);
plot(t,x);
xlabel('time--->');
ylabel('amp---->');
axis([-1 1 -0.5 1.5]);
text(0.55,1.0,['no.of har=',num2str(n_har(k))]);

end

clc
clear all;
close all;
syms t;
x=exp(-2*t)*heaviside(t);
y=fourier(x);

disp('Fourier Transform of input signal');


y
z=ifourier(y);
disp('Inverse Fourier Transform of input signal');
z
mg=abs(y);
subplot(2,1,1);
ezplot(mg);
xlabel('time');
ylabel('amplitude');
title('magnitude spectrum of a input signal');
grid;
pha=atan(imag(y)/real(y));
subplot(2,1,2);
ezplot(pha);
xlabel('time');
ylabel('amplitude');
title('phasespectrum of a input signal');
grid;

clc
clear all;
close all;
syms t;
x=exp(-2*t)*heaviside(t);
y=laplace(x);
disp('Laplace Transform of input signal');
y
z=ilaplace(y);
disp('Inverse Laplace Transform of input signal');
z

clc;
clear all;
close all;
num=input('enter numerator co-efficients');
den=input('enter denominator co-efficients');
h=tf(num,den);
poles=roots(den);
zeros=roots(num);
sgrid;
pzmap(h);
grid on;
title('locating poles of zeros on s-plane');

enter numerator co-efficients1


enter denominator co-efficients[1 0.5]

clc;
clear all;
close all;
num=input('enter numerator coefficient');
den=input('enter denominator coefficient');
p=roots(den);
z=roots(num);
zplane(p,z);
grid;
title('locating poler and zeros on s-plane');

enter numerator coefficient 1

enter denominator coefficient[1 0.5]

clc
clear
fm=input('Enter the Msg frequency(fm)');
t=0:0.01:1;
x=sin(2*pi*fm*t);
subplot(2,2,1);
plot(t,x);
fs1=input('Enter the sampling frequency greater than 2xfm');
n=0:0.001:1;

y=sin(2*pi*n*fm);
subplot(2,2,2);
plot(n,y);
fs2=input('enter the sampling frequency less than 2xfm');
n1=0:1/fs2:1;
z=sin(2*pi*n1*fm);
subplot(2,2,3);
plot(n1,z);
fs3=input('Enter the sampling frequency equal 2xfm');
n2=0:1/fs3:1
k=sin(2*pi*n2*fm);
subplot(2,2,4);
plot(n2,k);

Вам также может понравиться