Sunteți pe pagina 1din 11

DSP lab manual

1.1 Introduction
Digital signal processing is concerned with the processing of a discrete-time
signal, called the input signal, to develop another discrete-time signal, called the output
signal, with more desirable properties. In certain applications, it may be necessary to
extract some key properties of the original signal using specific digital signal processing
algorithms. It is also possible to investigate the properties of a discrete-time system by
observing the output signals for specific input signals. It is thus important to learn first
how to generate in the time domain some basic discrete-time signals in MATLAB and
perform elementary operations on them, which are the main objectives of this first
exercise. A secondary objective is to learn the application of some basic MATLAB
commands and how to apply them in simple digital signal processing problems.


































Expt. No. 1
Aim: - Generation of discrete- time signals

Theory:

Discrete time Signals

Signals are broadly classified into analog and discrete signals. An analog signal will be
denoted by x
a
(t), in which the variable t can represent any physical quantity. A discrete
time signal will be denoted by x(n), in which the variable n is integer-valued and
represents discrete instance in time. Therefore it is also called as discrete time signal,
which is number sequence and will be denoted by one of the following notations:

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

Where the up-arrow indicates the sample at n=0.

In MATLAB a finite- duration sequence is represented by a two row vector.
For example the sequence x(n) ={ 2,1,-1,0,1,4,3,7} can be represented in MATLAB


>> n= [-3,-2,-1, 0, 1, 2, 3, 4];
or by
>>n=-3:1:4;
>>x= [2, 1,-1, 0, 1, 4, 3, 7];
>>stem(n,x)
>> xlabel('Samples')
>> ylabel('Amplitude')
>> title(First Example)




Type of Sequences

1. Unit sample sequence

{ }
1, 0
( ) ....0, 0,1, 0, 0, 0,.....
0, 0
n
n
n

=
= =



The logical relation n==0 is an elegant way of implementing (n).

For example MATLAB code to implement

0
0
0
1,
( )
0,
n n
n n
n n

=
=

=

over the n
1
n
0
n
2
.


% MATLAB code to generate impulse sequence at a specified location n
0
in the range
between n
1
and n
2
.
clc; clear all; close all;
n1=input('Enter the lower range');
n2=input('Enter the upper range');
n0=input('Enter the reference point');
n=[n1:n2];
x=[(n-n0)==0];
stem(n,x);
xlabel('samples n');
ylabel('Amplitude');
title('Unit impulse Sequence');

Write down the above code in m-file and run the MATLAB code and try this.






Write down the function for the above MATLAB Code.

function [x,n]=impseq(n0,n1,n2)
n= [n1:n2];
x= [(n-n0) ==0];

Generate the following signal and plot them

( ) ( 4) 3 5 i n n s s
( ) ( 2) 5 4 ii n n + s s


Solution
( ) ( 4) 3 5 i n n s s

n0=4;
n1=-3;
n2=5;
[x,n]=impseq(n0,n1,n2);
stem(n,x);
xlabel('samples n');
ylabel('Amplitude');
title('Unit impulse Sequence');





( ) ( 2) 5 4 ii n n + s s

n0=-2;
n1=-5;
n2=4;
[x,n]=impseq(n0,n1,n2);
stem(n,x);
xlabel('samples n');
ylabel('Amplitude');
title('Unit impulse Sequence');





2. Unit step sequence

{ }
1, 0
( ) ....0, 0,1,1,1,1,1,1.....
0, 0
n
u n
n
>
= =

<




In MATLAB the function ones(1,N) generates a row vector of N ones. It can used to
generates u(n) over a finite interval.

But an elegant way is to use logical relation n0.

Write a MATLAB Code to implement
0
0
0
1,
( )
0,
n n
u n n
n n
>
=

<

over the n
1
n
0
n
2
.

Write MATLAB code to generate Unit sequence at a specified location n
0
in the range
between n
1
and n
2
using function given below.



function [x,n]=unitseq(n0,n1,n2)
n=[n1:n2]
x=[(n-n0)>=0]


( ) ( 2) 0 10 i u n n s s
( ) ( 3) 5 5 ii u n n + s s


n0=2;
n1=0;
n2=10;
[x,n]=unitseq(n0,n1,n2);
stem(n,x);
xlabel('samples n');
ylabel('Amplitude');
title('Unit Step Sequence');







0 1 2 3 4 5 6 7 8 9 10
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
samples n
A
m
p
l
i
t
u
d
e
Unit Step Sequence
n0=-3;
n1=-5;
n2=5;
[x,n]=unitseq(n0,n1,n2);
stem(n,x);
xlabel('samples n');
ylabel('Amplitude');
title('Unit Step Sequence');





3. Unit ramp sequence
{ }
, 0
( ) ....0, 0,1, 2, 3, 4, 5, 6.....
0, 0
r
n n
u n
n
>
= =

<



In MATLAB the function ones(1,N) generates a row vector of N ones. It can used to
generates u
r
(n) over a finite interval.

But an elegant way is to use logical relation n0.

Write a MATLAB Code to implement
-5 -4 -3 -2 -1 0 1 2 3 4 5
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
samples n
A
m
p
l
i
t
u
d
e
Unit Step Sequence
0
0
0
,
( )
0,
r
n n n
u n n
n n
>
=

<

over the n
1
n
0
n
2
.

Write MATLAB code to generate Unit ramp sequence at a specified location n
0
in the
range between n
1
and n
2
.

function [x,n]=rampseq(N)
n=[0 :1 :N]
x=n ;

Program 3
N=input (Enter the value of N);
[x,n]=rampseq(N);
stem(n,x);
xlabel('samples n');
ylabel('Amplitude');
title('Unit ramp Sequence');


4. Real-valued exponential sequence:

( ) , ;
n
x n a n a = e

In MATLAB an array operator .^ is required to implement a real exponential sequence.
Example,

x(n) = (0.9)
n
, 0n10,
n=[0:10];
x=(0.9).^n;
stem(n,x);
xlabel('samples n');
ylabel('Amplitude');
title('Unit ramp Sequence');


Try for a=-0.9, a=1.2, a=-1.2 and plot all four sequences in single figure window.

5. Complex-valued exponential sequence:


0
( )
( ) ,
j n
x n e n
+
=

Where is called an attenuation and
0
is the frequency in radians. A MATLAB function
exp is used to generate exponential sequence.



Example,
x(n) = exp[(2+j3)n], 0n10,

>> n= [0:10];
>> x=exp ((2+3j)*n);

Write a MATLAB code to generate Complex valued exponential sequence for any value
of and
0
in the range between n
1
and n
2
.

6. Sinusoidal sequence :
0
( ) cos( ), x n n n = +

Where is the phase in radians.

A MATLAB function cos (or sin) is used to generate sinusoidal sequences

Write a MATLAB script to generate sinusoidal sequence

(i) x(n) = 3cos(0.1n+/3) , 0n10

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

(ii) x(n) = 2sin(0.5n), 0n10
>> n1=[0:10];
>>x1=2*sin(0.5*pi*n);
>>stem(n1,x1)




Lab Exercise

Generate and plot each of the following sequences over the interval.

( ) ( ) 2 ( 2) ( 4), 5 5. i x n n n n = + s s

| | ( ) ( ) ( ) ( 10) , 0 20. ii x n n u n u n n = s s


| |
0.3( 10)
( ) ( ) 10 ( 10) ( 20) , 0 20
n
iii x n e u n u n n

= s s

( ) ( ) cos(0.04 ), 0 50. iv x n n n = s s



Viva Questions:-
1. What are the advantages of DSP?
2. Give applications of digital signal processing?
3. What is meant by discrete-time signal?
4. What do you mean by sampling?
5. How will you relate u(n) with (n)?
6. What is the effect of varying the value of a in exponential sequence?

S-ar putea să vă placă și