You are on page 1of 13

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation Laboratory 2: Cover Sheet Laboratory Objectives:

SSUET

Familiarization with the Common Sequences: Unit Impulse, Unit Step, and Unit Ramp To understand generation of sinusoidal and exponential sequence To understand the periodicity property of Digital frequency (frequency of discrete time sinusoid) To understand Amplitude Modulation using Square Wave with a Cosine Wave

Place a check mark in the Assigned column next to the exercises your instructor has assigned to you. Attach this cover sheet to the front of the packet of materials you submit following the laboratory. Activities Pre-lab Exercises In-lab Exercises Take Home Exercises Any Other Remarks Signature

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation

SSUET

Discrete-Time (DT) Signals Time Domain Representation


A signal can be broadly defined as any dependent quantity that varies as a function of some independent variable (e.g. time, frequency, space, etc.) and both has a physical meaning and has the ability to convey information. Examples Electrical signals (Radio communications signals, audio and video etc). Mechanical signals (vibrations in a structure, earthquakes). Biomedical signals (EEG, lung and heart monitoring, X-ray etc).

A system can be represented mathematically as a transformation between two signal sets, as in x[n] S1 y[n] = T{x[n]}

S2

Depending on the nature of the signals on which the system operates, different basic types of systems may be identied: Analog or continuous-time system: the input and output signals are analog in nature. Discrete-time system: the input and output signals are discrete. Digital system: the input and outputs are digital. Mixed system: a system in which different types of signals (i.e. analog, discrete and/or digital) coexist. Signals can be either continuous-time (CT) or Discrete-time (DT). Signals normally occurring in nature (e.g. speech) are continuous in time as well as amplitude. Such signals are called Analog signals. DT signals have values defined at only discrete instants of time. These time instants need not be equidistant, but in practice, they are usually taken at equally spaced intervals for computational convenience and mathematical tractability. If amplitude of DT signal is also made discrete through process of quantization or rounding off, then this becomes a Digital Signal. Digital Signal Processing (DSP) is concerned with digital processing of signals.

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation

SSUET

An analog signal is denoted as x(t). To emphasize its discrete time nature, a DT signal is denoted as x(n), instead of x(t). A discrete-time signal x(n) is a function of an independent variable n, which is an integer. A discrete-time signal is not defined at instants between two successive samples. A discretetime signal is represented as a sequence of numbers, called samples. A sample value of a typical discrete-time signal or sequence {x[n]} is denoted as x[n] with the argument n being an integer in the range and . The following methods are in use to illustrate the Digital signals

where the bar on top of symbol 1 indicates origin of time (i.e. n = 0) Graphical Representation

Mathematical expression:

Sequence Representation

Tabular Representation

A set of rules that transforms one discrete signal into another is known as an algorithm and this transformation is what we call Discrete-time signal processing or Digital signal processing (DSP).

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation

SSUET

Section A
GENERATION OF UNIT SAMPLE AND UNIT SEPT SIGNALS

Unit Sample Sequence


Unit Sample Sequence is often called the discrete time impulse or the unit impulse. It is denoted by [n] and is defined as

Generation of Unit Sample Sequence


% Generation of a Unit Sample Sequence clf; %Clear current figure window % Generate a vector from -10 to 20 n = -10:20; % Generate the unit sample sequence u = [zeros(1,10) 1 zeros(1,20)]; % Plot the unit sample sequence stem(n,u); xlabel('Time index n');ylabel('Amplitude'); title('Unit Sample Sequence'); axis([-10 20 0 1.2]) s= (n==0); %Following command will also generate unit sample sequence

Generation of Unit Sample Sequence using user input option


% Generation of a Unit Sample Sequence clf; %Clear current figure window % Generate a vector from -10 to 20 n = -10:30; % Generate the unit sample sequence u = [zeros(1,10) .8 zeros(1,30)]; subplot(211); stem(n,u) k=input('Give the number of places to shift the signal right (delay) or left (advance) i.e. +ve or -ve (number has to be within the range of -10 to 30)='); subplot(212);% Plot the unit sample sequence stem(n+k,u); xlabel('Time index n');ylabel('Amplitude'); title('Unit Sample Sequence');

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation


axis([-10 20 0 1.2]) s=(n==0); %Following command will also generate unit sample sequence

SSUET

Matlab Notes: K=input(text) Request user input and it prompt the use in the text string and then waits for input from the keyboard. The value entered by the user is assigned to k. B=zeros(n) return an n-by-n matrix of zeros similarly for ones.

Unit Step Sequence:


The unit step function is one of the most important functions used by mathematicians and engineers in the analysis and design of continuous-time systems. In addition to being useful, step functions also provide a way to turn on and turn off other functions as well, due to its on-off characteristics. Thus, we can think of step functions as mathematical switches. The unit step sequence , denoted by [n], is dened by

Generation of Unit Step Sequence


% Generation of a Unit Step Sequence clf; % Generate a vector from -10 to 20 n = -10:20; % Generate the unit step sequence s = [zeros(1,10) ones(1,21)]; % Plot the unit step sequence stem(n,s); xlabel('Time index n');ylabel('Amplitude'); title('Unit Step Sequence'); axis([-10 20 0 1.2]) u=(n>=0)% Following command will also generate unit step sequence

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation

SSUET

Unit Ramp
The ramp function, denoted by ur( n) is a signal whose amplitude increases proportionally as time increases

Generation of a Unit Ramp


% Generation of a unit ramp signal clf; m=0:1:10; % Generate the unit ramp signal x5=m; stem(m,x5); xlabel('Time index n');ylabel('Amplitude'); legend('ramp') title('Unit Ramp Signal'); u=m % Following command will also generate unit ramp signal

Exponential Sequence
Another basic discrete-time sequence is the exponential sequence. Such a sequence can begenerated using the MATLAB operators .^ and exp. The exponential sequence is a signal whose amplitude exponentially increases or exponentially decreases, depending on the value of a, as time approaches infinity. x(n) = a
n

for n 0

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation Generation of a Real Exponential Sequence
% Generation of a real exponential sequence clf; n = 0:35; a = 1.2; K = 0.2; x = K*a.^n; stem(n,x); xlabel('Time index n');ylabel('Amplitude'); legend('Real Exponential') title('Real Exponential Sequence');

SSUET

when, a = re then the complex exponentia l signal becomes : x(n) = r cos(2f + )n + j sin (2f + )n
n j ( 2f +

such that, xR (n) = r cos(2f + )n


n

xI (n) = r sin (2f + ) n Also,


n

and we can plot them

both seperately

x(n) = A(n) = r

is the magnitude function of the complex signal is the phase function of the complex signal

Ang {x(n)} = (n) = (2f + )n

Generation of a Complex Exponential Sequence


% Generation of a complex exponential sequence clf; c = -(1/12)+(pi/6)*i; K = 2; n = 0:40; x = K*exp(c*n); subplot(2,1,1); stem(n,real(x)); xlabel('Time index n');ylabel('Amplitude'); title('Real part'); subplot(2,1,2); stem(n,imag(x)); xlabel('Time index n');ylabel('Amplitude'); title('Imaginary part');

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation

SSUET

Sinusoidal Sequence
Another very useful class of discrete-time signals is the real sinusoidal sequence. Such sinusoidal sequences can be generated in MATLAB using thetrigonometric operators cos and sin x[n] = A cos[(0 + 2 r )n + ] = A cos(0n + ).

Generation of a Sinusoidal Sequence


% Generation of a sinusoidal sequence n = 0:40; f = 0.1; phase = 0; A = 1.5; arg = 2*pi*f*n - phase; x = A*cos(arg); clf; % Clear old graph stem(n,x); % Plot the generated sequence axis([0 40 -2 2]); grid title('Sinusoidal Sequence'); xlabel('Time index n'); ylabel('Amplitude');

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation

SSUET

Periodicity Property of Digital Frequency (frequency of discrete time sinusoid)


Digital Frequency (that of DT sinusoid) has the range 0 to 2 pi and starts repeating itself after 2 pi. This is different from Analog frequency which is unique from 0 till repetition.

without

n=[0:1023] %1024 samples freq1=pi/4; %frequency x1=2*sin(freq1*n) %sine wave of 1024 samples, pi/4 radian/sample frequency and amplitude of 2 figure(1);stem(n(1:30),x1(1:30)); grid freq2=9*pi/4; %(2*pi+freq1)condition of periodicity x2=2*sin(freq2*n); %sine wave of 1024 samples, 9*pi/4 radian frequency figure(2); subplot(2,1,1); stem(n(1:30),x1(1:30)); ylabel('x1');grid subplot(2,1,2); stem(n(1:30),x2(1:30)); ylabel('x2');grid; %compression of x1 & x2 xlabel('n');

Amplitude Modulation using Square Wave with a Cosine Wave


n=0:199; f=0.1; phase=0; a=1.5; arg=2*pi*f*n+phase; x=a*cos(arg); s1=[zeros(1,20) ones(1,20) zeros(1,20) ones(1,20) zeros(1,20) ones(1,20) zeros(1,20) ones(1,20) zeros(1,20) ones(1,20)]; %'s1' is a square wave sequence of unit amplitude % Another command square can also be used to generate s1 z=x.*s1; %modulation is achieved by point to point multiplication subplot(3,1,1); stem(n,x); grid subplot(3,1,2); stem(n,s1); grid subplot(3,1,3); stem(n,z); grid axis([0 200 -2 2]) xlabel('time index n'); ylabel('Modulated Signal'); title('Amplitude Modulation Sequence');

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation

SSUET

LAB Assignments
1. Practice all the examples in the Lab Manual 2. Generate a delayed unit sample sequence ud[n] with adelay of 11 samples. Run the modied program and display the sequence generated. 3. 4. Generate a delayed unit step sequence sd[n] with an advance of 7 samples. Run the modied program and display the sequence generated. Create a simple m-file that creates a unit sample, unit step, and unit ramp function for a sequence of length 15. Use a for loop to generate the ramp sequence. Then plot them all on the same axes with a stem plot. legend('sample','step','ramp') Add a legend. The final result should be as shown below. Note that the legend command for a stem plot is given as:

5. Generate the complex-valued exponential sequence. Which parameter controls the rate of growth or decay of this sequence? Which parameter controls the amplitude of this sequence? What will happen if the parameter c is changed to (1/12)+(pi/6)*i 6. Generate a sinusoidal sequence of length 50, frequency 0.08, amplitude 2.5, and phase shift 90 degrees and display it. What is the period of this sequence?Now display result using stem, plot and stairs commands. Comment on your results. 7. What is the difference between the arithmetic operators ^and. ^?

8. What are the purposes of these commands: legend real imag

10

DSP Lab # 2 Discrete-Time (DT) Signals Time Domain Representation

SSUET

9. Plot the figure shown below and explain what is happening.

10. Generate amplitude modulation using Square Wave with a Sin Wave and plot your results.

11

You might also like