A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

Similar documents
Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

AN INTRODUCTION TO MATLAB

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

A Guide to Using Some Basic MATLAB Functions

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

Dr Richard Greenaway

Introduction to MATLAB

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

EE3TP4: Signals and Systems Lab 1: Introduction to Matlab Tim Davidson Ext Objective. Report. Introduction to Matlab

Lab 1 Intro to MATLAB and FreeMat

EGR 111 Introduction to MATLAB

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

Matlab Introduction. Scalar Variables and Arithmetic Operators

Colorado State University Department of Mechanical Engineering. MECH Laboratory Exercise #1 Introduction to MATLAB

LAB 1 General MATLAB Information 1

University of Alberta

2.0 MATLAB Fundamentals

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Introduction to MatLab. Introduction to MatLab K. Craig 1

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

How to learn MATLAB? Some predefined variables

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

PART 1 PROGRAMMING WITH MATHLAB

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

To see what directory your work is stored in, and the directory in which Matlab will look for files, type

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

General Information. There are certain MATLAB features you should be aware of before you begin working with MATLAB.

Introduction to MATLAB

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

Experiment 3. Getting Start with Simulink

The value of f(t) at t = 0 is the first element of the vector and is obtained by

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

AMS 27L LAB #2 Winter 2009

Programming in Mathematics. Mili I. Shah

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

Lab 1 Introduction to MATLAB and Scripts

Introduction to MATLAB

Introduction to MATLAB Practical 1

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

ELEMENTARY MATLAB PROGRAMMING

Lab P-1: Introduction to MATLAB. 3. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization.

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB.

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

ARRAY VARIABLES (ROW VECTORS)

Introduction to Engineering gii

Chapter 1 Introduction to MATLAB

Introduction to MATLAB

ECE 3793 Matlab Project 1

MATLAB. Miran H. S. Mohammed. Lecture 1

Getting To Know Matlab

Matlab Programming Introduction 1 2

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division

Introduction to MATLAB

Lab. Manual. Practical Special Topics (Matlab Programming) (EngE416) Prepared By Dr. Emad Saeid

General MATLAB Information 1

MATLAB TUTORIAL WORKSHEET

1-- Pre-Lab The Pre-Lab this first week is short and straightforward. Make sure that you read through the information below prior to coming to lab.

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

Introduction to MATLAB

DSP First. Laboratory Exercise #1. Introduction to MATLAB

Laboratory 1 Octave Tutorial

MATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs).

The Very Basics of the R Interpreter

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:

CS1114 Section 8: The Fourier Transform March 13th, 2013

Teaching Manual Math 2131

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

Finding MATLAB on CAEDM Computers

Math 2250 MATLAB TUTORIAL Fall 2005

Getting Started with MATLAB

GEORGIA INSTITUTE OF TECHNOLOGY. SCHOOL of ELECTRICAL and COMPUTER ENGINEERING. ECE 2026 Summer 2018 Lab #0: Introduction to MATLAB

Matlab Tutorial 1: Working with variables, arrays, and plotting

Getting Started With Mathematica

McTutorial: A MATLAB Tutorial

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Introduction to MATLAB

A very brief Matlab introduction

Introduction to MATLAB LAB 1

Can be put into the matrix form of Ax=b in this way:

George Mason University Signals and Systems I Spring 2016

Computer Vision. Matlab

CITS2401 Computer Analysis & Visualisation

LAB 1: Introduction to MATLAB Summer 2011

Chapter 2. MATLAB Fundamentals

MATLAB/Octave Tutorial

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

ENGR Fall Exam 1

Laboratory 1 Introduction to MATLAB for Signals and Systems

EE-3221 MATLAB INTRODUCTION

Computational Modelling 102 (Scientific Programming) Tutorials

1 Introduction to Matlab

Transcription:

CHAPTER 1 INTRODUCTION Digital signal processing (DSP) technology has expanded at a rapid rate to include such diverse applications as CDs, DVDs, MP3 players, ipods, digital cameras, digital light processing (DLP) for high quality television pictures, cellular phones, high-speed modems, satellite systems, GPS receivers, medical imaging (X-rays, MRIs), voice recognition systems, radar processing, missile guidance systems, and even toys. A few decades ago, digital signal processing was taught only in graduate schools to electrical engineering majors. Today, it is a required course in most undergraduate programs in electrical and computer engineering and is often included in engineering technology programs and many electronic music programs as well. Figure 1.1 is a basic block diagram for a digital signal processing system. An analog signal is converted to a digital signal, processed in some manner, and then converted back to analog if appropriate. A simple example of this would be a CD. Analog music is sampled at a rate of 44.1 khz (44,100 samples/sec) and the digital data is stored on a CD. When the CD is played, the digital data stored on the CD is converted back to analog and played through the speakers. There is a lot of additional processing including data interleaving and error-correction coding that is used for CDs, but for now, this simple explanation will have to suffice. Analog Signal In Analog Signal Out Anti-Aliasing Filter (Low Pass Filter) A/D Converter Digital Processor D/A Converter Sampling Reconstruction Figure 1.1: Block Diagram of a DSP System This text introduces both the theory behind digital signal processing and some practical applications. Chapter 2 covers digital and analog signals and signal spectra. A lot of DSP processing occurs in the frequency domain so an understanding of signal spectra is critical. The sampling theorem and A/D and D/A conversion are covered in Chapter 3. Some of the key mathematical concepts including fixed-point and floating-point number systems, Z-Transforms, convolution, and correlation are introduced in Chapter 4. Chapters 5 and 6 cover digital filter design and many of the practical considerations associated with digital filter design and implementation. Multi-rate digital signal processing systems, including interpolation and decimation, are also covered in Chapter 5. Chapter 7 provides a detailed explanation of Discrete 1

Fourier Transforms a mathematically challenging but extremely practical topic. Chapter 8 covers some useful algorithms for real-time processing of signals including the sliding Discrete Fourier Transform, the Overlap Add and Overlap Save algorithms for real-time convolution or filtering, and an introduction to adaptive filters. Although many applications are introduced in each of the earlier chapters, Chapters 9 and 10 focus on specific DSP applications. Chapter 9 is an introduction to image processing and includes blurring filters, sharpening filters, edge detectors, and other algorithms for altering an image. The text concludes with an introduction to radar processing in Chapter 10. Pulsed radar signals are processed to determine range to target and to estimate target velocity. MATLAB is used extensively throughout the text and is an excellent tool for learning about digital signal processing. Many of the examples in the text use MATLAB. The code used to generate the results and the figures is included. Students are encouraged to repeat these examples using MATLAB and try variations to develop an in-depth understanding of the topics. Most of the chapters also include an extensive MATLAB lab exercise designed to further explore concepts covered in the chapter. These lab exercises provide an opportunity to practice concepts and develop a deeper understanding of the material. Each chapter also includes challenge questions to test students understanding of the concepts and to provide a preview of topics covered later in the text. Students are encouraged to review the section concepts and try to think through these questions. Answers for all challenge questions are at the end of the chapter and should definitely be reviewed before moving on to the next section or topic. The text website provides access to the MATLAB m-files, Simulink mdl files, and other types of files required for some of the lab exercises and examples in the text. Links to some useful and informative DSP sites are also provided. The lab exercise at the end of this chapter provides an introduction to using MATLAB. Students who are familiar with MATLAB may just want to skim the exercise for a quick review. 2

CHAPTER 1 LAB EXERCISE Introduction to MATLAB Objectives 1. Learn how to enter data into MATLAB and perform calculations. 2. Learn to plot functions in MATLAB. 3. Learn to write an m-functions for MATLAB. Procedure A. The MATLAB desktop Launch MATLAB. A desktop similar to the one shown in Figure 1 should come up, but may differ in appearance depending on the version of MATLAB being used. The Command Window is where commands are typed and executed. The Workspace Window displays all variables defined in the current MATLAB session. Figure 1: MATLAB Desktop 1. At the command prompt (>>) type the command: a=5 then hit Enter. You should see a = 5 appear in the Command Window. The variable, a, should also appear in the Workspace Window. 3

2. Next type the following command and hit Enter: b=7; Placing a semicolon at the end of a command line suppresses the output! However, the variable b with a value of 7 has been created and shows up in the Workspace Window. 3. To view or display a variable, simply type the variable name and hit Enter. For example, typing b at the command prompt will cause b = 7 to appear on the screen. 4. If you wish to repeat a previous command without re-typing it, there are two easy ways to accomplish this. In the Command Window, just hit the up-arrow as many times as necessary to travel back to the previous command. In the Command History Window, scroll back to the desired command and double click on it. B. Variables, Vectors, and Matrices in MATLAB Variable names can be defined using a combination of upper and lower case letters. If possible, variable names should reflect the nature of the variable being defined. Keep in mind: MATLAB is case sensitive (i.e., A is a different variable than a) i and j are defined in MATLAB to be (-1) to accommodate complex numbers. Do not use these variables for anything else or you will overwrite (-1). pi is defined in MATLAB to be the constant = 3.1416. Keep it reserved for this purpose. 1. Vectors and Matrices are entered into MATLAB using brackets [ ]. Entries are separated by spaces (or commas) while rows are separated using a semicolon. Type the following set of commands. row_vector = [1 3 7 15 25] column_vector = [1; 3; 5; 7] matrix = [1 2 3; 4 5 6; 7 8 9] Now hit Enter and record the output in the space below: 2. Complex numbers are entered using the pre-defined variables i or j. Type the following command: d = 2 + 7i Result = 4

3. To get a list of currently defined variables, use the command whos. You should get a list of variables similar to the following showing everything you have already defined. Name Size Bytes Class a 1x1 8 double array b 1x1 8 double array column_vector 4x1 32 double array d 1x1 16 double array (complex) matrix 3x3 72 double array row_vector 1x5 40 double array The whos command gives a complete listing of all variables currently defined and the size of those variables. The who command simply lists all variable names currently in use. This information is also available in the Workspace Window on the MATLAB desktop. 4. Vectors with equally spaced entries can easily be entered in MATLAB. These are useful as time or frequency variables. Type the following set of commands. t1 = 0:0.1:1 t2 = linspace(0,5,10) f = logspace(1,2,10) Record the output in the space below. Notes: The command linspace(t1,t2,n) will create a vector with N equally spaced points between t1 and t2. The command logspace(d1,d2,n2) will create a vector with N logarithmically spaced points between 10^d1 and 10^d2. The command clear will clear all variables. The command clear t1,t2 will simply clear variables t1 and t2. 5

C. Formatting Data There are several options for formatting data in MATLAB. 1. Open the MATLAB command window and type help format at the prompt. Read about the different formats for displaying numbers. Execute the following commands and write the output under each command: format short; number = 0.005152535455 format long; number format short e; number format long e; number Output = Output = Output = Output = 2. Return MATLAB to the default (short) by typing format at the command prompt and hitting Enter. D. MATLAB Operations and Functions MATLAB utilizes many operations and functions and follows the math order of operations rules. Some of the operations and functions are listed below. Operations Functions + Addition abs returns magnitude of a number Subtraction angle returns angle of a number in radians * Multiplication cos cosine assuming angle is in radians / Divide sin sine assuming angle is in radians ^ Power exp exponential function ' Transpose sqrt returns square root of a number Application: Solving Systems of Equations Suppose we wish to solve the following set of linear equations: 2x + 3y 7z = 10 3x + y + 4z = 12 x + 2y z = 15 6

Execute the following commands (note that % is used for comments): A = [2 3-7; 3 1 4; 1 2-1]; %Coefficients of the 3 equations b = [10; 12; -15]; %Constants on right hand side inv(a)*b ans = 15.8437-17.6562-4.4688 The solution is: x = 15.8437, y = 17.6562, and z = 4.4688. Exercise: Solve the following system of linear equations. x + 2y 5z = 8 3x + y + 4z = 9 x + 2y z = 0 List MATLAB commands and solution below: E. Plotting Signals 1. Plot the function f(t) = e 5t by executing the following set of commands: t = 0:0.01:2; f=exp(-5*t); plot(t,f); title('exponential Function'); xlabel('time'); ylabel('function');grid Plot Tools Icon for Editing Plots 7

2. Click on the plot tools icon at the top of the figure window. Experiment with changing color, line style, and other options within plot tools. Notice that title and axis labels can also be added using plot tools rather than as commands in the command window. When finished editing the plot, simply click on the close plot tools icon. 3. Plot the functions f1(t) = e 1t, f2(t) = e 2t, and f3(t) = e 5t on the same graph by executing the following commands: t = 0:0.01:2; f1 = exp(-1*t); f2 = exp(-2*t); f3 = exp(-5*t); plot(t,f1,t,f2,t,f3); title('three Functions at Once'); xlabel('time'); grid; legend('exp(-1t)','exp(-2t)','exp(-5t)') 4. Execute the following set of commands to divide the figure into several partitions and put a plot in each partition using the subplot function: t=0:0.1:10; f1 = sin(2*pi*0.2*t); f2 = sin(2*pi*0.5*t); f3= exp(-1*t).*sin(2*pi*0.5*t); f4=exp(-3*t).*sin(2*pi*0.5*t); subplot(2,2,1); plot(t,f1); title('f1');grid subplot(2,2,2); plot(t,f2); title('f2');grid subplot(2,2,3); plot(t,f3); title('f3');grid subplot(2,2,4); plot(t,f4); title('f4');grid 8

5. Figures created in MATLAB can easily be imported into other documents simply by clicking on Edit Copy Figure in the Figure Window. 6. To find out about more of the plot features, type the command: help plot in the MATLAB command window. F. Creating m-functions in MATLAB 1. In MATLAB, click on NEW, then choose Function. Type the MATLAB commands shown in Figure 2 into the editor window for your new function. Comments: The first line is a function line that defines the outputs (variables that will be sent back to the MATLAB workspace) and the inputs (variables that must be defined in order to run the m-file). For this function, the output variables are signal and t and the input variables are gain and power. The next line(s) are comments documenting what the function does The next set of lines are the MATLAB commands needed to complete the function 9

Figure 2: MATLAB FUNCTION 2. Save the file in your current directory folder as my_exponential. The file must be saved under the same name as the function. In order to run the function, it must be located in your current directory. 3. Close the edit session and in the MATLAB workspace type help my_exponential at the MATLAB command prompt. You should see all the comment lines prior to the first executable command. These are extremely helpful in reminding you what the function does and what input arguments need to be included. 4. At the MATLAB command prompt, type the command [f,t] = my_exponential(2,-5); You should see a plot of an exponentially decaying function. Also, the variables f and t should appear in your workspace window. f and t are vectors of the signal and time values created when the function was executed. MATLAB functions make MATLAB a customizable program and are very useful for calculations that you need to do often. They are also very useful if you have a very long set of commands that you don t wish to execute one at a time in the command window. You can also create a script file instead of a function file. A script file has no input or output arguments and simply executes all of the commands listed in the file. A script file is executed by simply typing the name of the file in the command window or by selecting Run in the MATLAB editor window. As with m-function files, a script file will only run if the file is located in your current directory. 10