**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.**
__Graph 1:__ Shows the plot of the code

**2. What does clear all do?**
It clears all the variables in the work space.

**3. What does close all do?**
It closes all the figures 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?**
It is a 1 x 5 matrix; 1 row and 5 columns.

**5. Why is there a semicolon at the end of the line of x and y?**
It supresess the output so that it does not appear in the command window and therefore helps not clutter up the command window

**6. Remove the dot on the y = 2.^x; line and execute the code again. What does the error message mean?**
The dot is required whenever doing an operation to an input that is a matrix because the multiplication must be applied to each individual number in the array.

**7. How does the LineWidth affect the plot? Explain.**
It increases or decreases the width of the line in the plot which is helpful when adjusting the precision of the graph based on the range.

**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’)**
plot(x,y,'r-o','markersize',10,'linewidth',4)

**9. What happens if you change the line for x to x = [1; 2; 3; 4; 5]; ? Explain.**
Nothing changes it workes exactly the same way because it is changing the matrix into a 5x1 matrix with 5 rows and 1 column.

**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,'k:s','markersize',12,'linewidth',4)

grid ON

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.**
sin(30)=0.5

**b. Type sin(30) in the command line of the MATLAB. Why is this number different? (Hint: MATLAB treats angles as radians).**
Matlab outputs that sin(30) is -0.9880 because matlab treats the number inside the parenthesis as radians as opposed to degrees.

**c. How can you modify sin(30) so we get the correct number?**
You change the function to "sind(30)" and then get an output of 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:**
clear all;

close all;

t1=[0:pi/25000:pi/25];

y=10*sin(100.*t1);

t2=[0:pi/250:pi/25];

z=10*sin(100.*t2);

plot(t1,y,'k',t2,z,'r-o')

axis([0 .14 -10 10])

xlabel('Time (s)', 'FontSize', 12)

ylabel('y function', 'FontSize',12)

legend('fine','coarse','location','NorthEast')

__Graph 2__: Shows the two plotted points from the code

**13. Explain what is changed in the following plot comparing to the previous one.**
The only thing that is different is that the "fine" plot has a cut-off point that the other didn't have at y=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.**
clear all;

close all;

t1=[0:pi/25000:pi/25];

y=10*sin(100.*t1);

a=find(y<5)

t2=[0:pi/250:pi/25];

z=10*sin(100.*t2);

plot(t2,z,'r-o',t1(a),y(a),'k')

axis([0 .14 -10 10])

xlabel('Time (s)', 'FontSize', 12)

ylabel('y function', 'FontSize',12)

legend('fine','coarse','location','NorthEast')

**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(Hz): |
Vout: (pk-pk) |

500 |
9.68 |

600 |
9.36 |

700 |
9.04 |

800 |
8.8 |

900 |
8.48 |

1000 |
8.24 |

1100 |
7.92 |

1200 |
7.6 |

1300 |
7.36 |

1400 |
7.04 |

1500 |
6.80 |

1600 |
6.56 |

1700 |
6.4 |

2000 |
5.76 |

2200 |
5.44 |

__Table 1:__ Shows frequency and Vout of the low pass filter
**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.**
f=[500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,2000,2200];

v=[9.68,9.36,9.04,8.8,8.48,8.24,7.92,7.6,7.36,7.04,6.80,6.56,6.4,5.76,5.44];

plot(f,v)

axis([400 2200 5 10])

xlabel('Frequency (f)', 'FontSize', 12)

ylabel('Vout', 'FontSize',12)

title('Low pass filter')

**Graph 3:** Shows the low pass filters outputs

**3. Calculate the cut off frequency using MATLAB. find command will be used. Provide your code.**
f=[500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,2000,2200];

v=[9.68,9.36,9.04,8.8,8.48,8.24,7.92,7.6,7.36,7.04,6.80,6.56,6.4,5.76,5.44];

vin=10

a=find(v<7.07)

plot(f(a),v(a))

axis([400 2200 5 10])

xlabel('Frequency (f)', 'FontSize', 12)

ylabel('Vout', 'FontSize',12)

title('Low pass filter')

**4. Put a horizontal dashed line on the previous plot that passes through the cutoff frequency.**

**Graph 4:** Shows the low pass filters outputs at the cut off frequency

**5. Repeat 1-3 by modifying the circuit to a high pass filter.**
**A.**
Frequency(Hz) |
Vout: (pk tp pk) |

500 |
4.16 |

600 |
4.8 |

700 |
5.44 |

800 |
6.08 |

900 |
6.56 |

1000 |
7.01 |

1100 |
7.44 |

1200 |
7.84 |

1300 |
8 |

1400 |
8.56 |

1500 |
8.8 |

1600 |
9.04 |

1700 |
9.28 |

2000 |
9.92 |

2.2 |
10.2 |

3000 |
11 |

4000 |
11.7 |

5000 |
11.9 |

__Table 2__: Shows frequency and Vout for the high pass filter
**B. **

__Graph 5:__ Shows the high pass filters data plotted

f=[500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,2000,2200,3000,4000,5000];

v=[4.16,4.8,5.44,6.08,6.56,7.01,7.44,7.84,8,8.56,8.8,9.04,9.28,9.92,10.2,11,11.7,11.9];

plot(f,v)

axis ([500 5000 4 12])

xlabel('Frequency (f)', 'FontSize', 12)

ylabel('Vout', 'FontSize',12)

title('High pass filter')

C.

__Graph 6:__ Shows the cut off frequency for the high pass filter