Dawdaw

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Lab Assistant: Neyre Tekbyk EEE420 Lab Handout

LAB # 2 HANDOUT
Signals can be classified as; analog signals, x(t), where t represents time and
discrete signals, x(n), where n represents integer and sample position.

1. DISCRETE TIME SIGNALS

x(n)= {, x(-1), x(0), x(1),}


Representation of x(n) would require two vectors : x and n

Ex:
x(n)= {2,1,-1,0,1,4,3,7}

In matlab
>> n=[-3,-2,-1,0,1,2,3,4];
>> x=[2,1,-1,0,1,4,3,7];
>> stem(n,x)

Note: When the sequence begins at n=0, we do not need to use n vector.

2. TYPES OF SEQUENCES

2.1 Unit Sample Sequence

1 , n=0 and 1 , n=n0


(n) = , otherwise (n n0) = , otherwise
0 shifted by n0 0

In matlab (M-file)
function [x,n]=impseq(n0,n1,n2)
% Generates x(n)= delta(n-n0); n1<=n<=n2
%--------------
%[x,n]=impseq(n0,n1,n2)
n=[n1:n2]; x=[(n-n0)==0];

Ex:
% n= -3 -2 -1 0 1 2 3 4 5
>> impseq(3,-3,5)
ans =
0 0 0 0 0 0 1 0 0
% n= -6 -5 -4 -3 -2 -1 0 1 2
>> impseq(-1,-6,2)
ans =
0 0 0 0 0 1 0 0 0

1
Lab Assistant: Neyre Tekbyk EEE420 Lab Handout

2.2 Unit Step Sequence

1 , n 0 and 1 , n0
u (n) = ,n<0 u (n n0) = ,n<0
0 shifted by n0
0

In matlab (M-file)
function [x,n]=stepseq(n0,n1,n2)
% Generates x(n)= u(n-n0); n1<=n<=n2
%[x,n]=stepseq(n0,n1,n2)
n=[n1:n2]; x=[(n-n0)>=0];

Ex:
% n= -4 -3 -2 -1 0 1 2 3 4
>> stepseq(2,-4,4)
ans =
0 0 0 0 0 0 1 1 1
% n= -2 -1 0 1 2 3
>> stepseq(-1,-2,3)
ans =
0 1 1 1 1 1

2.3 Real-Valued Exponential Sequence

x(n)=a^n real exponential function

Ex:
x(n)=(0.9)^n for 0 <=n <= 10

In matlab
>> n=[0:10];
>> x=(0.9).^n;
>> stem(n,x)

2.4 Complex-Valued Exponential Sequence

x(n)= exp(a-jw0)n

Ex:
x(n)=exp[(2+j3)n] for 0 <=n <= 10

In matlab
>> n=[0:10];
>> x=exp((2+3*j).*n);
>> stem(n,x)

2
Lab Assistant: Neyre Tekbyk EEE420 Lab Handout

2.5 Sinusoidal Sequence

x(n)=Acos(w0n+)

Ex:
x(n)=3cos(0.1n+/3)+2sin(0.5n) for 0 <=n <= 10

In matlab
>>n=[0:10];
>>x=3*cos(0.1*pi*n+pi/3)+2*sin(0.5*pi*n);
>>stem(n,x)

2.6 Random Sequence

rand(1,N) generates a length N random sequence whose elements are


uniformly distributed between [0,1].
randn(1,N) generates a length N Gaussian random sequence with mean 0
and variance 1.

2.7 Periodic Sequence

x(n) is periodic if x(n)=x(n+N)


>> xtilde=[x,x,,x];

In matlab
>> x=[6 9 0]
>> xtilde=x *ones(1,4);
>> xtilde=xtilde(:);
>> xtilde=xtilde ;

3. OPERATIONS ON SEQUENCES

3.1 Signal Addition

x1(n)+x2(n)

Ex:
The lengths of y1 and y2 are same.
>> n=[1 2 3 4 5];
>> y1=[1 0 1 0 1];
>> y2=[0 2 2 1 0];
>> z=y1+y2
z= 1 2 3 1 1

3
Lab Assistant: Neyre Tekbyk EEE420 Lab Handout

However, if the sequences are of unequal lengths, or if the sample positions are
different for equal-length sequences, then we can not directly use the operator
(+). We have to use sigadd function.

M-file
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;

Ex:
>> x1=[2 2 2 2];
>> n1=[2 3 4 5];
>> x2=[2 2 2 2];
>> n2=[1 2 3 4];
>> sigadd(x1,n1,x2,n2)
ans= 2 4 4 4 2

3.2 Signal Multiplication

x1(n)*x2(n) Only change (+) to (.*) and sigadd to sigmult.

Ex:
>> x1=[2 2 2 2];
>> n1=[2 3 4 5];
>> x2=[2 2 2 2];
>> n2=[1 2 3 4];
>> sigmult(x1,n1,x2,n2)
ans= 0 4 4 4 0

3.3 Scaling :
Each example is multiplied by a scalar a. ( a*x(n) )

Ex:
>> A=[3 5 8]
>>B=3*A

3.4 Shifting

y(n)=x(n-k) m=n-k and n=m+k

M-file
function [y,n]=sigshift(x,m,n0)
n=m+n0; y=x;

4
Lab Assistant: Neyre Tekbyk EEE420 Lab Handout

Ex:
>> x=[2 0 1 3 5];
>> n=[-3 -2 -1 0 1];
>>[y1,n1]=sigshift(x,n,4)
y1=____
n1=____

Ex:
>> x=[5 4 8];
>> n=1:3;
>>[y,n1]=sigshift(x,n,-2)
y=____
n1=____

3.5 Folding

y(n)=x(-n)

M-file
function [y,n]=sigfold(x,n)
y=fliplr(x); n=-fliplr(n);

Ex:
>> a=[1 2 3 4];
>> n=2:5;
>>[y,n1]=sigfold(a,n)
y=____
n1=____

Ex:
>> c=[1 2 1 6 1 0 1];
>> n=-3:3;
>>[y,n1]=sigfold(c,n)
y=____
n1=____

3.6 Sample Summation

It adds all sample values of x(n) between n1 and n2.


n2
x(n)= x(n1)++ x(n2)
n=n1

In matlab
>> sum(x(n1:n2))

5
Lab Assistant: Neyre Tekbyk EEE420 Lab Handout

Ex:
>> x=[1 1 4 2 6 3];
>> sum(x(2:4))
ans=__

3.7 Sample Product

It multiplies all sample values of x(n) between n1 and n2.


n2
x(n)= x(n1)** x(n2)
n=n1

In matlab
>> prod(x(n1:n2))

Ex:
>> x=[8 9 7 3];
>> sum(x(1:4))
ans=__

3.8 Signal Energy

The energy of a sequence



x= x(n)x*(n)= |x(n)|
- -
In matlab
>> Ex= sum(x.*conj(x)) % x is a sequence
>> Ex=sum(abs(x).^2)
Try for x=[2 4 5]
Both of the answers will be same

3.9 Signal Power


The average power of a periodic sequence
N-1
Px= (1/N)* |x(n)|
0

In matlab
>> Px=sum(abs(x).^2)/N % x is a sequence

Ex:
x=[9 6 4 7] Find Px for N=2and N=3.

>> x=[9 6 4 7]
>> Px=sum(abs(x).^2)/2
>> Px=sum(abs(x).^2)/3

You might also like