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

crude

understanding

of

a

sampling phenomena

the

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 E k <

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 P av <

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 ‘n 0 ’?

We’ll see the answer to it in a while

REVIEW Real and Complex Exponentials

Real exponential

No imaginary components

x[n] = a n

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

Consider the following signal x 1 [n] = x[n n o ]

If the integer n o is +ve then the signal x 1 [n] is the delayed version of x[n]

If the integer n o is ve then the signal x 1 [n] is the advanced version of x[n]

In general

Signal delayed n 0 indices then (for x[n]):

Moves by n 0 indices to the right if n 0 is positive

Moves by n 0 indices to the left if n 0 is negative

Signal delayed n 0 indices then (for x[-n]):

Moves by n 0 indices to the left if n 0 is positive

Moves by n 0 indices to the right if n 0 is negative

Sampling A Crude Definition

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

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

Nyquist’s Criteria A Crude Definition

The

greater

than twice the maximum frequency in the

signal

Digital signals have many spectral components

sampling

frequency

should

be

inside them

REVIEW - Prescribed Format for Signal

Generation

Example: Generate a 5kHz sine wave in MATLAB

n = 0:499; fm = 5e3; SR = 3; fs = SR*fm;

% Use ‘n’ NOT ‘t’; n is integer % Maximum signal frequency % Sampling ratio % 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

sampling rate of 8192

passed

to

the

speakers

at

a

You can define the rate yourself in the input arguments

For

more

help,

type

‘doc sound’ or ‘help

command window of MATLAB

soundsc

sound’ in

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

 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 “f s ” to “f m ”. 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:

f m = 5 kHz.

Sampling Ratio = SR = 3.

No. of samples = N = 60000.

Pass this sound wave to the output at a certain f s (< 30 kHz). Answer the following questions:

1. Calculate the time for which the above array should play at speakers?

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) 