• No results found

Lab 2 Report and Homework Phy122 2016

N/A
N/A
Protected

Academic year: 2020

Share "Lab 2 Report and Homework Phy122 2016"

Copied!
8
0
0

Loading.... (view fulltext now)

Full text

(1)

Lab #2 Report: Analog Input and Output – Fall 2016

Student Name: Lab Partner:

Exercise 1: Test analog input with MAX - Show the instructor or TA that your program works

Exercise 2: Test analog output with MAX - Show the instructor or TA that your program works

Exercise 3: Hardware-Timed Analog Input - Show the instructor or TA that your program works

a) How fast can you acquire data? Does it agree with the advertised specifications of the USB-6212 card? (Note that you can access the DAQ assistant configuration window by double clicking on the DAQ Assistant icon).

b) How many data points can you collect at the highest rate?

c) Determine whether the maximum possible speed of data acquisition is affected by recording two channels together.

Exercise 4: Repeated Hardware-Timed Input with Triggering - Show instructor or TA that program works

Exercise 5: Point-by-Point Analog Input - Show the instructor or TA that your program works

a) About how fast does this program acquire data? Wire up the while loop index "i" to an indicator to see how many points get acquired. Use a clock or stopwatch to figure out roughly how many points get acquired in 10 seconds. Note that the may vary for different computers, depending on the computer's speed.

b) Add code to write the data to a text file (recall the function we used in Lab #1). Does this affect the rate of data acquisition?

c) The above method of acquisition is "software timed" and is usually not very accurate except possibly at low sampling rates. More accurately timed acquisition can be done by configuring the DAQ assistant for acquisition mode "1 sample (HW timed)", meaning "hardware timed", where the timing is controlled by circuits on the DAQ card, rather than by Labview. However, in this case if you try to acquire faster than Labview can respond, the program will crash. Test this and determine how fast can you acquire data?

(2)

Exercise 6: Faster Point-by-Point Analog Input (using DAQmx) - Show the instructor or TA that your program works

(3)

b) If you add a "Write to measurement file" function (set to write a text file with only one header) does this slow down the maximum acquisition rate?

Exercise 7: Continuous (Buffered) Analog Input - Show the instructor or TA that your program works

a) How many measurements per second are recorded if the program is set up as shown above?

b) How often is the waveform graph redrawn when set up as shown above?

c) How often is the graph redrawn if the number of samples is set to 100?

Exercise 8: Analog Output (with DAQ Assistant) - Show the instructor or TA that your program works

Exercise 9: Analog Output Based On Analog Input - Show the instructor or TA that your program works

(a)How much lag is there between the acquired signal and output signal?

Homework and Pre-lab questions for Lab #2

Relevant references (posted on the class website under the "Labview" link):

 "NI USB-6212 Devices Specifications.pdf" (and "NI DAQ Specifications Glossary.pdf")  "DAQ M Series User Manual.pdf" (also note glossary at end of manual)

 "Wiring and Noise Considerations.pdf"  "Labview Analysis Concepts Guide.pdf"

1. Answer the following further questions about the specifications of the USB-6212 data acquisition card.

a) What does "ADC resolution 16 bits" on the spec sheet for Analog Input mean?

b) If the analog input range is set to ±0.2 volts, what is the smallest voltage change that can be measured?

2. Answer the following questions about electrical wiring and noise (brief answers of 1-2 sentences are fine)

(4)

a) What is "ground-loop induced noise" and how can it be minimized? (you may quote from the "Wiring and Noise Considerations" Guide)

a) How can you minimize conductively coupled noise? (you may quote from the "Wiring and Noise Considerations" Guide)

b) How can you minimize capacitively coupled noise? (you may quote from the "Wiring and Noise Considerations" Guide)

c) How can you minimize inductively coupled noise? (you may quote from the "Wiring and Noise Considerations" Guide)

(5)

4. Answer the following questions about digital filtering (brief answers of 1-2 sentences are fine)

a) What is a "bandpass" filter?

b) What advantages do IIR filters have over FIR filters? (you may quote from the Labview Analysis Concepts Book)

c) What advantages do FIR filters have over IIR filters? (you may quote from the Labview Analysis Concepts Book)

d) Which type of IIR filter has a monotonic decrease in response (no ripple in the passband or stopband)?

5. Answer the following questions regarding frequency analysis (brief answers are fine)

a) What equation describes a "discrete Fourier transform" (DFT)?

b) Write out the X[0] expression for the DFT. How is this related to the mean value of the signal x?

(6)

c) If a signal is sampled at 1 kHz for 1 minute, what is the highest frequency that can be analyzed by DFT?

d) If a signal is sampled at 1 kHz for 1 minute, what is the lowest frequency that can be analyzed by DFT?

e) How is the power spectrum calculated from the DFT? (you may quote from the Labview Analysis Concepts Book)

(7)

g) Which window function is recommended by the "Labview Analysis Concepts" guide to be useful for most general purpose applications?

6. Use Matlab to demonstrate "aliasing" problems when sampling a signal

(a) Specify a sine wave of frequency fsig=13 Hz, with data points every dt=0.0001 sec, as follows

clear; close all; % specify signal

dt=0.0001; % choose time step

t=0:dt:100; % generate array of time points from 0 to 100 in steps of dt N=length(t); % number of time points in array

fsig=13; y=sin(2*pi*fsig*t); % calculate sin with frequency=13 subplot(2,1,1); % configure to plot two plots

plot(t,y); xlim([0 1]); % first plot with x-axis from 0 to 1 xlabel('signal'); ylabel('time (s)'); % add axis labels

Note that a comment follows each line (after %) to explain what the Matlab commands are doing. Look this program (and the ones below) over line by line and understand what they're doing. Looking thru example programs will help you learn Matlab. If it still seems foreign, read the "Matlab Primer" PDF manual.

(8)

Note that because the time between points is dt=0.0001 sec this signal has a "sampling frequency" Fs=1/dt=10000 Hz. This is high relative to the 13 Hz frequency of the signal, so the sine wave appears nearly continuous (is very well represented by the discrete set of point values).

Make sure the program runs.

(b) Add code to re-sample the signal at a lower frequency, by keeping only every 10th point of the original signal's t and y values, and plot these as red points over the original signal, as follows:

% sample signal by taking every kth point k=10;

tsamp=t(1:k:N); ysamp=y(1:k:N); % take every kth point dtsamp=k*dt; fsamp=1/dtsamp; % new dt and new frequency

hold on; plot(tsamp,ysamp,'r.'); % superpose on plot in red points xlabel('signal'); ylabel('time (s)');

Run the program. Note that the time between each point of the sampled signal is k*dt, so the sampling frequency is 1/(k*dt).

Questions:

(b1) When plotting every 10th point of the sine wave what is the sampling frequency, and does this still give a good representation of the signal?

(b2) Change the program so it only plots every 100th point of the sine wave. What is the sampling frequency now, and can you still see that the signal is an oscillation with frequency 13 Hz?

(b3) Change the program so it only plots every 500th point of the sine wave. What is the sampling frequency now, and can you still see that the signal is an oscillation with frequency 13 Hz?

(c) Add code to calculate the power spectrum (power spectral density vs. frequency) of the original signal (y), as follows.

% calcualte power spectrum (PSD) of signal

Fs=1/dt; % sampling frequency (# points per sec)

[PSD,freq] = pwelch(y,[],[],[],Fs); % see matlab help for pwelch subplot(2,1,2); % second plot

semilogy(freq,PSD); xlim([0 20]); % plot with log scale on y-axis, x-axis from 0 to 20 xlabel('frequency (Hz)'); ylabel('Power Spectral Density');

Run the program. You should see a sharp peak in the power spectrum at 13 Hz, because the signal is a sine wave with frequency 13 Hz.

(d) Add code to calculate and plot the power spectrum of the sampled signal in red on top of the original power spectrum.

Hints:

- Calculate PSD in the same way as for the original signal (cut-paste, with appropriate substitutions for Fs and y). - use "hold on;" before plotting to plot the second PSD on top of the first.

- use "semilogy(freq,PSD,'r')" to make second PSD red

(9)

(c1) Compare the PSDs with the sampled signal taking every 100th point of the sine wave. Copy the figure by selecting on the Edit > Copy Options on the Figure menu bar and select "Bitmap" and "Force white background". Then hit "OK" and then select Edit > Copy Figure. Then paste the figure into the box below (and click to resize)

(c2) Compare the PSDs with the sampled signal taking every 500th point of the sine wave. Copy the figure by selecting on the Edit > Copy Options on the Figure menu bar and select "Bitmap" and "Force white background". Then hit "OK" and then select Edit > Copy Figure. Then paste the figure into the box below

(10)

(c3) What is the sampling frequency when taking every 500th point? What is the apparent frequency of the signal according to the Power Spectrum?

(c4) What dominant frequency does the power spectrum show when the sampling frequency is more than twice the 13 Hz frequency of the signal, for example 27 Hz or higher?

(c5) What dominant frequency does the power spectrum appear to show when the sampling frequency is less than twice the frequency of the signal (here, 2*13 = 26 Hz)? Try 25 Hz, 24 Hz, 23 Hz, and 20 Hz? Do you see a relationship between the apparent dominant frequency in the power spectrum and |sampling frequency – 13|?

References

Related documents