Tuesday, March 22, 2016

Lab Team 4 Week 10

Blog Sheet week 10

In this week’s lab, you will collect more data on low pass and high pass filters and “process” them using MATLAB.


PART A: MATLAB practice.

  1.  Open MATLAB. Open the editor and copy paste the following code. Name your code as FirstCode.m
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)

<Save the resulting plot as a JPEG image and put it here.>



(FirstCode.m code and output figure.)

  2.  What does clear all do?

Clear All clears all previously assigned variables/Scripts and functions.

  3.  What does close all do?

Close All clears all deletes all figures whose handles are not hidden.

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

When “x” is input into the command window it returns a 10 column single row matrix as seen below:

>> x

x =

         0    0.0140    0.0279    0.0419    0.0559    0.0698    0.0838    0.0977    0.1117    0.1257



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

The Semi colon at the end of x and y prevent those lines of text from being displayed in the command window.

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

When the periods is removed  from line four the following error is returned

Error using  ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.

The reason we are getting this error is that we are trying to use an operator that only works with scalar values in a calculation involving matrices.

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

As the Name implies the LineWidth value sets the width of the line connecting the points on your plot.  A low LineWidth value outputs a thin line while a higher value will  result in a thicker line.

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


Below is a version of our original code, along with a screenshot of its output, that our group modified to mimic the figure above.

clear all;
close all;
x = [1; 2; 3; 4; 5];
y = x.^2;
plot(x, y, '-ro','LineWidth', 5, 'MarkerSize', 18, 'MarkerEdgeColor', 'r')
xlabel('Numbers', 'FontSize', 12)
ylabel('Results', 'FontSize', 12)




By adding the text ‘-ro’ (r for red and o for circle) sets the line color to red and adds circular markers at each specified point.  The size of the marker is determined by the “‘MarkerSize’, x,” script additionally the edge color of the marker be set using the “‘MarkerEdgeColor’, x,” although in this case it matches the line color.

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

The addition of the semi-colons between the values of x makes no visible change to the output of our script.  The reason for this is that the final semi-colon outside of our closing bracket suppresses the x values from being displayed in the command window.  If that final semicolon were removed the output of x would change from output 1 below to something closer to output 2 (please ignore any vertical alignment issues).

1.)   x = 
         Columns 1 through 5
                        1 2 3 4 5   

2.)  x = 
              1
              2
              3
              4
              5


  10.  Provide the code for the following figure. You need to figure out the function for y. Notice there are grids on the plot.



Below is the code and output we came up with to mimic the figure shown above.

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)




To achieve the output above we changed the ‘-or’ script to ‘:sk’ (: for a dotted line, s for square markers and k for the color black).

  11.  Degree vs. Radian in MATLAB:
a.       Calculate sinus of 30 degrees using a calculator or internet.

sin(30°) equals 1/2 or 0.5 on my TI-Nspire Calculator
b.      Type sin(30) in the command line of the MATLAB. Why is this number different? (Hint: MATLAB treats angles as radians).

In MatLab sin(30) equals -0.9880.  This is because sin(x) function in MatLab looks at x as a radian value.
c.       How can you modify sin(30) so we get the correct number?

To find the value of sin(30 degrees) in MatLab use the sind(x) function.  When sind(30) is input into MatLab  you get the following result.

>> sind(30)

ans =

    0.5000

  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:

Below is the code and output we came up with to mimic the figure shown above.

clear all;
close all;
t = linspace(0,pi/25,1000);
x = linspace(0,pi/25,10);
y = 10*sin(100.*t);
z = 10*sin(100.*x);
plot(t, y, '-k','LineWidth', 1)
hold on
plot(x, z, '-or','LineWidth', 1, 'MarkerSize', 5)
hold off
xlabel('Time', 'FontSize', 12)
ylabel('Line Function', 'FontSize', 12)




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

The change in this figure is that the maximum y value of the “Fine” plot has its maximum value capped at 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.

Below is the code and output we came up with to mimic the figure shown above, using the find command to cap the Fine plot’s y value at 5.

clear all;
close all;
t = linspace(0,pi/25,10);
y = 10*sin(100.*t);
plot(t, y, '-or','LineWidth', 1, 'MarkerSize', 10)
hold on
x = linspace(0,pi/25,1000);
y = 10.*sin(100.*x);
k = find(y>5);
y(k)= 5;
plot(x,y,'-k')
legend('Coarse','Fine',0);
xlabel('Time (s)', 'FontSize', 12)
ylabel('y function', 'FontSize', 12)




 15.  Create a code that would clip the negative part of the sinusoidal signal for the fine plot to -5.

Below is the Code, and output I wrote to clip the limit the minimum y value of the Fine plot to -5.

clear all;
close all;
t = linspace(0,pi/25,10);
y = 10*sin(100.*t);
plot(t, y, '-or','LineWidth', 1, 'MarkerSize', 10)
hold on
x = linspace(0,pi/25,1000);
y = 10.*sin(100.*x);
k = find(y>5);
j = find(y<-5);
y(k)= 5;
y(j)= -5;
plot(x,y,'-k')
legend('Coarse','Fine',0);
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.

Table B-1

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.

Below is the Code, and output we wrote Displaying the output of Table B-1.

clear all;
close all;
vin = [5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94];
vout = [5.89 4.39 2.88 2.03 1.57 1.28 1.07 .929 .813 .656 .267];
x = [30 200 400 600 800 1000 1200 1400 1600 2000 5000];
y = vout ./ vin;
plot(x, y, '-ro','LineWidth', 2, 'MarkerSize', 8, 'MarkerEdgeColor', 'k')
xlabel('Frequency', 'FontSize', 12)

ylabel('Vout / Vin RMS', 'FontSize', 12)


Low Pass Filter Output 

3.  Calculate the cut off frequency using MATLAB. find command will be used. Provide your code.

Below is the Code, and output we wrote to calculate our filter's cutoff value.

clear all;
close all;
vin = [5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94];
vout = [5.94 5.86 5.61 5.26 4.88 4.48 4.12 3.79 3.49 2.99 2.12 1.64];
x = [30 200 400 600 800 1000 1200 1400 1600 2000 3000 4000];
y = vout ./ vin;
plot(x, y, '-ro','LineWidth', 2, 'MarkerSize', 8, 'MarkerEdgeColor', 'k')
xlabel('Frequency', 'FontSize', 12)
ylabel('Vout / Vin RMS', 'FontSize', 12)
k = find (vout>5.94*.65, 1, 'last')
x(k)

Output

>> w10B1
k =  7
ans = 1200

>> 

We were not entirely surprised that the cutoff was around 1200 Hz as opposed to the expected 1.0 kHz.  The reason for this was although our capacitor was labelled as 22 nF our DMM showed it to actually be close to 18 NF and when calculated

1/(2*pi*7230 Ohms*18E-9 NF) =1222 Hz

 4.  Omitted, Not required for Team Blog

 5.  Repeat 1-3 by modifying the circuit to a high pass filter.

   We modified our circuit to construct a high pass filter similar to the one we worked with in week 9 by placing our capacitor in series between our Frequency Generator and Resistor.  

    1B.  Build a high 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.

Table B-2 Below shows the data we collected as request in step 1B


Table B-2

    2B.  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.


Below is the Code, and output we wrote to calculate our filter's cutoff value.

clear all;
close all;
vin = [5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94];
vout = [5.89 4.39 2.88 2.03 1.57 1.28 1.07 .929 .813 .656 .267];
x = [30 200 400 600 800 1000 1200 1400 1600 2000 5000];
y = vout ./ vin;
plot(x, y, '-ro','LineWidth', 2, 'MarkerSize', 8, 'MarkerEdgeColor', 'k')
xlabel('Frequency', 'FontSize', 12)
ylabel('Vout / Vin RMS', 'FontSize', 12)

High Pass Filter Output




3B.  Calculate the cut off frequency using MATLAB. find command will be used. Provide your code.

clear all;
close all;
vin = [5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94 5.94];
vout = [.261 1.02 1.95 2.78 3.41 3.91 4.29 4.59 4.82 5.14 5.53];
x = [30 200 400 600 800 1000 1200 1400 1600 2000 3000 4000];
y = vout ./ vin;
plot(x, y, '-ro','LineWidth', 2, 'MarkerSize', 8, 'MarkerEdgeColor', 'k')
xlabel('Frequency', 'FontSize', 12)
ylabel('Vout / Vin RMS', 'FontSize', 12)
k = find (vout>5.94*.7, 1, 'first')
x(k)

Output

>> w10B1
k =  7
ans = 1200

>> 

Once again MatLab calculated our cutoff frequency to 1200 Hz.  Again this is not surprising as the formula for calculating the cutoff frequency is the same in both High and Low Pass Capacitive Filter, so;  

1/(2*pi*7230 Ohms*18E-9 NF) 

still equals 1222 Hz in our High Pass setup.



Please feel free to comment below and we will be back again next week

Lab Team 4 Out


Sunday, March 20, 2016

Lab Team 4 Week 9



Blogsheet week 9

    1. Measure the resistance of the speaker. 
          
  We measured the speaker's resistance at 8.3 Ω, which is not surprising since 8 Ω  is an excepted industry standard for commercial speakers.  


    2. Build the following circuit using a function generator setting the amplitude to 5V (0V offset). What happens when you change the frequency? (video)


Figure 1: Test setup for the speaker.


Video demonstrating the circuit above.


Table 1: This table displays our observations we had while changing the frequency in the above circuit.




TABLE 1

Frequency
Observation
300 Hz
Low pitch hum/vibration only audible at a very short distance
500 Hz
Steady audible tone, also only audible at a short distance
1.0 kHz
High Pitch Tone, audible for several feet similar to an emergency broadcast tone
1.5 kHz
Similar to the 1.0 kHz tone but at a slightly higher pitch
12.5 kHz
Tone reaches peak volume and becomes uncomfortable to listen too.

* At around 14 kHz the tone became so high pitch it was difficult to hear.


      3.  Add one resistor to the circuit in series with the speaker (first 47 Ω, then 820 Ω).  Measure the voltage across the speaker. Briefly explain your observations.

Table 2: This table shows our observations as well as the oscilloscope output of the above circuit with an added resistor at a frequency of 1 kHz.


TABLE 2

Resistor value
Oscilloscope output
Observation

47 Ω
Sinusoidal Wave with 820 mV peak to peak Voltage.
High pitch tone with no noticeable difference from 



820 Ω
Sinusoidal Wave with 123 mV peak to peak Voltage, with significantly more distortion than the 47Ω resistor.
Significant Decrease in volume from both the Table 1 and 47Ω configurations. 


    4. Build the following circuit. Add a resistor in series to the speaker to have an equivalent resistance of 100 Ω. Note that this circuit is a high pass filter. Set the amplitude of the input signal to 8 V. Change the frequency from low to high to observe the speaker sound. You should not hear anything at the beginning and start hearing the sound after a certain frequency. Use 22 nF for the capacitor.


Figure 2: Test setup for the high pass filter.

     a. Explain the operation.  (video)


This video demonstrates our high pass filter circuit and how it works


    b. Fill out the following table by adding enough (10-15 data points) frequency measurements. V-Out is measured with the DMM, thus it will be RMS value.




     c. Draw V-Out/Vin with respect to frequency using Excel.

V-In/V-Out vs Frequency plot from MS Excel.


    Observation:
    The results we observed did not match our expectations for a High-Pass filter.  We expected the graph to slope steadily upward as the filter allowed more voltage to pass as the input frequency increased, until it reached a peak output and level off.  Instead after reaching it's peak the graph begins a steady linear decline.

    d. What is the cut off frequency by looking at the plot in b?
     
Two cutoff frequencies at approximately 5 & 40 kHz.  This can be determined by looking at the point the V-Out/V-In ratio equals 1/2 of it's peak which occurs at the filter's mid-range frequency. 

    5. Design the circuit in 4 to act as a low pass filter and show its operation. Where would you put the speaker? Repeat 4a-g using the new designed circuit.
     
      a. Explain the operation.  (video) 


A Schematic of our Low Pass Circuit.


This video displays our low pass filter and how it is operated.

b. Fill out the following table by adding enough (10-15 data points) frequency measurements. V-Out is measured with the DMM, thus it will be RMS value.




c. Draw V-Out/V-In with respect to frequency using Excel. 
V-In/V-Out vs Frequency plot from MS Excel.
Observation:
This graph above shows the data we collected.  Because our circuit is a  Low-Pass filter as the frequency of the signal increased less of the voltage was allowed to pass through the filter.  On a practical level as our video demonstrates the speaker's volume decreases steadily and  significantly after peaking at the mid-range frequency.

d. What is the cut off frequency by looking at the plot in b? 

The cutoff frequency is at approximately 30 kHz.  This can be determined by looking at the point the V-Out/V-In ratio equals 0.5, or 1/2 the mid-range output. 

   6. Construct the following circuit and test the speaker with headsets. Connect the amplifier output directly to the headphone jack (without the potentiometer). Load is the headphone jack in the schematic. “Speculate” the operation of the circuit with a video.   


This video shows our microphone and headphone circuit in action, along with an explanation of how it works.

   We speculate the resistors and capacitor between the microphone and Op-Amp acts a Low Pass Filter.  This allows the Microphone to send a clean signal into the Op-Amp which then amplifies that signal and sends it to the Headphone  Jack with sufficient strength to be audible through a set of headphones.