49
LOGO LAB 3 Discrete Time Signals Part One iugaza2010.blogspot.com [email protected]

LAB 3 Discrete Time Signals Part One

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: LAB 3 Discrete Time Signals Part One

LOGO

LAB 3

Discrete Time Signals

Part One

[email protected]

Page 2: LAB 3 Discrete Time Signals Part One

2

Page 3: LAB 3 Discrete Time Signals Part One

3

1. Unit sample sequence

Write a Matlab function to generate

x(n)=delta(n-no), n1<=n<=n2

Page 4: LAB 3 Discrete Time Signals Part One

4

Note

Page 5: LAB 3 Discrete Time Signals Part One

5

function [x,n]=impseq(no,n1,n2)

n=[n1:n2];

x=[(n-no) == 0];

end

Write a Matlab function to generate

x(n)=delta(n-no), n1<=n<=n2

[x,n]=impseq(5,2,6)

Results:

n =2 3 4 5 6

x = 0 0 0 1 02 3 4 5 6

0

0.2

0.4

0.6

0.8

1

Page 6: LAB 3 Discrete Time Signals Part One

6

2. Unit step sequence

Write a Matlab function to generate

x(n)=step(n-no), n1<=n<=n2

Page 7: LAB 3 Discrete Time Signals Part One

7

Page 8: LAB 3 Discrete Time Signals Part One

8

function [x,n]=stepseq(no,n1,n2)

n=[n1:n2];

x=[(n-no) >= 0];

end

Write a Matlab function to generate

x(n)=step(n-no), n1<=n<=n2

[x,n]=stepseq(3,2,6)

Results:

n =2 3 4 5 6

x = 0 1 1 1 12 2.5 3 3.5 4 4.5 5 5.5 6

0

0.2

0.4

0.6

0.8

1

Page 9: LAB 3 Discrete Time Signals Part One

9

3. Real-valued exponential sequence

Page 10: LAB 3 Discrete Time Signals Part One

10

n=[-10:10];

x1=(0.7).^n;

subplot(221),stem(n,x1),title('0<a<1')

x2=(1.4).^n;

subplot(222),stem(n,x2),title('a>1')

x3=(-0.7).^n;

subplot(223),stem(n,x3),title('-1<a<0')

x4=(-1.4).^n;

subplot(224),stem(n,x4),title('-1>a')

Page 11: LAB 3 Discrete Time Signals Part One

11

-10 -5 0 5 100

10

20

30

400<a<1

-10 -5 0 5 100

10

20

30a>1

-10 -5 0 5 10-40

-20

0

20

40

-1<a<0

-10 -5 0 5 10-40

-20

0

20

40

-1>a

Page 12: LAB 3 Discrete Time Signals Part One

12

4. Complex-valued exponential sequence

cos sinje j

cos sin 1je j

Euler's equation:

Page 13: LAB 3 Discrete Time Signals Part One

13

-5 0 5-5

0

5

Quadra

ture

In-Phase

Scatter plot

>> scatterplot(3+j*5)

Page 14: LAB 3 Discrete Time Signals Part One

14

1n nj n je e

n=-10:10;

y=exp((j*pi)*n);

stem(n,y)

scatterplot(y)

-10 -5 0 5 10-1

-0.5

0

0.5

1

-1 0 1-1

0

1

Quadra

ture

In-Phase

Scatter plot

stem(n,y)scatterplot(y)

Page 15: LAB 3 Discrete Time Signals Part One

15

Page 16: LAB 3 Discrete Time Signals Part One

16

What is the mathematical definition of a complex sinusoid?

The complex sinusoid can be thought of as a two-dimensional sinusoid. One dimension

contains a cosine wave, and the perpendicular dimension contains a sinewave. Here is

a picture of a complex sinusoid with the third dimension being time:

Page 17: LAB 3 Discrete Time Signals Part One

17-1 0 1

-1

-0.5

0

0.5

1

Quadra

ture

In-Phase

Scatter plot

n=-10:10;

y=exp((j*pi/3)*n);

scatterplot(y)

/3n

j n je e

-1 -0.5 0 0.5 1-1

-0.5

0

0.5

1

Page 18: LAB 3 Discrete Time Signals Part One

18

-1 -0.5 0 0.5 1-1

-0.5

0

0.5

1

theta=linspace(0,2*pi,100);

y=exp(j*theta);

scatterplot(y)

Page 19: LAB 3 Discrete Time Signals Part One

>> help linspace

LINSPACE Linearly spaced vector.

LINSPACE(X1, X2)

generates a row vector of 100 linearly

equally spaced points between X1 and X2.

LINSPACE(X1, X2, N)

generates N points between X1 and X2.

19

Page 20: LAB 3 Discrete Time Signals Part One

>> L=linspace(0,10,5)

L =0 2.5000 5.0000 7.5000 10.0000

>> L=linspace(3,9,6)

L= 3.0000 4.2000 5.4000 6.6000 7.8000 9.0000

10 02.5

Number of elements 1 5 1

end value start valueStep

9 31.2

6 1Step

Start end points

Page 21: LAB 3 Discrete Time Signals Part One

>> L=linspace(0,10,5)

L =0 2.5000 5.0000 7.5000 10.0000

>> L=0:2.5:10

L =0 2.5000 5.0000 7.5000 10.0000

21

Page 22: LAB 3 Discrete Time Signals Part One

22

histogram

0 1 2 3 4 5 6 7 8 9 1011121314150

0.5

1

1.5

2

2.5

3

>> A=[15 15 6 8 6 6 1];

>> hist(A)

3

Page 23: LAB 3 Discrete Time Signals Part One

>> help randn

RANDN Normally distributed random numbers.

R = RANDN(N) returns an N-by-N matrix containingpseudo-random values drawn from a normal distributionwith mean zero and standard deviation one

>> randn(1,4)

ans =1.9574 0.5045 1.8645 -0.3398

23

randn Gaussian distribution

6. Random sequence (rand ,randn)

Page 24: LAB 3 Discrete Time Signals Part One

24

-3 -2 -1 0 1 2 3 40

10

20

30

40

50

0 20 40 60 80 100 120 140 160 180 200-4

-2

0

2

4

>> randn(1,200)

x=randn(1,200)

figure(1), plot(x)

figure(2), hist(x)

Page 25: LAB 3 Discrete Time Signals Part One

25

>> rand(1,5)

ans = 0.8147 0.9058 0.1270 0.9134

Page 26: LAB 3 Discrete Time Signals Part One

26

▪ OPERATIONS ON SEQUENCES

1. Signal addition:

Build a Matlab function that takes two sequences with its indices

and return the sum of them with the index of the result

sequence.

Before build this function follow the helpful notes next slides

Page 27: LAB 3 Discrete Time Signals Part One

27

For example find: x1+x2

Page 28: LAB 3 Discrete Time Signals Part One

28

%% means find x that is not equal to zero

Page 29: LAB 3 Discrete Time Signals Part One

29

Page 30: LAB 3 Discrete Time Signals Part One

30

>> A=[1 2 3;4 5 6;7 8 9]

A = 1 2 3

4 5 6

7 8 9

>> min(A)

ans =1 2 3

>> min(min(A))

ans = 1

Page 31: LAB 3 Discrete Time Signals Part One

31

>> a=[0 0 0 0 0 0 0 0 0 0 ];

>> b=[10 20 30 40 50];

>> y([6 7 8 9 10])=b

y =0 0 0 0 0 10 20 30 40 50

Page 32: LAB 3 Discrete Time Signals Part One

32

n1=[0,1,2,3,4];

n2=[-2,-1,0,1,2];

n=min( min(n1),min(n2)):max( max(n1),max(n2));

n = -2 -1 0 1 2 3 4>> A=n>=min(n1) % n>=0 {0,0,1,1,1,1,1}

>> B=n<=max(n1) % n<=4 {1,1,1,1,1,1,1}

>> A&B

>> z=find(A&B==1) % index

A = 0 0 1 1 1 1 1

B = 1 1 1 1 1 1 1

A&B = 0 0 1 1 1 1 1

z = 3 4 5 6 7

Page 33: LAB 3 Discrete Time Signals Part One

33

Page 34: LAB 3 Discrete Time Signals Part One

34

Page 35: LAB 3 Discrete Time Signals Part One

35

========================================================

% Function adds two discrete time sequences

y(n)=x1(n)+x2(n)

function [y,n]=sigadd(x1,n1,x2,n2)

n=min(min(n1),min(n2)):max(max(n1),max(n2));

y1=zeros(1,length(n));

y2=y1;

y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;

y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;

y=y1+y2;

end

========================================================

Page 36: LAB 3 Discrete Time Signals Part One

36

using sidadd function x1=[0,2,4,6,8];

n1=[0,1,2,3,4];

x2=[1,3,5,7,9];

n2=[-2,-1,0,1,2];

[y,n]=sigadd(x1,n1,x2,n2)

y = 1 3 5 9 13 6 8

n =-2 -1 0 1 2 3 4

Page 37: LAB 3 Discrete Time Signals Part One

37

2. Signal multiplication :

Page 38: LAB 3 Discrete Time Signals Part One

38

3. Signal scaling:

In this operation each sample is multiplied by a scalar α.

Page 39: LAB 3 Discrete Time Signals Part One

39

4. Signal shifting:

x=[1,1,1,1];

n=[1,2,3,4];

n2=n+6;

n3=n-6;

stem(n,x),hold on

stem(n2,x),hold on

stem(n3,x)

For example:

Page 40: LAB 3 Discrete Time Signals Part One

40

-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 120

0.5

1

1.5

2

Page 41: LAB 3 Discrete Time Signals Part One

41

=============================================

% Function does signal shifting y(n)=x(n-no)

function [y,n]=sigshift(x,n,no)

n=n+no;

y=x;

end

=============================================

% x=[1,1,1,1];

% n=[1,2,3,4];

%[y1,n2]=sigshift(x,n,6)

%[y2,n3]=sigshift(x,n,-6)

Page 42: LAB 3 Discrete Time Signals Part One

42

5. Signal Folding:

each sample of x(n) is flipped around n=0

Page 43: LAB 3 Discrete Time Signals Part One

43

x=[1,2,3];

n=[2,3,4];

y=fliplr(x);

n2=-fliplr(n);

% [y,n2]=sigfold(x,n)

stem(n,x),hold on,stem(n2,y)

For example:

Page 44: LAB 3 Discrete Time Signals Part One

44

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

1

2

3

4

Page 45: LAB 3 Discrete Time Signals Part One

45

==========================================

% Function does signal folding y(n)=x(-n)

function [y,n]=sigfold(x,n)

y=fliplr(x);

n=-fliplr(n);

end

==========================================

Page 46: LAB 3 Discrete Time Signals Part One

46

6. Sample summation :

Page 47: LAB 3 Discrete Time Signals Part One

47

7. Sample product:

Page 48: LAB 3 Discrete Time Signals Part One

48

Page 49: LAB 3 Discrete Time Signals Part One

LOGO

49