Sunteți pe pagina 1din 14

LAB NO 2

Basic Operations on Discrete-Time


Sequences
Instructor: Fahd Ali Shifa
OBJECTIVES

To learn to generate sequences in MATLAB


To develop a crude understanding of the
sampling phenomena
To learn the basics of plotting in MATLAB
To learn the use of the playback commands of
MATLAB
REVIEW Energy and Power
Energy (Aperiodic) signals
Energy is the ability of a body to do useful work

For a signal to be an energy signal Ek <


Power (Periodic) signals
Power is the rate of transfer of energy to and/or from a body

For a signal to be a power signal Pav <


Brain teaser: Why can periodic signals NOT be energy signals?
REVIEW Unit Step and Unit Impulse
Unit step (Definition?)
1 when n > 0
0 when n < 0
Unit impulse (Definition?)
1 when n = 0
0 elsewhere
When delayed by an integer n0?
Well see the answer to it in a while
REVIEW Real and Complex Exponentials
Real exponential
No imaginary components
x[n] = an
Complex exponential
x[n] = a(a+bi)n
Significance: Every sequence can be expressed as a sum of
infinite complex exponentials
Fourier series
Analogy: An exponential is to a periodic signal what an atom is to any
substance
Assignment task: Read the Wikipedia article on Fourier series and
answer what would happen if the no. of complex exponentials
were finite?
Hint: The answer is contained in the article
REVIEW Delaying and Advancing
Consider the following signal
x1[n] = x[n no]
If the integer no is +ve then the signal x1[n] is the delayed
version of x[n]
If the integer no is ve then the signal x1[n] is the advanced
version of x[n]
In general
Signal delayed n0 indices then (for x[n]):
Moves by n0 indices to the right if n0 is positive
Moves by n0 indices to the left if n0 is negative
Signal delayed n0 indices then (for x[-n]):
Moves by n0 indices to the left if n0 is positive
Moves by n0 indices to the right if n0 is negative
Sampling A Crude Definition
Much like blinking
Example given, a truck is coming towards you (Just an
example, try to grasp the concepts behind it rather than
the example itself)
1. At a slow pace
If your eyes are blinking at a normal pace, even then you are able to
perceive it
2. At a relatively higher speed
You may be able to perceive it even now at normal blinking pace
3. At a very high speed
If your eyes are still blinking at a normal pace, lets just say you will
perceive the reality when it hits you
Its all about perception
A digital system needs to perceive/visualize the
variable(s) being passed to it
The need to sample a view of the variable being passed to it
Nyquists Criteria A Crude Definition
The sampling frequency should be greater
than twice the maximum frequency in the
signal
Digital signals have many spectral components
inside them
REVIEW - Prescribed Format for Signal
Generation
Example: Generate a 5kHz sine wave in MATLAB
n = 0:499; % Use n NOT t; n is integer
fm = 5e3; % Maximum signal frequency
SR = 3; % Sampling ratio
fs = SR*fm; % fs > 2fm (Nyquist criterion)
y = sin(2*pi*(fm/fs)*n);
subplot(2,1,1); plot(y);
subplot(2,1,2); stem(y);
MATLAB Playback Commands
sound
Input arguments include the array to be passed to the
speakers
By default, the array is passed to the speakers at a
sampling rate of 8192
You can define the rate yourself in the input arguments
For more help, type doc sound or help sound in
command window of MATLAB
soundsc
Scales the values in the array to be passed to speakers for
playback
Values passed lie in the range from -1.0 to 1.0
Scaling done to ensure that the array is played with
maximum possible amplitude or volume without any sort
of clipping in the sound
Tasks
1. Write a function which takes frequency fm, sampling ratio SR and the no. of
samples N as the input arguments and generates a sinusoidal sequence. Here, SR is
the sampling ratio defined as the ratio of fs to fm. Keep in mind that SR > 2.Use
the formula mentioned in the prescribed format for signal generation?
Hint: n=0:N-1; OR n=1:N;
2. Write a function which takes a sequence x[n] as input and calculates the energy and
average power of the sequence. Use the function in previous task to pass a sinusoid
as input
3. Write a function which takes the limits of n-axis as the input arguments and
generates
1. A unit-step sequence
2. A unit-impulse sequence
Plot the resultant sequences. Properly label and format the plots
4. Use the function in task 1 to generate a sine wave with following specifications:
fm = 5 kHz.
Sampling Ratio = SR = 3.
No. of samples = N = 60000.
Pass this sound wave to the output at a certain fs (< 30 kHz). Answer the following
questions:
1. Calculate the time for which the above array should play at speakers?
2. Use a stop watch to measure the actual time for which the array plays at speakers.
Comment on your observations in your reports.
Design Problem
Write a code to generate the following output.
You must use a sine or cosine wave in your code.
You must use the functions you have created in this
lab.
y(n) = 0.866 when n=1
y(n) = zero otherwise
Hint: You may have to employ time shifting
properties of signals in this task.
Convert this code into function
Call the function and its corresponding parameter
file in the main file.
CONTACT INFO
Working days
Monday to Friday
Location(s)
Office no 129, 1st floor, EE-dept
Contact (Email)
fahd.shifa@comsats.edu.pk

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