expt01 scilab

12
Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 1 Discrete-Time Signals in the Time-Domain Experiment 01 Background Digital signal processing is concerned with the processing of a discrete-time signal, called input signal, to develop another discrete signal, called the output signal, with more desirable properties. This discrete signal is initially inputted as analogue signal which is obtained from the real world. In specific 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 specific input signals. Objectives 1. To learn how to generate in time-domain some basic discrete-time signals in SCILAB and perform elementary operations on them 2. To learn the application of some basic SCILAB commands and how to apply them in simple digital signal processing algorithms. Getting Started The discrete provided with this book contains all the SCILAB programs and the partially written reports for the PC. In particular, it includes the latest version of the SCILAB SCE-files of the first 5 exercises in folders grouped by chapters and report documents written in Word in folders grouped by chapters. Installation Instructions for a PC 1. Insert the CD provided in the package 2. Open the Windows Explorer or other directory tool and click on CD drive 3. Look for the scilab-5.1.1 icon and click on it 4. Copy other files provided Theories T1.1 A discrete-time signal is represented as a sequence of numbers, called samples. A sample value of a typical discrete-time signal or sequence xn is denoted as xn with the argument n being an integer in the range -and +. For convenience, the sequence xn is often denoted without the curly brackets. T1.2 The discrete-time signal may be a finite length or an infinite length sequence. A finite length (also called finite duration or finite extent) sequence is defined only for a finite time interval: 1 2 N n N where 1 N and 2 N with 1 2 N N . The length or duration of the finite length sequence is 2 1 1 N N N .

Upload: harlz-ranch

Post on 18-Apr-2015

421 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 1

Discrete-Time Signals in the Time-DomainExperiment 01

Background

Digital signal processing is concerned with the processing of a discrete-time signal, called input signal, to develop another discrete signal, called the output signal, with more desirable properties. This discrete signal is initially inputted as analogue signal which is obtained from the real world. In specific 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 specific input signals.

Objectives

1. To learn how to generate in time-domain some basic discrete-time signals in SCILAB and perform elementary operations on them

2. To learn the application of some basic SCILAB commands and how to apply them in simple digital signal processing algorithms.

Getting Started

The discrete provided with this book contains all the SCILAB programs and the partially written reports for the PC. In particular, it includes the latest version of the SCILAB SCE-files of the first 5 exercises in folders grouped by chapters and report documents written in Word in folders grouped by chapters.

Installation Instructions for a PC

1. Insert the CD provided in the package2. Open the Windows Explorer or other directory tool and click on CD drive3. Look for the scilab-5.1.1 icon and click on it4. Copy other files provided

Theories

T1.1 A discrete-time 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 +∞. For convenience, the sequence x n is often denoted without the curly brackets.

T1.2 The discrete-time signal may be a finite length or an infinite length sequence. A finite length (also called finite duration or finite extent) sequence is defined only for a finite time interval: 1 2N n N where

1N and 2N with 1 2N N . The length or duration of the finite length sequence

is 2 1 1N N N .

Page 2: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 2

T1.3 A sequence x n

= x n kN

for all n , is called a periodic sequence with a period N where N is a

positive integer and k is any integer.

T1.4 The energy of a sequence x n is defined by 2

n

x n

, and the energy of a sequence over a

finite interval 1 2K n K is defined by 2K

n K

x n

.

T1.5 The average power of an aperiodic sequence x n is defined by

1lim

2 1av KK K

= 21lim

2 1

K

Kn K

x nK

The average power of a periodic sequence x n

with a period N is given by 21

0

1 N

avn

x nN

.

T1.6 The unit sample sequence, often called the discrete-time impulse or the unit impulse, denoted by

n is defined by 1, 0,

0, 0.

for nn

for n

The unit step sequence, denoted by n , is defined by 1, 0,

0, 0.

for nn

for n

T1.7 The exponential sequence is given by nx n A , where A and ∝ are real or complex numbers. By

expressing 0 0je and jA A e . Or, x n can be rewritten as

0 0n j nx n A e = 00 0cos sinnA e n j n .

T1.8 The real sinusoidal sequence with a constant amplitude is of the form 0cosx n A n , where

A , 0 , and are real numbers. The parameters A , 0 , and are called as amplitude, angular frequency,

and the initial phase of the sinusoidal sequence x n . 0 0 / 2f is the frequency.

T1.9 The complex exponential sequence with 0 0 and the sinusoidal sequence are periodic sequences if

0N is an integer multiple of 2 , that is, 0 2N r , where N is a positive integer and r is any integer.

The smallest possible N satisfying this condition is the period of sequence.

T1.10 The product of two sequences x n and h n of length N yields a sequence y n , also of length N ,

as given by y n x n h n .

The addition of two sequences x n and h n of length N yields a sequence y n , also of length N , as given

by y n x n h n .

Page 3: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 3

The multiplication of a sequence x n of length N by a scalar A results in a sequence y n of length N , as

given by y n A x n .

The time-reversal of a sequence x n with infinite length results in a sequence y n of infinite length as

defined by y n x n

The delay of a sequence x n with infinite length by a positive integer M results in a sequence y n of

infinite length given by y n x n M .

If M is a negative integer, the operation indicated results in an advance of the sequence x n .

A sequence x n of length N can be appended by another sequence g n of length M resulting in a longer

sequence y n of length N and M given by ,y n x n g n .

SCILAB Commands Used

The SCILAB commands you will encounter in this experiment are listed below. You may refer to Appendix A for the complete SCILAB commands.

Operators and Special Characters

: . + - * / ; %

Elementary Matrices and Matrix Manipulation

i ones pi rand rand randn zeros

Elementary Functions

cos exp imag real

Data Analysis

sum

Two-Dimensional Graphics

axis grid legend plot stairs stem title xlabel label

General Purpose Graphics Functions

clf subplot

Signal Processing Toolbox

Page 4: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 4

sawtooth square

Introduction to SCILAB

The purpose of this section is to familiarize each student with the basic SCILAB commands for signal generation and for plotting the generated signal. SCILAB is an open source application software and has been designed to operate on data stored as vectors or matrices. For our purposes, sequences will be stored as vectors. Therefore, all signals are limited to being causal and of finite length. The steps to follow to execute the programs listed in this laboratory guide are based on the Windows platform; Linux and Macintosh may have some unique steps to follow. Also the software used in the development of this manual is SCILAB-5.1.1 for windows x86 platform. You can visit www.scilab.org to download installers for other platforms.

Installing SCILAB/SCICOS

1. Locate scilab-5.1.1.exe in the CD provided with the DSP kit 1.0.2. Copy the scilab-5.1.1.exe file to your desired directory in your Hard Drive. Preferably, use C:\SCILAB as your

main directory.3. Click on the scilab-5.1.exe icon to install the software. You can also click on the scilab-5.1.1.exe icon

located at the DSP Kit 1.0 CD companion to install the software.4. Create a workspace in your Hard drive (e.g. C:\SCILAB\Work\). You will use the workspace to save your

working files.

Note: When you installed SCILAB (version 5), SCICOS was installed too. SCICOS is one of the most interesting packages integrated with SCILAB. SCICOS will be discussed and used extensively starting experiment 7. At this point, only SCILAB commands and its environment will be discussed and used in the experiments.

Starting up SCILAB

1. Though the SCILAB icon was automatically created when you installed scilab-5.1.1.exe but make sure you have it in your Windows desktop or else create an icon by locating WScilex.exe in your Hard Drive (C:\SCILAB\bin\WScilex.exe). You can also locate scilab-5.1.1 under scilab-5.1.1 group menu to run SCILAB. For Windows Vista, you can see the figure as shown below.

2. The SCILAB console will be displayed as shown below after clicking the SCILAB icon . Under the prompt in the Command Window, you can write your codes. However, this would take time and may potentially defeat the purpose of learning Digital Signal Processing. Anyway, you can try using it once you already learned to use the SCILAB editor.

Page 5: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 5

3. To fire up the SCILAB editor, click Applications > Editor as shown below. You can also opt to use notepad and other editing tools to encode your SCILAB codes and compile and test it with your SCILAB software.

4. The SCILAB editor has the same user-friendliness as the other editing tools. Just click on the Help menu bar to access help for all available SCILAB commands.

Exercises

Generation of Sequences

In this experiment, five (5) exercises will be performed to learn on how o use SCILAB and, at the same time, know how to generate signals and understand some characteristics of discrete-time signals in the time-domain.

Page 6: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 6

Exercise 1.1 Unit Sample and Unit Step Sequences

Two basic discrete-time sequences are the unit sample sequence and the unit step sequence as shown in T1.6. A unit sample sequence n of length N can be generated using the SCILAB command.

Figure 1 Generation of Unit Sample Sequence

Procedures and Results

P1.1 Encode the SCILAB codes shown in Figure 1 and save as e1_1.sci.P1.2 Click on Execute > Load into Scilab or CTRL-I to execute the Unit Sample Sequence n and display it.

Figure 2 Running a SCILAB Program

You must obtain a graph as shown below. If you did not get the graph shown, review your codes, make some modifications, and run again.

Page 7: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 7

Figure 3 Unit Sample Sequence Graph

P1.3 Modify Program e1_1 to generate a delayed unit sample sequence ud n with a delay of 4 samples.

Run the modified program and display the sequence generated. Draw the resulting graph below.P1.4 Modifiy Program e1_1 to generate a unit step sequence s n . Run the modified program and display

the sequence generated. Draw the resulting graph below.P1.5 Modify Program e1_1 to generate a delayed unit step sequence ud n with an advance of 6 samples.

Run the modified program and display the sequence generated. Draw the resulting graph below.

Exercise 1.2 Exponential Signals

Another basic discrete-time sequence is the exponential sequence. Such as sequence can be generated using the SCILAB operators .^ and exp.

Program e1_2 given below can be employed to generate a complex-valued exponential sequence.

Page 8: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 8

Program e1_3 given below can be employed to generate a real-valued exponential sequence.

Procedures and Results

P1.6 Encode and run Program e1_2 and generate the complex-valued exponential sequenceP1.7 Which parameter controls the rate of growth or decay of this sequence? Which parameter controls the amplitude of this sequence?P1.8 What will happen if the parameter c is changed to 1/12 / 6 *pi i ?

P1.9 What are the purposes of the operators real and imag?P1.10 What is the purpose of the command subplot?P1.11 Encode and run Program e1_3 and generate the real-valued exponential sequence.P1.12 Which parameter controls the rate of growth or decay of this sequence? Which parameter controls the amplitude of this sequence?P1.13 What is the difference between the arithmetic operators ^ and .^?P1.14 What will happen if the parameter a is less than 1? Run Program e1_3 again with the parameter a changed to 0.9 and the parameter K changed to 20.

Page 9: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 9

P1.15 What is the length of this sequence and how can it be changed?P1.16 You can use the SCILAB command sum(s.*s) to compute the energy of a real sequence s n stored as a

vector s . Evaluate the energy of the teal-valued exponential sequences x n generated in P1.11 and P1.14.

Exercise 1.3 Sinusoidal Sequences

Another very useful class of discrete-time signals is the real sinusoidal sequence of the form

0cosx n A n . Such sinusoidal sequences can be generated in SCILAB using the trigonometric

operators cos andsin .

Program e1_4 is a simple example that generates a sinusoidal signal.

Procedures and Results

P1.17 Encode and run e1_4 to generate the sinusoidal sequence and display it.P1.18 What is the frequency of this sequence and how can it be changed? Which parameter controls the phase of this sequence? Which parameter controls the amplitude of this sequence? What is the period of this sequence?P1.19 What is the length of this sequence and how can it be changed?P1.20 Compute the average power of the generated sinusoidal sequence.P1.21 What are the purposes of the grid commands?P1.22 Modify program e1_4 to generate a sinusoidal sequence of frequency 1.1 and display it. Compare this new sequence with the one generated in P1.17. Give comment on your results.P1.23 Modify the above program to 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?P1.24 Replace the plot2d3() command in e1_4 with the plot() command and run the program again. What is the difference between the new plot and the one generated in P1.17?P1.25 Replace the plot2d3() command in program e1_4 with the stairs() command and run the program again. What is the difference between the new plot and those generated in P1.17 and P1.24?

Exercise 1.4 Random Signals

Page 10: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 10

A random signal of length N with samples uniformly distributed in the interval 0,1 can be generated by using

SCILAB command (1, );x rand N Likewise, a random signal x n of length N with samples normally

distributed with zero mean and unity variance can be generated by using the following SCILAB command (1, );x randn N

P1.26 Write a SCILAB program to generate and display a random signal of length 100 whose elements are uniformly distributed in the interval 2,2 .

P1.27 Write a SCILAB program to generate and display a Gaussian random signal of length 75 whose elements are normally distributed with zero mean and a variance of 3.P1.28 Write a SCILAB program to generate and display five sample sequences of a random sinusoidal signal of length 31.

Simple Operations on Sequences

As indicated earlier, the purpose of digital signal processing is to generate a signal with more desirable properties from one or more given discrete-time signals. The processing algorithm consists of performing a combination of basic operations such as addition, scalar multiplication, time-reversal, delaying, and product operation (see T1.10). We consider here three very simple examples to illustrate the application of such operations.

Exercise 1.5 Signal Smoothing

A common example of a digital signal processing application is the removal of the noise component from a signal corrupted by additive noise. Let s n be the signal corrupted by a random noise d n resulting in the

noisy signal x n s n d n . The objective is to operate on x n to generate a signal y n which is a

reasonable approximation to s n . To this end, a simple approach is to generate an output sample by

averaging a number of input samples around the sample a instant n . For example, a three-point moving

average algorithm is given by 11 1

3y n x n x n x n .

Program e1_5 implements the above algorithm.

Page 11: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 11

Procedures and Results

P1.29 Encode and run program e1_5 and generate all pertinent signals.P1.30 What is the form of the uncorrupted signal s n ? What is the form of the additive noise d n ?

P1.31 Can you use the statement x s d to generate the noise-corrupted signal? If not, why not? P1.32 What are the relations between the signals 1, 2, 3x x and x , and the signal x ? P1.33 What is the purpose of the legend command?

Exercise 1.6 Generation of Complex Signals

More complex signals can be generated by performing the basic operations on simple signals. For example, an amplitude modulated signal can be generated by modulating a high-frequency sinusoidal signal

cosH Hx n n with a low-frequency modulating signal cosL Lx n n . The resulting signal y n is of

the form 1 L Hy n A m x n x n = 1 cos cosL HA m n n , where m , called the modulation

index, is a number chosen to ensure that 1 Lm x n is positive for all n . Program e1_6 can be used to

generate an amplitude modulated signal.

Procedures and Results

Page 12: expt01 scilab

Digital Signal Processing Laboratory Using SCILAB/SCICOS (RU Espina ©2009) Page 12

P1.34 Encode and run program e1_6 and generate the amplitude modulated signal y n for various values of

the frequencies of the carrier signal Hx n and the modulating Lx n , and various values of the modulation

index m .P1.35 What is the difference between the arithmetic operators * and .*?

As the frequency of a sinusoidal signal is the derivative of its phase with respect to time, to generate a swept-frequency sinusoidal signal whose frequency increases linearly with time, the argument of the sinusoidal signal must be a quadratic function of time. Assume that the argument is of the form 2an bn (i.e. the angular frequency us 2an b ). Solve for the values of a andb from the given conditions (minimum angular frequency and maximum angular frequency). Program e1_7 is an example program to generate this kind of signal.

Procedures and Results

P1.36 Encode and run program e1_7 and generate the swept-frequency sinusoidal sequence x n .

P1.37 What are the minimum and maximum frequencies of this signal?P1.38 How can you modify the above program to generate a swept sinusoidal signal with a minimum frequency of 0.1 and a maximum frequency of 0.3?

Questions

Write SCILAB programs to generate the square-wave and the sawtooth wave sequences. Using the created programs, generate and plot the sequences.