Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3.1 Debug coscos. Download the file coscos.m and use the debugger to find the er

ID: 2085893 • Letter: 3

Question

3.1 Debug coscos. Download the file coscos.m and use the debugger to find the error(s) in the function. Call the function with the test case.( xn , tn] = cos cos (2, 3 , 20 , 1 ) . Use the debugger to: 1. Set a breakpoint to stop execution when an error occurs and jump into "Keyboard" mode 2. Display the contents of important vectors while stopped Determine the size of all vectors by using either the size) function or the whos command; and, 4. Lastly, modify variables while in the "Keyboard" mode of the debugger. function [xx ,tt] cos cos ( f1, f2, fs, dur ) % coscos multiply two sinusoids ti 0: (1/fs) : dur cos1 = cos (2*pi * f1+t1) ; cos2 cos (2*pi*f2 * t2) ; = tt = t1 ; Show that you can use the debugger on the text file coscos.m to the TA for verification.

Explanation / Answer

The code mentioned in the question has the following errors:

1. Matrix dimensions of cos1 and cos2 do not agree. This is because t1 and t2 are defined for different steps ( for 1/fs and 1/f2 respectively), Therefore, elementwise multiplication (.*) or multiplication of matrixes (*) functions can't be used. For this the possible solution use same step size for t1 and t2. Therefore, the correct code is:

function [xx, tt] = coscos(f1,f2,fs,dur)
t1=0:(1/fs):dur;
t2=0:(1/fs):dur;
cos1=cos(2*pi*f1*t1);
cos2=cos(2*pi*f2*t2);
xx=cos1.*cos2;
tt=t1;

size(xx)--> this command is used to find out the dimensions of the variable xx. For the above code, size(xx) will give answer as

1 21

whos --> this command is used to find out the Name, Size, Bytes, Class, Attributes of all variables used in a program.

Since, your are defining a function, the workspace used is a local and is shared by the gobal workspace i.e. the variables will not be displayed in the Workspace Window.

To find use the command size() or whos, use it in the function itself.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote