LAB 2 F

LAB 2 F

LAB 2 F. A. Q.


Updated on 30-Jan-2000



0. Some of these questions don’t seem to make sense with respect to this semester’s lab.


ANSWER: Correct. The FAQs are based on the labs from Fall-99. Refer to that lab description when certain section numbers are cited.



1. (4.1.1) If I understand correctly, my resultant "xx" will need to be a vector containing amplitudes. These amplitudes will be the sum of the complex amplitudes "Xk" at their respective frequencies "fk." I have the sum of all the complex amplitudes at their respective frequencies; however, I am at a loss as to how to create my "xx" vector. I know I can multiply the magnitude of my sum by the cosine of some frequency plus my "tt" vector plus the phase of my sum, but I am not sure which frequency to use. I have an entire vector, fk(), of frequencies. Is this correct?


ANSWER: NO, "xx" should be a vector containing values of the sinusoid. In other words, it is a function of time (t). You don’t sum the complex amplitudes! For example, if all the frequencies are different, the “Phasor Addition Theorom” does NOT apply, so you wouldn’t want to sum the complex amplitudes. Instead, you should use the complex amplitudes to produce the sinusoids, which are functions of time. Then add the sinusoids (which are vectors in MATLAB).



2. (4.1.1) I am confused about samples per period. If we take in 3 different cosine waves with different frequencies, how are we supposed to know which one to use for sampling purposes.


Since the frequencies are different we cannot add them, so I assume we should display 3 separate waves on a single graph. Is this correct?


ANSWER: You can combine the signals into one. Look up equation 7 on page 4 of the (Fall-99) lab. Base you samples per period on the highest frequency sinusoid in the summation.



3. (4.1.1) I keep getting this message: "Improper assignment with rectangular empty matrix.” I think it has something to do with my "for" loop. Could you please tell me why I’m getting this message?


ANSWER: Read pages 408-411. Some discussion of functions and loops can be found there. You need some DEBUGGING capability. Remove the semi-colons from the end of statements, and then the results will be echoed. That should let you see what’s going on. Or, use the MATLAB debugger. See help dbstop and related commands. One very helpful command is: dbstop if error. This will put you in the debugger when an error occurs. Then you can inspect the contents of some variable names.



4. (4.1.1) The following code is what I am using to add my sinusoids, but when I try to


test using [xx4, tt4], I receive an error about matrix dimensions not agreeing. What am I doing wrong?


xx = xx + real(Xk(k)*exp(j*2*pi*fk(k)*tt));


ANSWER: This looks correct, so something else is going on. Time for DEBUGGING. (Use the command "help debug" to learn more about debugging capabilities) Use dbstop if error (in the command window). When the program bombs, look at what is in the variables, xx and tt. Use the whos command to see sizes of all the variables. They are probably not the same dimensions. Or, use size(tt) or size(xx) to see what’s going on. (ADDITIONALLY: it may be useful to initialize xx as zero, ie., xx = 0, or as the empty matrix, ie. xx = [ ]!)



5. (4.1.4) When the lab asks for a concatenation of three sinusoids, and asks us to use the sinus function to do so, how is this possible? The sinus function is supposed to add the sinusoids together, and that defeats the purpose of concatenation. Is there some way the sinus function can be used in this problem without rewriting the function?


ANSWER: Sure, but you have to call it three times. Note the hint in the lab text: “in MATLAB row vectors can be concatenated by writing xxx = [xx1,xx2,xx3].” Basically, you need to put tones together in sequence such as A B C. It means playing A first, then B, then C. A, B, and C are all vectors.



6. (4.1.4) Are we supposed to change our code in sinus( ) to change from summation and concatenation?


ANSWER: That’s one way to do it. Make a new function called sinus_cat(). Or, you can just call sinus() a few times; and do the concatenation in the calling program.

7. (4.2) From my understanding, we are supposed to write the following:


xt = sinus(“[fk]”, “[Xk]”, “fs”, “dur”).


I have an idea of what “[fk]” and “[Xk]” are, but what about the rest?


ANSWER: The comments given for the proposed sinus() function should define all the arguments. Repeating some of these:



% fs = the number of samples per second for the time axis


% dur = total time duration of the signal


% tstart = starting time (default is zero, if you make this input optional)



ADDENDUM 1: I know how to get the values for the first two but I am unsure about the last two variables (fs and dur).


ANSWER: The values are passed into the function. You use the variable name to “get the values.” For examples: "dur" was used in the mycos() function, and fs has been used on


several occasions to generate sounds.



ADDENDUM 2: This is the command that I have for section 4.2:


xt = sinus([100],[-2-j*2], fs, dur); (1)


I got 100 for "fk" because the original equation had 200*pi*t, which is equal to 100*2*pi*t, 100 being fk (in Hz). And, for Xk, I assumed it was -2-j*2, because the original equation had x(t)=Re{(-2-j*2)*exp(j*200*pi*t)}, in which Ak = Xk = -2-j*2. Getting the values to put into command (1) for "fs" and "dur" seems to be a problem.


ANSWER: Read page 6 of the lab carefully. The information to define "fs" and "dur" is contained in the instructions on that page. Or experiment with some values to see what you get. The “testing” cases might give some clues also.