1. Open MATLAB. Open the editor and copy paste the following code. Name your code as FirstCode.m
Save the resulting plot as a JPEG image and put it here.
clear all;
close all;
x = [1 2 3 4 5];
y = 2.^x;
plot(x, y, 'LineWidth', 6)
xlabel('Numbers', 'FontSize', 12)
ylabel('Results', 'FontSize', 12)
2. What does clear all do?
it will clear everything include all the variable and the commend window.
3. What does close all do?
it will close all the figure windows that are open.
4. In the command line, type x and press enter. This is a matrix. How many rows and columns are there in the matrix?
1 row and 5 columns
5. Why is there a semicolon at the end of the line of x and y?
when we typed the semicolon at the end of the line of x and y that to make sure that the output of the commend is not displayed, and just to make sure when the output is very large.
6. Remove the dot on the y = 2.^x; line and execute the code again. What does the error message mean?
Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
the eror showed that we must use the dot in order to not get eror in this equation and getting the right graph.
7. How does the LineWidth affect the plot? Explain.
we used the LineWidth to specify the width of the line in the plot. We can make the bigger or thinner that depends in the point we upload.
8. Type help plot on the command line and study the options for plot command. Provide how you would change the line for plot command to obtain the following figure (Hint: Like ‘LineWidth’, there is another property called ‘MarkerSize’)
To change the width of the line, the last number (which is number 6/default in the code) needs to be changed. To obtain a thicker line a higher number needs to be in instead of the 6, and to get a smaller number a smaller number than 6 needs to be used.
9. What happens if you change the line for x to x = [1; 2; 3; 4; 5]; ? Explain.
The only thing that changes is that the row vector is changed into a column vector, but nothing changes on the graph. No visual changes, nothing...
10. Provide the code for the following figure. You need to figure out the function for y. Notice there are grids on the plot.
clear all;
close all;
x = [1; 2; 3; 4; 5];
y = x.^2;
plot(x, y, ':sk','LineWidth', 6, 'MarkerSize', 19)
grid
xlabel('Numbers', 'FontSize', 12)
ylabel('Results', 'FontSize', 12)
11. Degree vs. radian in MATLAB:
a. Calculate sinus of 30 degrees using a calculator or internet.
using the calculator we got 0.5
b. Type sin(30) in the command line of the MATLAB. Why is this number different? (Hint: MATLAB treats angles as radians).
when we type sin(30) in the matlab we got 0.9880
c. How can you modify sin(30) so we get the correct number?
if we add d after sin we will change the calculation from radians to degrees
sind(30)=0.5
12. Plot y = 10 sin (100 t) using Matlab with two different resolutions on the same plot: 10 points per period and 1000 points per period. The plot needs to show only two periods. Commands you might need to use are linspace, plot, hold on, legend, xlabel, and ylabel. Provide your code and resulting figure. The output figure should look like the following:
t=linspace(0,0.126,10);
y=10*sin(100*t);
x=linspace(0,0.126,1000);
z=10*sin(100*x);
plot(t,y,'ro',x,z,'k')
axis([0 0.14 10 10])
xlabel('Time(S)')
ylabel('y function')
legend('Course','Fine')
13. Explain what is changed in the following plot comparing to the previous one.
by making the fine function equal or greater than 5.
14. The command find was used to create this code. Study the use of find (help find) and try to replicate the plot above. Provide your code.
PART B: Filters and MATLAB
1. Build a low pass filter using a resistor and capacitor in which the cut off frequency is 1 kHz. Observe the output signal using the oscilloscope. Collect several data points particularly around the cut off frequency. Provide your data in a table.
Frequency(kHz)

V(out) (V)

(V(out)/V(in)) (V)

0

0

0

0.1

3.764

1.08

0.2

3.643

1.04

0.2

3.509

1.002

0.4

3.372

0.963

0.5

3.162

0.903

0.6

2.959

0.845

0.7

2.768

0.791

0.8

2.572

0.735

0.9

2.406

0.687

1.0

2.257

0.645

1.1

2.096

0.599

1.2

1.963

0.561

1.3

1.846

0.527

1.4

1.743

0.498

1.5

1.634

0.466

1.6

1.582

0.452

1.7

1.471

0.420

1.8

1.390

0.397

2. Plot your data using MATLAB. Make sure to use proper labels for the plot and make your plot line and fonts readable. Provide your code and the plot.
3. Calculate the cut off frequency using MATLAB. find command will be used. Provide your code.
A=find(z>0.68)
B=x(A);
C=z(A);
D=find(C<0.72);
fC=B(D);
fprintf ('Cutoff Frequency = %1.1f kHz' fc)
the cut off frequency we get from the matlab is 0.9kHz
5. Repeat 13 by modifying the circuit to a high pass filter.
Frequency(kHz)

V(out) (V)

(V(out)/V(in)) (V)

0

0

0

0.1

0.588

0.168

0.2

0.976

0.279

0.2

1.345

0.384

0.4

1.568

0.448

0.5

1.866

0.533

0.6

2.122

0.606

0.7

2.244

0.641

0.8

2.421

0.692

0.9

2.512

0.712

1.0

2.591

0.740

1.1

2.624

0.749

1.2

2.697

0.771

1.3

2.725

0.779

1.4

2.769

0.791

1.5

2.791

0.797

1.6

2.811

0.803

1.7

2.829

0.808

1.8

2.837

0.811

3. Calculate the cut off frequency using MATLAB. find command will be used. Provide your code.
A=find(z>0.68)
B=x(A);
C=z(A);
D=find(C<0.72);
fC=B(D);
fprintf ('Cutoff Frequency = %1.1f kHz' fc)
B=x(A);
C=z(A);
D=find(C<0.72);
fC=B(D);
fprintf ('Cutoff Frequency = %1.1f kHz' fc)
the cut off frequency we get from the matlab is 0.9kHz