Wednesday, March 22, 2017

Blog 10 group 1

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’)

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;
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.

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;
axis([0 .14 -10 10])
xlabel('Time (s)', 'FontSize', 12)
ylabel('y function', 'FontSize',12)

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;
axis([0 .14 -10 10])
xlabel('Time (s)', 'FontSize', 12)
ylabel('y function', 'FontSize',12)

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.

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.

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.

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
Graph 5: Shows the high pass filters data plotted

axis ([500 5000 4 12])
xlabel('Frequency (f)', 'FontSize', 12)
ylabel('Vout', 'FontSize',12)
title('High pass filter')

Graph 6: Shows the cut off frequency for the high pass filter


  1. Good blog this week guys. This week's blog was pretty straightforward. Taking EGR 200 last year has helped me use MATLAB much more efficiently. My only gripe would be I am not quite sure what your last graph is supposed to be showing. The way I understood the question, all that was asked was to calculate the cutoff freq using the find command and provide the code. This will be very similar to what you did in part b, question 3.

    1. Yes, Nick our graph is similar to the graph that we provided the code for in part b question 3.

  2. Overall I think you guys did a great job on your blog!I didn't take EGR200, I took CPS180, so I am not used to MATLAB like some others in the class are. Your graphs look very good especially on the high and low pass filter, and the graph from #12 looks almost identical to ours! It looks like you guys did a great job this week, good job.

  3. The High pass filter that is pictured last seems to be missing a lot of data. I also was curious about your Y axis. Our voltage output was a lot lower than yours. I wonder if thats because of different equipment.

  4. We found significantly different plots of data for our high pass filter. The only question now is which one of us is correct. Also, you may want to check your frequency values for your part b # 5 problem 1, as one is 2.2 Hz between values or higher degree.