The reference book for DSP lab is Computer-Based Exercises for Signal Processing Using MATLAB (CBESP) by Burrus et al. Prentice-Hall, 1994. The class is taught by Howard L. Weinert. Dr. Weinert is a faculty member in the Electrical and Computer Engineering department at the Johns Hopkins University. The TA for DSP this semester is Chenyang Xu who is a research assistant at Image Processing and Communication lab.
note: all page numbers used in the projects assignment refer to CBESP; the subplot command is strongly recommended to be used whenever a lot of plots are required. For those who never use subplot before, try typing "help subplot" inside MATLAB and you should be able to learn how to use it easily.
Download the functions in the CBESP. All of these files are also available from their official distribution site via anonymous FTP (eedsp.gatech.edu or IP address 130.207.226.24) in the directory pub/MATLAB and also as a disk distributed through the MathWorks, Inc., makers of the MATLAB software.
A matlab program is a collection of MATLAB statements which is saved as .m file on the disk. One could use any text editor to compose the .m program. For example, paste the following MATLAB code into a file and save as hello.m
disp('Hello MATLAB'); a = 3 b = a*aMake sure the hello.m is saved in the current directory. Now type hello inside the MATLAB. hello.m will be executed sequentially just as if one typed in by hand. ".m" file is very useful for us to organize MATLAB code in our DSP project.
A matlab function is a special type of .m file which has a special statement (funcion ...) as its first line. Examples of functions which return one and two variables are listed below.
---------- onevar.m ------------------------------- function d = onevar(x,y) % this is a comment which will show up % when one type "help onevar" in the matlab. % this is a useful way to write help message % for your function % this is a local comment which will not show % up when "help onevar" is typed. d = sqrt(x.*x+y.*y); ---------------------------------------------------Now one can call onevar inside the matlab as following:
x = 3 y = 5 d = onevar(x,y) x = [1 2 3] y = [-1 -2 -3] d = onevar(x,y)
---------- twovars.m ------------------------------- function [s,d] = twovars(x,y) % function [s,d] = twovars(x,y) % compute the sum and difference between x and y % The sum and difference are stored in s and d % respectively. % Here the program starts s = x+y; % compute the sum d = x-y; % compute the difference ----------------------------------------------------Now one can call twovars inside the matlab as following:
x = 3 y = 5 [s,d] = twovars(x,y) x = [1 2 3] y = [-1 -2 -3] [s,d] = twovars(x,y)
x[n] = delta(n), and y[n] = delta(n-5)Judge the use of each method by yourself.
METHOD 1 n = -10:10; x = zeros(size(n)); x(11) = 1; y = zeros(size(n)); y(16) = 1; METHOD 2 n = -10:10; x = zeros(size(n)); x(n==0) = 1; y = zeros(size(n)); y(n==5) = 1;
[Q]: > I have started working on the Matlab homework, but I am confused in > certain places whatg you want us to turn in for a grade. For example > part b on page 6. It says compare the result to formula 1-6. Do we > have to write up the comparisson? Just compute the sum in two ways and output the results to see whether they match each other. The material to turn in for this part is your MATLAB code for computing two sums and the output of your code. [Q]: > Also for part a), what is it asking us to turn in? Matlab code and the plot of x[n] = (0.9)^n, 0<=n<=20. [Q]: > In the cases where it asks for a function (I assume a .m file), > do we print that up and staple it with our other work? Yes. [Q]: > For our plots, how do you want them labled? ( problem 1.2 part a). Just say 'Time index [n]' is fine. [Q]: > In cases where it says "Show", how should we turn in our work > (store the work in a .mat file and mail it to you) ? If you work in the Windows 95 or Mac, you may be able to use Matlab Notebook to write your report which includes any discussion or mathematic manipulation required as well as pictures generated by your program. As for the implementation code, you can attach them at the end. But their names need to be properly labeled and referred in your report. If you work in the X windows environment, you could type any analysis, discussions, and math manipulations using any text editor. Attach all your figures and programs at the end. Make sure all the programs and figures are properly labelled and referred in your report. As for mailing me matlab program, I think this is a very good idea. This may happen for the later projects. However for project 1, written report is required.