Lab 4 Procedure FA23

pdf

School

University of California, San Diego *

*We aren’t endorsed by this school

Course

170

Subject

Aerospace Engineering

Date

Dec 6, 2023

Type

pdf

Pages

15

Uploaded by GeneralFlowerDragon7

Report
MAE 170 [FA23]: LAB 4 Conditioning Signals: RC filters, Amplifiers, and Transfer Functions Submit your answers to the questions posed in this lab to gradescope and turnitin via the Canvas course website by 11:59 pm (midnight) the evening before your next lab section. Learning objectives: LLO4-1: Understand the use of RC circuits in filtering signals (both high pass and low pass), and be able to characterize their behavior and effect on varied input signals. LLO4-2: Understand the use of an amplifier which incorporates an Operational Amplifier (opamp), be able to characterize its behavior, and understand its use in signal processing/conditioning. LLO4-3: Understand the effect of cascaded analog signal conditioning elements. LLO4-4: Be able to construct and interpret transfer functions and frequency domain information. LLO4-5: Be able to use normalization to extract system parameters from data fitting. LLO4-6: Understand how, and be able, to communicate context and motivation for your work in a technical writing scenario. LLO4-7: Be able to generate a clear figure with high information density for communicating the results of your work. LLO4-8: Understand what works and what doesn’t in summarizing experiments. LLO4-9: Become comfortable with automated signal collection and analysis. LLO4-10: Gain experience with norms and ethics in signal conditioning, data analysis and data presentation. 1
PRE-LAB View the Arduino Lecture 4 video , paying particular attention to the section on library usage. View the Lab 4 demonstration video . Read the following via the custom course textbook: Part A. 4, 10, 11, 16 Review the Arduino following commands: digitalWrite() % (modulo) millis() Ensure you have at least the 2019 version of Matlab installed. Read the following Matlab tutorials Fourier transforms: https://www.mathworks.com/help/matlab/math/fourier-transforms.html https://www.mathworks.com/help/matlab/ref/fft.html https://www.mathworks.com/help/signal/ref/periodogram.html Curve fitting toolbox (ensure that the curve fitting toolbox is installed to Matlab): https://www.mathworks.com/help/matlab/ref/polyfit.html https://www.mathworks.com/help/matlab/math/polynomial-curve-fitting.htm Smoothing https://www.mathworks.com/help/curvefit/smooth.html We expect that you have read, in detail, the lab instructions before coming to the lab. 2
IN-LAB Part I: Characterize RC filters via their transfer function A “transfer function” relates a system’s outputs to their inputs. In control theory it has a specific meaning, however, it is also often used interchangeably with terms such as “transmission function” or “transmission spectrum” or “Bode plot”. In this class, we will use “transfer function” in the context of this general “transmission function/spectrum or Bode plot”. The transfer function is often expressed in the frequency domain (thus a spectrum), such that the amplitude of the transfer function is a function of frequency. In this part, you will measure the transfer function of low and high-pass RC filters by sending signals of gradually increasing frequencies and measuring the signal’s amplitude before and after it passes through the filter. To do this, you will work with your partner to set up two Arduinos. The first Arduino will act as an oscilloscope, similar to what was done in Lab 3. In this case, the Arduino will acquire two signals simultaneously (one for the input to the filter and one for the signal that is output from the filter). The output will be channel A0 on the Arduino, and the input (or reference) signal will be sent to channel A1. Upload the following code to the first (the “read”) Arduino. // Arduino two-channel serial read script // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 115200 bits per second: Serial.begin(115200); } // the loop routine runs over and over again forever: void loop() { Serial.print(analogRead(A1)); Serial.print(", "); Serial.print(analogRead(A0)); Serial.print("; "); Serial.println(micros()); } Set up your second (the “write”) Arduino and connect a MCP4725 I2C Digital to Analog Converter chip, as shown in Fig. 1. This chip enables the Arduino to act as a signal generator. The VOU pin with the blue wire will serve as the positive side of the generated signal, and the black wire coming from the GND pin will serve as the ground. The 5 V source from your Arduino should be connected to the VDD pin on the MCP4725 I2C Digital to Analog Converter chip as a power source (red wire). The SCL and SDA pins on the MCP4725 I2C Digital to Analog Converter chip should be connected to Analog In pins A5 (yellow wire) and A4 (white wire), respectively, on your Arduino. Upload the following script to your second (“signal generator”) Arduino to run 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
the signal generator. Make sure the specified libraries, as well as the ‘Adafruit Bus IO’ library , are added via the sketch->include libraries->manage libraries menu in the Arduino interface. Figure 1: Photo of electrical connections for your “write” Arduino. // NOTE: This script requires two open source packages in order to run. // To install these packages, navigate to Sketch > Include Library > Manage Libraries // and search for and install the following: // * Adafruit BUSIO // * Adafruit MCP4725 #include <Wire.h> // I2C library #include <Adafruit_MCP4725.h> // MCP4725 library Adafruit_MCP4725 dac; //invoke the MCP4725 library float freq = 0, volts = .5, vavg = 1.0; // initialize frequency and voltage variables int counts = 4095; // initialize counts and max voltage variables double pi = 3.14159; // set pi String freq_str = " "; // initialize frequency string variable void setup() { dac.begin(0x62); // set I2C address 4
Serial.begin(115200); // start serial reader } void loop() { while (Serial.available() > 0) { // loop while there are strings in read buffer freq_str = Serial.readString(); // read the signal frequency Serial.println(freq_str); // print out the frequency to the serial monitor freq = freq_str.toFloat(); // convert the frequency read on serial to float type } dac.setVoltage(counts / 5 * (volts * sin(2 * pi * freq * micros() / 1E6) + vavg), false); // drive a sine wave with amplitude volts, and offset max voltage / 2 } Figure 2 : Low-pass filter circuit with Read & Write Arduinos Before we characterize a device, it is recommended to ensure your characterization tools are functioning as they should. To do this, connect the generated signal output directly to the “read” ports on the second Arduino. The GND terminal of the first Arduino (“read”) should also be connected to the GND side coming out of the Arduino signal generator via the protoboard. The blue wire from the VOU pin should be connected to the A0 and A1 terminals on the “read” Arduino via the protoboard. Connecting via the protoboard allows the placement of filters or other devices in between the output and measurement channels, so that their behavior may be studied. Next, use the following Matlab script to control the two Arduino’s and plot the transfer function of the system being characterized. Ensure that the COM ports (highlighted in yellow) are set to match those of the 5
Arduinos. Note that the parameters at the top can be adjusted (also highlighted in yellow). A text version of the code below is provided on canvas. clc; clear all ; close all ; instrreset; %% Parameters to set T = 2; % Total sampling time in seconds fs = 1000; % sampling frequency target in Hz f_min=1; % minimum frequency to be characterized in Hz f_max=30; % maximmum frequency to be characterized in Hz f_step=1; % frequency step in Hz %% f_vec=[f_min:f_step:f_max]; % initialize vector for frequency sweep transfer_vec=zeros(length(f_vec),1); % initialize transfer function vector for j=1:length(f_vec) % loop over each frequency to be tested % create the serial objects % you must replace the port name with the port on your machine % you can find this through the arduino interface (tools->port) % the baud rate must match what you selected in your serial read ... % Ardino code % the first serial object, s_gen, corresponds to the Arduino acting ... % as your signal generator % the second serial object, s_read, corresponds to the Arduino ... % acting as your oscilloscope % open object for your signal generator arduino % this segment sets the frequency of the generated signal s_gen = serial( 'COM11' , 'BaudRate' ,115200); fopen(s_gen); % open the serial connection pause(5); % pause for 5 seconds while the serial object is opened fprintf(s_gen, '%s' ,int2str(f_vec(j))); % write the signal frequency fclose(s_gen); % close serial object pause(2); % open object for your "read" arduino s_read = serial( 'COM9' , 'BaudRate' ,115200); fopen(s_read); % opens said serial object flag=0; %set flag for timer i=1; % set sample counter dt_set=1/fs; % set time step target timer=0; % initialize timer L=T*fs*2; % oversized vector length time=zeros(L,1); % initialize time vector A=zeros(L,1); % initialize amplitude vector A_ref=zeros(L,1); waittime=2; %set initial wait time before sampling in seconds t=0; % initialize time variable ind=0; % initialize index variable ind_ref=0; a=0; % initialize amplitude variable a_ref=0; 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
dump= '' ; % initialize text dump variable out= '' ; % initialize serial output string variable tic; % start timer while toc<waittime % read and dump serial data until wait time is reached dump=fscanf(s_read); end while flag==0 out=fscanf(s_read); % reading the serial port ind_ref=find(out== ',' ,1); % find index of comma ind=find(out== ';' ,1); % find index of semi-colon a=str2double(out(1:ind_ref-1)); % get amplitude of output signal % get amplitude of reference signal a_ref=str2double(out(ind_ref+2:ind-1)); t=str2double(out(ind+2:end))/1E6; % get time % condition to take sample at set sampling rate if (t-timer)>dt_set time(i) = t; % establishing time steps for sampling frequency A(i)=a; % add signal amplitude to signal amplitude vector A_ref(i)=a_ref; % add reference amplitude to vector timer=time(i); i=i+1; % condition to end loop when end time is reached if t>(T+time(1)) flag=1; end end end fclose(s_read); % closes serial port for "read" arduino reps=i-1; % get number of samples acquired time = time(1:reps)-time(1); % setup a vector for time % convert serial amplitude to voltage voltage = 5/1023*A(1:reps); % convert serial amplitude to voltage for reference signal voltage_ref = 5/1023*A_ref(1:reps); % find the average time interval between samples dt_avg = mean(diff(time)); fs_avg=1/dt_avg; % calculate the average sampling frequency from dt_avg %% Create plot figure(01); % setup figure 01 % plot time vs. voltage for output signal subplot(221) plot(time, voltage(1:reps), '-o' , 'LineWidth' ,2, 'MarkerSize' ,4); xlabel( 'time (s)' ); % x-axis label name ylabel( 'voltage (V)' ); % y-axis label name ylim([min(voltage)-abs(0.1*max(voltage)) ... max(voltage)+abs(0.1*max(voltage))]); % set y plot range title([ 'f_{s,average}=' num2str(round(fs_avg)) ' Hz' ]); % set title as sampling rate % get current plot axes, set font and line width set(gca, 'FontSize' ,22, 'LineWidth' ,2); set(gcf, 'units' , 'normalized' ); % set plot sizing to normalized units % plot time vs. voltage for reference signal subplot(222) plot(time, voltage_ref(1:reps), '-ok' , 'LineWidth' ,2, 'MarkerSize' ,4); xlabel( 'time (s)' ); % x-axis label name ylabel( 'voltage (V)' ); % y-axis label name ylim([min(voltage_ref)-abs(0.1*max(voltage_ref)) ... max(voltage_ref)+abs(0.1*max(voltage_ref))]); % set y plot range 7
title( 'Reference signal' ); % set title as sampling rate % get current plot axes, set font and line width set(gca, 'FontSize' ,22, 'LineWidth' ,2); set(gcf, 'units' , 'normalized' ); % set plot sizing to normalized units % calculate Power spectral density (PSD) for the output signal [PSD,f_psd] = periodogram(voltage-mean(voltage),rectwin(reps), ... reps,fs_avg, 'onesided' ); FT=sqrt(PSD); % convert Arduino PSD to Fourier magnitude [FT_max,ind_max]=max(FT); % find the maximum of the output signal FT % calculate Power spectral density (PSD) for the reference signal [PSD_ref,f_psd] = periodogram( ... voltage_ref-mean(voltage_ref),rectwin(reps), ... reps,fs_avg, 'onesided' ); FT_ref=sqrt(PSD_ref); % convert Arduino PSD to Fourier magnitude % find the maximum of the reference signal FT [FT_max_ref,ind_max_ref]=max(FT_ref); % calculate the transfer function value at this frequency % e.g. the output divided by the input transfer_vec(j)=FT_max/FT_max_ref; % plot the FT spectra for the output and reference signals subplot(223) plot(f_psd,FT_ref, 'k-o' ,f_psd(ind_max_ref),FT_max_ref, 'gx' , ... f_psd,FT, 'b-o' ,f_psd(ind_max),FT_max, 'rx' , ... 'LineWidth' ,2, 'MarkerSize' ,4); xlabel( 'frequency (Hz)' ); % x-axis label name ylabel( '|FT|' ); % y-axis label name title([ 'FFT of AC signals (f_{in}=' int2str(f_vec(j)) ' Hz)' ]); % set title as sampling rate xlim([0 f_max*2]); % get current plot axes, set font and line width set(gca, 'FontSize' ,22, 'LineWidth' ,2); set(gcf, 'units' , 'normalized' ); % set plot sizing to normalized units % plot the transfer function subplot(224) plot(f_vec,transfer_vec, 'r-o' , 'LineWidth' ,2, 'MarkerSize' ,4); xlabel( 'frequency (Hz)' ); % x-axis label name ylabel( '|FT|_{max}/|FT|_{max,ref}' ); % y-axis label name title( 'Transfer Function' ); % set title as sampling rate xlim([f_min f_max]); % get current plot axes, set font and line width set(gca, 'FontSize' ,22, 'LineWidth' ,2); set(gcf, 'units' , 'normalized' ); % set plot sizing to normalized units % set position of figure on screen [distance from left, top, width, height] set(gcf, 'Position' , [0.1, 0.1, .6, 0.8]); drawnow; pause(2); end % Be sure to change filenames if you don’t want to overwrite your data! save( 'MAE170_lab4' , 'f_vec' , 'transfer_vec' ); % save frequency and gain to mat file 8
csvwrite( 'MAE170_lab4.csv' ,[f_vec',transfer_vec]); % save frequency and gain to csv file saveas(gcf, 'MAE170_lab4' ); % save figure The previous Matlab code is very similar to that used in Lab 3 to study aliasing, with the addition of the second (reference) channel. Because we are using inexpensive (Arduino) devices, the sampling rates achievable are relatively low. For this example, you will be aiming for a sampling rate of your measurement of ~1 kHz, and characterizing the signal frequency range of 1 to 30 Hz (in steps of 1 Hz). The amplitude of the generated signal is preset into the signal generator Arduino code. Given that your output and input are the same for this initial step, you should observe that the transfer function is equal to one across the frequency range measured. Now that you have ensured your characterization tool is acting as they should, you will attempt to characterize a low-pass filter, as shown below in Fig. 2. The circuit should be placed in-line with the characterization system, such that the positive output of the signal generator Arduino goes through your filter before being measured on channel A0 of the “read” Arduino. Use a 10 k and a 1 F ( or a 1 k resistor and a 10 F capacitor µ µ if you already started the lab before the updated instructions were posted) to give a cutoff frequency in the 1 to 30 Hz range. Your Matlab code should generate .mat and fig files, for which the first contains the transfer function data for frequency in Hz vs. gain (two separate vectors), and the 2nd is the figure file of the last frequency characterized. Note that the figure only represents the last input frequency characterized. Figure 3: Low pass filter circuit diagram 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Q1: Normalize your transfer function (gain) data using the analytical equation for the gain of a low-pass filter such that the quantity plotted on the y axis is a linear function of frequency, and plot the normalized data (linear scale on both axes). Fit a line to this normalized data, and use the equation for the fitted line to experimentally determine the RC time constant for your filter. Turn in with your assignment: The normalized plot of your data, with the fitted line and its equation overlaid. The expected and (above) experimentally determined RC time constants. Comment on the difference between your expected and measured RC values, and suggest ideas regarding possible causes of any differences. Consider the resistor and capacitor’s tolerances. The resistor’s tolerance can be found from the color bands, and the capacitor’s tolerance is estimated at 20% via the specification sheet. Q2: Create another plot of your low-pass filtered data (this time without the normalization), and overlay on top a curve for the analytical transfer function expected using the gain equation and the experimentally determined RC time constant. Place a vertical dashed line at the identified -3 dB frequency and a horizontal dashed line at the -3 dB amplitude level. The -3 dB frequency is the frequency at which the output power is half the input power (where P=V 2 /R). Refer to the appendix for more information regarding the -3 dB frequency. Include with your assignment: Your plot. The -3 dB frequency and the expected cutoff frequency. Comment on how you might translate the tolerances specified in the previous problem to uncertainty bounds in the expected cutoff frequency. Technical accuracy will not be graded for this part of the question, we are just asking you to think about how the problem might be addressed. Comment also on how this might be presented in a figure, as relates to the expected gain curves. 10
Part II: Characterize a non-inverting amplifier Next, you will build a non-inverting amplifier circuit as is diagrammed in Fig. 3 using a 1 k resistor for both R 1 and R 2 . Figure 4: Schematic diagram for a non-inverting amplifier circuit, leveraging an opamp component (image taken from Wheeler and Ganji “Introduction to engineering experimentation”). Figure 4 shows the pin definitions for your MCP 6271 opamp. Pin #1 is located at the upper left corner adjacent to the small “half-moon” cutout. You can view a photo of the electrical connections in the Lab 4 demonstration video. Figure 5: Pinout diagram for the opamp. You will not use pins 1, 5, or 8. Characterize the transfer function of the non-inverting amplifier using the same method as the previous part. Note that an amplifier also has a cutoff frequency (similar to a low-pass filter), however it is occurring at a frequency higher than what we are measuring. 11
Figure 6: Non-inverting amplifier circuit with Read & Write Arduinos Q3: Turn in a plot of your measured transfer function with your assignment. How does this transfer function differ from the prior one, and why? How does your transfer function value compare to the analytically predicted gain of your amplifier? Discuss any differences observed, and possible causes. Part III: Technical Writing Assemble your low pass filter from Part I, and your amplifier from Part II in series. Characterize the combined circuit’s transfer function using the same method as the previous parts. Q4: Plot your measured transfer function, and overlay an analytically predicted curve based on your low pass filter’s cutoff frequency and the amplifier’s gain. Turn in this plot with your assignment. Make sure to construct your figure in the context of the WLO2 dimensions. Purpose: to gain practice presenting data visually in an accessible and information dense manner. How does this transfer function differ from the prior ones, and why? 12
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Q5: This question pertains to WLO3. Main task: Assess the comparative strengths of three technical writing samples . Three samples of technical writing have been provided to you on canvas under Writing and Learning Objective . These three samples contain introductions describing the context of a prior version of Lab 3 (the same as the results/discussion sections you reviewed as part of Lab 1). These three writing samples should be considered small components of a larger technical lab report or academic paper. Critique the three writing samples and compare their efficacy in the context of technical writing learning outcome 3 (WLO3) dimensions discussed in class (and listed below, for your reference). Purpose: To gain perspective on what works, and what doesn’t, in technical writing. WLO3: Be able to accurately convey the context and novelty of your work [Introduction section]. General introduction to the topic provided, followed by a more in-depth background related to your work/experiment (e.g.: What physical phenomena is being explored?). Description of context has appropriately sized scope (not too broad or too narrow) to introduce a reader to what you are doing. Text is appropriately referenced. All necessary claims are supported with review articles, books, or a first study on a particular subject/statement. One clear, persuasive knowledge gap, problem statement, or objective is established. Preferably in one sentence. A statement precisely specifying/summarizing what was done in the work (preferably in one sentence). Typically, this will be responsive to the prior stated knowledge gap. By construction, in conjunction with the prior stated knowledge gap, this should make clear the current work’s importance. A brief summary of what was done in the experiment/study is provided in order to establish context (significantly shorter than would be used to reproduce your results) [this can extend between the end of the introduction and the beginning of the results section] Q6: This question pertains to WLO3. Main task: Based on the textbook reading you have been assigned to date, outline the context of the experiment and analysis performed in this lab (Lab 4) by providing one sentence each that describes: The general area. Background specific to this experiment. The motivation or knowledge gap. What you did. Purpose: to gain practice accurately conveying the context and novelty of your work. . 13
Q7: This question pertains to WLO4. Main task: Assess the comparative strengths of three technical writing samples . Three samples of technical writing have been provided to you on canvas under Writing and Learning Objective These three samples contain abstracts describing the context of a prior version of Lab 4. These three writing samples should be considered small components of a larger technical lab report or academic paper. Critique the three writing samples and compare their efficacy in the context of technical writing learning outcome 4 (WLO4) dimensions discussed in class (and listed below, for your reference). Purpose: To gain perspective on what works, and what doesn’t, in technical writing. WLO4: Be able to effectively summarize your work and its contribution [Abstract section]. - Articulates a brief introduction of the topic that encompasses historical background and/or motivation. - Concisely states what your work is about and what you did (~1 sentence: “In this work, we studied this phenomenon ...). - Includes a clear and brief statement of the approach/methods used. - Provides a brief but comprehensive summary of the most important results (not overly quantitative to the point where important take-aways are obfuscated). - Articulates significant implications of the work and meaningful potential broader impacts. - Summary is written such that a scientist/engineer outside of your discipline can understand generally what you did, why you did it, and your main conclusion. - Can understand the content being summarized without the summary statement, thus, the abstract should not include any information that is not included in the main content. APPENDIX: The -3dB frequency: Where does it come from? Why is it useful? How can you measure it? The “bel” is a unit of measure defined as the base 10 logarithm of a ratio of two quantities, and was named after Alexander Graham Bell, the American developer of the earliest telephones. The decibel (dB) is 1/10 of a bel. Electronic components and circuits have frequency-limited responses. That is, as the input signal increases in frequency, the ability of the circuit to completely ‘follow’ the input is diminished. For circuits such as low-pass filters or opamp circuits, their response varies between the passband , where the input signal is (nearly) preserved, to the stopband where the output is increasingly attenuated. The cutoff or corner frequency or the “ -3dB frequency ” has been defined as the 14
border between pass and stop bands, and is the point where the output power from the circuit is ½ the input power. This can be expressed as: Power gain = Power out / Power in. Since power varies as voltage squared we can also write Power gain = V 2 out / V 2 in . Therefore the half power point, in terms of voltage, is when 1 /√ 2 = V out / V in . Now we can write the logarithmic form using the voltage ratio: Gain f-3dB = 20 log 10 (V out / V in ) dB such that Gain f-3dB = -3.01 dB. Why use dB? The dynamic range of the V out / V in ratio can vary over a very large range. Expressing the ratio logarithmically in dB gives us a way to more easily handle this large variation. Experimentally determining the -3 dB frequency. Considering a sine wave signal input, a practical definition of the -3 dB corner frequency is the frequency at which the voltage ratio (V out / V in ) is equal to 1/√2 or 0.707. For a low-pass situation this frequency can be experimentally determined by inputting a ‘slow’ sinewave of a given amplitude and then gradually increasing the frequency until the output amplitude drops to 0.707 times the input amplitude. For a high-pass situation start with a high frequency and work backward. An example transfer function for a low pass filter, with the -3 dB point identified is shown in Fig. A1. Figure A1: Transfer function of a low pass filter. Acknowledgements Appendix (N. Busan, S. Roberts, R.Kapadia (2011), S. Roberts (2013-2018)). Some elements of the lab instructions have been adapted from prior MAE170 iterations. 15
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help