Sunday, March 19, 2017

Blog Report Week 10

PART A: MATLAB practice.
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)

Add caption

2. What does clear all do?

Clear all clears all of the previous commands that are left in the command window.

3. What does close all do?

Close all closes all of the figures and windows that have been made previous to this command.

4. In the command line, type x and press enter. This is a matrix. How many rows and columns are there in the matrix?

This matrix has 5 columns and 1 row.

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

This semicolon prevents the command from showing up in the command window, but still allows the command to go through.

6. Remove the dot on the y = 2.^x; line and execute the code again. What does the error message mean?

7. How does the LineWidth affect the plot? Explain.

Line Width makes allows you to change the thickness of the graph.

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’)
Add caption
clear all;
close all;
x = [1 2 3 4 5];
y = 2.^x;
plot(x, y,'ro-', 'LineWidth', 6, 'markersize', 20)
xlabel('Numbers', 'FontSize', 12)
ylabel('Results', 'FontSize', 12)
Add caption




9. What happens if you change the line for x to x = [1; 2; 3; 4; 5]; ? Explain.

This adjusts the matrix by making it have 1 column and 5 rows. The semi columns cause you to "enter" within the matrix, moving your next entry down a row.

10. Provide the code for the following figure. You need to figure out the function for y. Notice there are grids on the plot.
Add caption
clear all;
close all;
x = [1 2 3 4 5];
y = x.^2;
plot(x, y,'sk:', 'LineWidth', 6, 'markersize', 20)
xlabel('Numbers', 'FontSize', 12)
ylabel('Results', 'FontSize', 12)
grid on
set(gca, 'gridlinestyle',':')
Add caption


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

sin(30)
ans =

   -0.9880

This number is different because 30 radians is not equivalent to 30 degrees and Matlab is doing the calculation with respect to radians while my calculator is doing the calculation with respect to degrees.


c. How can you modify sin(30) so we get the correct number?

The command "sind( )" allows you to evaluate the problem with respect to degrees instead of radians.

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:
Add caption
clear all;
close all;
clc;
x=linspace(0,.1256636,10);
y=100*sin(100*x);
plot(x,y,'ro-')
hold on
z=linspace(0,.1256636,2000);
q=100*sin(100*z);
plot(z,q)
xlabel('Time (s)');
ylabel('y function');
legend('Coarse','Fine')
Add caption

13. Explain what is changed in the following plot comparing to the previous one.
Add caption


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;
clc;
x=linspace(0,.1256636,10);
y=10*sin(100*x);
plot(x,y,'ro-')
hold on
z=linspace(0,.1256636,2000);
q=10*sin(100*z);
t=find(q>5);
q(t)=5;
plot(z,q)
xlabel('Time (s)');
ylabel('y function');

legend('Coarse','Fine')


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.



Low Pass






High Pass


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.


Low Pass
clear all;
close all;
x = [1000 990 980 889 789 688 589 299 104 1113 1300 2331 3000 5023 7588 4242 6500];
y = [2.124 2.1356 2.1469 2.237 2.3277 2.4294 2.5198 2.7571 2.825 2.011 1.853 1.22 0.983 0.621 0.429 0.734 0.497];
X=sort(x);
Y=sort(y,'descend');
plot(X, Y, '-ro','MarkerSize', 5)
xlabel('Frequency', 'FontSize', 12)
ylabel('Vout / Vin RMS', 'FontSize', 12)


High Pass
clear all;
close all;
x = [1000 743 560 342 243 154 1647 1813 2994 1484 1364 1125 2666];
y = [1.966 1.638 1.344 0.892 0.666 0.4519 2.406 2.474 2.700 2.316 2.248 2.079 2.655];
X=sort(x);
Y=sort(y);
plot(X, Y, '-ro','MarkerSize', 5)
xlabel('Frequency', 'FontSize', 12)
ylabel('Vout / Vin RMS', 'FontSize', 12)

3. Calculate the cut off frequency using MATLAB. find command will be used. Provide your code.
4. Put a horizontal dashed line on the previous plot that passes through the cutoff frequency.
5. Repeat 1-3 by modifying the circuit to a high pass filter.

clear all;
close all;
x = [1 2 3 4 5];
y = 2.^x;
plot(x, y,'ro-', 'LineWidth', 6, 'markersize', 20)
xlabel('Numbers', 'FontSize', 12)
ylabel('Results', 'FontSize', 12)
%%
clear all;
close all;
x = [1 2 3 4 5];
y = x.^2;
plot(x, y,'sk:', 'LineWidth', 6, 'markersize', 20)
xlabel('Numbers', 'FontSize', 12)
ylabel('Results', 'FontSize', 12)
grid on
set(gca, 'gridlinestyle',':')
%%
clear all;
close all;
clc;
x=linspace(0,.1256636,10);
y=10*sin(100*x);
plot(x,y,'ro-')
hold on
z=linspace(0,.1256636,2000);
q=10*sin(100*z);
t=find(q>5);
q(t)=5;
plot(z,q)
xlabel('Time (s)');
ylabel('y function');
legend('Coarse','Fine')
%%
clear all;
close all;
x = [1000 990 980 889 789 688 589 299 104 1113 1300 2331 3000 5023 7588 4242 6500];
y = [2.124 2.1356 2.1469 2.237 2.3277 2.4294 2.5198 2.7571 2.825 2.011 1.853 1.22 0.983 0.621 0.429 0.734 0.497];
X=sort(x);
Y=sort(y,'descend');
plot(X, Y, '-ro','MarkerSize', 5)
xlabel('Frequency', 'FontSize', 12)
ylabel('Vout / Vin RMS', 'FontSize', 12)
%%
clear all;
close all;
x = [1000 743 560 342 243 154 1647 1813 2994 1484 1364 1125 2666];
y = [1.966 1.638 1.344 0.892 0.666 0.4519 2.406 2.474 2.700 2.316 2.248 2.079 2.655];
X=sort(x);
Y=sort(y);
plot(X, Y, '-ro','MarkerSize', 5)
xlabel('Frequency', 'FontSize', 12)
ylabel('Vout / Vin RMS', 'FontSize', 12)
%% Calculating Cutoff LP
clear all;
close all;
x = [1000 990 980 889 789 688 589 299 104 1113 1300 2331 3000 5023 7588 4242 6500];
y = [2.124 2.1356 2.1469 2.237 2.3277 2.4294 2.5198 2.7571 2.825 2.011 1.853 1.22 0.983 0.621 0.429 0.734 0.497];
X=sort(x);
Y=sort(y,'descend');
plot(X, Y, '-ro','LineWidth', 2, 'MarkerSize', 8, 'MarkerEdgeColor', 'k')
xlabel('Frequency', 'FontSize', 12)
ylabel('Vout / Vin RMS', 'FontSize', 12)
k = find (vout>5.96*.65, 1, 'last')
x(k)
%% Horizontal Line
clear all;
close all;
x = [1000 990 980 889 789 688 589 299 104 1113 1300 2331 3000 5023 7588 4242 6500];
y = [2.124 2.1356 2.1469 2.237 2.3277 2.4294 2.5198 2.7571 2.825 2.011 1.853 1.22 0.983 0.621 0.429 0.734 0.497];
X=sort(x);
Y=sort(y,'descend');
plot(X, Y, '-ro','MarkerSize', 5)
hold on
xlabel('Frequency', 'FontSize', 12)
ylabel('Vout / Vin RMS', 'FontSize', 12)
f=2
fplot(f,':r')



No comments:

Post a Comment