0% found this document useful (0 votes)
15 views11 pages

LAB No. 5 Task No.2: Function

Download as doc, pdf, or txt
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 11

LAB No.

5
Task No.2

function[]=lab5task2()
n=0:3;
x=[1 2 3 1];
n1=-1:2;
y=[1 2 1 -1];
c=conv(x,y)
nc=-1:5
subplot(1,3,1)
stem(n,x)
subplot(1,3,2)
stem(n1,y)
subplot(1,3,3)
stem(nc,c)

OUTPUT:

>> lab5task2()

c=

1 4 8 8 3 -2 -1

nc =

-1 0 1 2 3 4 5

>>
3 2 8

7
2.5 1.5
6

5
2 1
4

1.5 0.5 3

2
1 0
1

0
0.5 -0.5
-1

0 -1 -2
0 2 4 -2 0 2 -5 0 5
LAB No. 5
Task No. 4

function[]=lab5task4()
n=-4:4;
x=[0 0 1 0 2 0 0 -1 0];
n1=-4:4;
y=[0 0 1 0.8 0.6 0 0 0 0];
c=conv(x,y)
nc=-8:8
subplot(1,3,1)
stem(n,x)
subplot(1,3,2)
stem(n1,y)
subplot(1,3,3)
stem(nc,c)
OUTPUT:

>> lab5task4()

c =

Columns 1 through 7

0 0 0 0 1.0000 0.8000
2.6000

Columns 8 through 14

1.6000 1.2000 -1.0000 -0.8000 -0.6000 0


0

Columns 15 through 17

0 0 0

nc =

Columns 1 through 12

-8 -7 -6 -5 -4 -3 -2 -1 0 1
2 3

Columns 13 through 17

4 5 6 7 8

>>
2 1 3

0.9
2.5
1.5
0.8
2
0.7
1
1.5
0.6

0.5 0.5 1

0.4
0.5
0
0.3
0
0.2
-0.5
-0.5
0.1

-1 0 -1
-5 0 5 -5 0 5 -10 0 10
LAB No. 5
Task No. 6

function[]=lab5task6()
n=0:7;
x=[1 -1 2 0 -1 0 0 0];
c=xcorr(x)
nc=-7:7
subplot(1,2,1)
stem(n,x)
subplot(1,2,2)
stem(nc,c)

OUTPUT:

>> lab5task6()

c=

Columns 1 through 7

0.0000 0.0000 -0.0000 -1.0000 1.0000 -0.0000 -3.0000

Columns 8 through 14

7.0000 -3.0000 -0.0000 1.0000 -1.0000 -0.0000 0.0000

Column 15

0.0000

nc =

Columns 1 through 12

-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4

Columns 13 through 15

5 6 7

>>
2 7

6
1.5
5

4
1
3

0.5 2

1
0
0

-1
-0.5
-2

-1 -3
0 2 4 6 8 -10 -5 0 5 10
LAB 5
TASK 3

function[y,xy]=lab5task5(x,nx,h,nh)
nh=0:3;
x=[1 2 3 1];
nx=-1:2;
h=[1 2 3 -1];
y=conv(x,h)
p=(nx<0)
q=sum(p,2)
r=(nh<0)
s=sum(r,2)
k=-(q+s)
c=length(nx)+length(nh)-1
w=k+c
xy=k:w-1
subplot(1,3,1)
stem(nx,x)
subplot(1,3,2)
stem(nh,h)
subplot(1,3,3)
stem(xy,y)

Result:

>> lab5task3

y=

1 4 10 12 9 0 -1

p=

1 0 0 0

q=

r=

0 0 0 0
s=

k=

-1

c=

w=

xy =

-1 0 1 2 3 4 5

ans =

1 4 10 12 9 0 -1

>>
3 3 12

2.5 10
2.5

2
8
2
1.5
6
1.5 1
4
0.5
1
2
0

0.5
-0.5 0

0 -1 -2
-2 0 2 0 2 4 -5 0 5

TASK 7

function[y,xy]=lab5task7
n=0:7;
x=[1 -1 2 0 -1 0 0 0]
c=abs(x)
w=c.^2;
e=sum(w,2)
d=xcorr(x)
nd=-7:7;
stem(nd,d);

Result:

>> lab5task7

x=

1 -1 2 0 -1 0 0 0

c=
1 1 2 0 1 0 0 0

e=

d=

Columns 1 through 7

0.0000 0.0000 -0.0000 -1.0000 1.0000 -0.0000 -3.0000

Columns 8 through 14

7.0000 -3.0000 -0.0000 1.0000 -1.0000 -0.0000 0.0000

Column 15

0.0000

>>

-1

-2

-3
-8 -6 -4 -2 0 2 4 6 8
TASK 8

function[y,xy]=lab5task8
g=xcorr(x,y)
n=-8:8;
x=[1 2 3 1]
subplot(2,1,1)
stem(n,g)
w=[0 0 0 0]
for n=1:5
w(n)=g(n+8)
end
n=0:4
subplot(2,1,2)
stem(n,w)

You might also like