**Part A: MATLAB Practice**

**Number 1:**

MatLab Code:

1 2 3 4 5 6 7 8 9 10 | 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) |

**Number 2:**

*What does clear all do?*

*clear all*Clears all objects in the work space.

**Number 3:**

*What does close all do?*

*close all C*loses all figures currently open

*.*

**Number 4:**

*Type x in the command line and press enter. how many rows and columns are there?*

There are 5 columns and 1 row in the matrix x.

**Number 5:**

*Why is there a semicolon at the end of the line of x and y?*

Because its the end of a statement.

**Number 6:**

*Remove the dot on the y=2.^x; line and execute the code again. what does the error*

*message mean?*

*ERROR MESSAGE: "error using ^ inputs must be a scalar and a square matrix to compute element wise power, use power (.^) instead."*

This means that without the '.' it thinks we are doing a matrix math power but since we are trying to do a element by element power with want the '.' to do that.

**Number 7:**

*How does the LineWidth affect the plot?*

Line width changes the width of the plot line of the graph making it thicker or thinner

MatLab Code:

1 2 3 4 5 6 7 | clear all; close all; x = [1 2 3 4 5]; y = 2.^x; plot(x, y, '-or', 'LineWidth', 2, 'MarkerSize', 10) xlabel('Numbers', 'FontSize', 12) ylabel('Results', 'FontSize', 12) |

**Number 9: What happens when you change x =**[1 2 3 4 5]; to x = [1;2;3;4;5];

Nothing happens different when we add in [1;2;3;4;5] instead of [1 2 3 4 5] at least visibly

**Number 10:**C

*hange code to copy figure from blogsheet week 10 PART A number 10 and provide code.*

1 2 3 4 5 6 7 8 9 10 11 12 | clear all; close all; x = [1 2 3 4 5]; y = x.^2 plot(x, y, ':sk', 'LineWidth', 4, 'MarkerSize', 15) grid on set(gcc, 'GridLineStyle', '--'') xlabel('Numbers', 'FontSize', 12) ylabel('Results', 'FontSize', 12) |

**Number 11:**

*Degree vs. radian in MatLab***a.)**

*C*

*alculate sin(30) using the Internet*

sin(30) = .5

**b.)**

*Calculate sin(30) using MatLab*

sin(30) = -.9880

**c.)**

*How do you modify sin(30) so we get the correct number?*

**S**in of 30 degrees in MatLab is sind(30) = .5

**Number 12:**

*Plot y = 10*sin(100*t) in MatLab with 2 different resolutions on the same plot. Provide Code.*

MatLab Code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | clear all; close all; tc = linspace(0,.125, 10); tf = linspace(0,.125, 1000); yc = 10*sin(100*tc); yf = 10*sin(100*tf); plot(tc, yc, '-or', 'LineWidth', 1, 'MarkerSize', 6) hold on plot(tf, yf, '-k', 'LineWidth', 1, 'MarkerSize', 2) xlim([0 .14]) xlabel('Time (s)', 'FontSize', 12) ylabel('y function', 'FontSize', 12) legend('Coarse','Fine') |

**Number 13:**

*Explain whats change in the following plot from the previous one. (fig. 5)*

The plot(fig. 5) has all values above 5 removed for the fine plot.

**Number 14:**

*Replicate the plot from the blogsheet week 10 number 13 using MatLab and find.*

Figure 5 Number 14 code output |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | clear all; close all; tc = linspace(0,.125, 10); tf = linspace(0,.125, 1000); yc = 10*sin(100*tc); yf = 10*sin(100*tf); yff = find(yf<5); plot(tc, yc, '-or', 'LineWidth', 1, 'MarkerSize', 6) hold on plot(tf(yff), yf(yff), '-k', 'LineWidth', 1, 'MarkerSize', 2) xlim([0 .14]) xlabel('Time (s)', 'FontSize', 12) ylabel('y function', 'FontSize', 12) legend('Coarse','Fine') |

**Part B: Fliters and MATLAB**

**Low Pass Filter**

MatLab Code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | clear all; close all; x = [50 100 200 300 400 500 600 700 800 850 860 870 880 890 895 900 1000 1200 1400 1600 1800 2000]; y = [5.95 5.9 5.75 5.55 5.31 5.06 4.81 4.57 4.34 4.28 4.24 4.22 4.2 4.18 4.16 4.12 3.92 3.57 3.26 3.00 2.77 2.58 ]; y = y/5.94; plot(x, y, '-or', 'LineWidth', 1, 'MarkerSize', 6) hold on refline(0,0.707); xlabel('Frequency', 'FontSize', 12) ylabel('Output/Input', 'FontSize', 12) |

**High Pass Filter**

MatLab Code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | clear all; close all; x = [50 100 300 600 800 850 860 870 880 890 895 900 910 920 930 940 950 1000 1200 1400 1600 1800 2000 2200 2400 2600 2800 3000 3500 4000 4500 5000]; y = [.4 .747 2 3.34 3.94 4.05 4.07 4.08 4.1 4.12 4.14 4.14 4.17 4.19 4.22 4.24 4.25 4.36 4.67 4.91 5.09 5.23 5.34 5.42 5.5 5.56 5.6 5.64 5.73 5.8 5.85 5.93]; y = y/5.94; plot(x, y, '-or', 'LineWidth', 1, 'MarkerSize', 6) hold on refline(0,0.707); xlabel('Frequency', 'FontSize', 12) ylabel('Output/Input', 'FontSize', 12) |