Gas station without pumps

2014 May 1

Sampling and aliasing lab

Filed under: Circuits course,Data acquisition — gasstationwithoutpumps @ 21:30
Tags: , , , , , ,

Yesterday, I only briefly mentioned sampling and aliasing, which was the subject of today’s lab.  I was hoping they would read the handout, as that has some of the explanation missing from the lecture. That, as usual, turned out to be a forlorn hope. Some of them did read the handout, but not in a way that gained them any comprehension, and no one had done the prelab exercises, so the first hour (or more) of lab time was spent with students trying to figure out how to do a high-pass filter that did level shifting, so that the output would be in the 0–3.3V range of the analog-to-digital converter.  They all got to reasonable designs eventually (with capacitor values in the range 4.7µF to 470µF—I really like that the answer is not dictated by having only a small selection of components!).  I did have to re-teach Thévenin equivalents to some of the teams, as they were not getting the RC time constants that they claimed.

The level-shifting high-pass filter design will be useful again next week, for connecting the microphone to an op-amp audio amplifier.

I did not bring the stroboscope into lab as a demo—the demo had not worked all that well last year, and the students have all seen stroboscopes before.

PteroDAQ worked well for doing downsampling, and students recorded several waveforms.  I’ll see whether anything sensible is said about them in this week’s lab reports.  At least they had fun looking at the weird beat patterns you get if the signal you are looking at is close to the Nyquist frequency.

I also got the data today from the students who had a loudspeaker that behaved differently from everyone else’s on Tuesday (they tested another loudspeaker with the identical setup and got normal results, and I checked a few of their measurements—I believe they did just have a weird speaker).  There was a little metadata missing (like exactly what their fixed resistor was for converting current to voltage), but I was able to fit their data with just two more parameters on the model, a resistor and capacitor in parallel with each other, in series with the rest of the model:

    The bad loudspeaker has a higher than expected resistance at low frequency, then a 1/f-sloped region after the resonance peak, then a return to normal behavior. I modeled this loudspeaker by adding an extra R||C in series with the model we used for good loudspeakers.

The bad loudspeaker has a higher than expected resistance at low frequency, then a 1/f-sloped region after the resonance peak, then a return to normal behavior. I modeled this loudspeaker by adding and extra R||C in series with the model we used for good loudspeakers.

I have no explanation for the physical or electrical causes of an extra R||C in the loudspeaker.

2014 April 30

Loudspeaker analysis

Filed under: Circuits course — gasstationwithoutpumps @ 21:39
Tags: , , , ,

In class today, we analyzed the data that the students collected yesterday in the loudspeaker lab.

I used gnuplot to work through several model fits to the magnitude of impedance as a function of frequency.  The first one was a simple L+R model (though later we got even simpler with just R=8Ω). I showed the difference between fitting Z and fitting \log(Z).

The model clearly was a poor fit, though it has roughly the right shape, with a sort of constant region for a while, then rising impedance with frequency.

I next introduced (L_{s}||C_{s}||R_{s}) for the resonance peak, and showed how to fit those parameters without changing R or L for the main model, both by limiting the frequency range and by specifying only the parameters we wanted to optimize.  After fitting the resonance peak, I refit R and L over all the data.  This model did a decent job for lower frequencies, but still had problems at high frequencies.

I then mentioned one hack (that I have played with in the past) that is commonly used to model loudspeakers, of adding more “knees” to the curve to get a wobbly line that tracks the data a little closer.  I did not try to develop this in class, since we have no particular need to stick with standard linear components.

Instead I introduced them to a non-linear inductor, whose impedance is j \omega^{\alpha} L instead of j \omega L, and fit that after fitting the resonance peak.  (This is the same model I developed in Better model for loudspeaker, though the parameterization may be slightly different.)

Here is the plot we produced (note that it was not properly labeled—I expect the students to be able to do that themselves by now):

 Final fit developed in class today. I'm pretty happy with how close a fit we get with only 6 parameters.

Final fit developed in class today. I’m pretty happy with how close a fit we get with only 6 parameters.

I also mentioned the concept of a semi-inductor (the formula above with \alpha=0.5), and showed them how that fit (OK, but not as good as \alpha=0.627).

The model-fitting took a little longer than I had expected.  I’d wanted to spend 45 minutes on it, but spent more like 55.  I think that the lessons on how to fit parameters when they affect just part of the curve (as for the resonance peak), and the basic lesson that there are no true models, just more or less useful ones, were worth the time, though. We talked a little about when each of the models we used might be useful.

The R=8Ω model came up as being a useful one for signals between 200Hz and 10kHz—most of the audio range of interest for speech, but not so useful near the resonance peak or for high frequency.  I pointed out that we’d want to know the characteristics of the loudspeaker at high frequency later this quarter for the class-D power amp lab, which was why I went so far as to introduce non-textbook non-linear devices like the generalized inductor.

In the last 15 minutes of the class, I managed to talk a little about discrete values and discrete time, explaining what made a 16-bit ADC 16 bits, and emphasizing again the distinction between resolution, repeatability, and accuracy (resolution is 1LSB, repeatability for the ADC converters on the board we are using is about ±4LSB, and the accuracy is about ±3%, though the accuracy can be improved by external measurement of the reference voltage).

I only briefly mentioned sampling and aliasing, which they will be examining in tomorrow’s lab.  I’m hoping they read the handout, as that has some of the explanation missing from today’s lecture.  I’m still trying to decide whether to bring the stroboscope into lab as a demo.

Despite not covering aliasing and the Nyquist theorem today, I was pretty happy with how the class went.

Here is the gnuplot script developed in class today (it was all typed live in class without notes—hence the lack of comments and other niceties). Code was modified in place as we went through the different models, so many of the initial fits are not shown here.


zc(f,c) = 1/(j*2*pi*f*c)
zl(f,l) = j*2*pi*f*l

zsemi(f,l,alpha) = j * (2*pi*f)**alpha *l

zpar(z1,z2) = z1*z2/(z1+z2)  # parallel impedances

rlrlc(f, R, L, rs, ls, cs) = abs(R + zl(f,L) + zpar(zl(f,ls), zpar(zc(f,cs), rs)))
rlarlc(f, R, L, alpha, rs, ls, cs) = abs(R + zsemi(f,L,alpha) + zpar(zl(f,ls), zpar(zc(f,cs), rs)))

Rload = 47.171
set logscale xy


ls =1e-3
cs = 1e-3

fit [50:500] log(rlarlc(x,R,L,alpha,rs,ls,cs)) "" using 1:(log($3/$2 *Rload)) via rs,ls,cs

fit log(rlarlc(x,R,L,alpha,rs,ls,cs)) "" using 1:(log($3/$2 *Rload)) via R,L,alpha,rs

set samples 1000

plot "" using 1:($3/$2 *Rload) notitle, \
	rlarlc(x,R,L,alpha,rs,ls,cs)  title sprintf("%.3f ohm + %.3eH (^%.3f) + (%.3fohm || %.2fmH || %.2fuF)", R, L, alpha, rs, ls*1e3,cs*1e6)

2013 February 21

Sampling lab went ok

Filed under: Circuits course,Data acquisition — gasstationwithoutpumps @ 21:14
Tags: , , , , ,

Today’s sampling and aliasing lab was one I expected to go fairly quickly, but it took longer than I thought.  The students had two design tasks and then a bunch of observations. The design tasks were supposed to have been easy ones that they did as a prelab, but everyone took a bit longer than I thought, and some really struggled with them.

The first design task was to design a high-pass filter to do level shifting of a signal from a signal generator (the signal generator is capable of being set to center at a voltage other than 0v, but I needed students to practice level shifting before they do the class-D audio amplifier and the EKG labs).  I gave them a very low corner frequency (0.03Hz).  Students didn’t have trouble with the RC time constant (mostly), but they did have trouble with the notion of using a voltage divider as a Thévenin equivalent of a resistor to the desired center voltage, though we had just done that yesterday in class in analyzing the do-now problems.  I think that they all got it in the end, but I’ll definitely have to consider including some sort of level-shifting question on the quiz.

They looked at the signal output from the high-pass filter using the scope (to make sure that the voltage range was appropriate), then hooked it up to the Arduino and ran the DataLogger code.  I had them run the signal into two pins, with one sampling at 40Hz or 50Hz and the other at 1/5 that (8Hz or 10Hz), and then look at various frequencies.  I may have to specify some specific frequencies for them to look at next year, since they tended to pick simple multiples of 1Hz, which does not reveal some of the interesting beat patterns that you get at 4.9Hz and 5.1Hz.  The DataLogger code worked quite well for this application, though one student managed to tickle an error message by leaving the down-sampling field blank (it should probably default to 1 in that case, rather than reporting an error).  One could do all the visualization with a purely software simulation lab, but the students learned a fair amount by designing and wiring the RC filters, as well as getting more experience with the oscilloscopes and function generator.

The second design task was to design a low-pass filter with a corner frequency of 4Hz.  For this one, most of them chose to do a 2.5v virtual ground with an op-amp circuit, though there was no need, since the capacitor blocks any DC and so could have been connected directly to ground. Using a virtual ground actually makes it harder to use the electrolytic capacitors without reverse biasing them.  This may get to be important in the LC filter for the class-D amplifier, so I’ll probably have to talk about proper biasing of electrolytic capacitors in class.

I did do the strobe demo at the beginning of lab time, but it was not as good a demo as I had hoped to do.  I’ll have to think of ways to improve it for next year.  Problems included that the strobe light was not bright enough (you can’t turn off all the lights in the lab) and that the spinning paper propeller did not have an adjustable speed, so I couldn’t match the propeller to the strobe (just the strobe to the propeller).  Perhaps I need to choose a better moving object next year, where the strobe light will have a more obvious relationship to the sampling of sine waves in the rest of the lab.

Tomorrow I’ll need to start teaching about instrumentation amps, and get the students to choose lab partners to work with over the weekend, so that they can come in with questions on Monday, since the first instrumentation amp lab is likely to cause them problems.



2013 January 4

Parts and tools packaged today

Filed under: Circuits course — gasstationwithoutpumps @ 20:44
Tags: , ,

The breadboards finally came, so I was able to pack all the parts and tools into 2-gallon Ziploc bags—all except the LM2903 comparators that I just ordered today and the hysteresis lab PC boards, which I still have to cut apart on the board shears at work.  The parts come to $65.50 a student, rather than the $65 I told the students about earlier, because of the addition of the comparator, and because I included 10 EKG electrodes rather than 9 in each kit (they come in sheets of 10, so dividing them into 9 per student would have been tough).

My son and I bicycled up to campus today so that he could check the installation of the drivers and software on all 12 of the computers in the lab, and install the latest version of the data logger code.  He found a bug that is due to a limitation of Tkinter names for items on a selection list—they don’t like backslashes in the names.  He had been using the names of the USB ports as names for selections, but on Windows, the port names have backslashes in them. He did a quick patch so that he could finish the installation, but he’ll try for a cleaner fix this weekend (using a separate dict to map Tkinter names to port names). I want to start the class on Monday with a demo of the blinky EKG feeding my heartbeat to the Arduino for display to the class, to give them an idea of what they should be able to accomplish by the end of the quarter.  I’ll have to see whether I can get all the components working together this weekend, so that I have them ready for class on Monday.

I’m still panicking a bit about class starting on Monday:  I’ve only gotten the first three labs written up, and I still haven’t nailed down the FET and phototransistor lab.  I may even want to rearrange some of the labs (moving the hysteresis lab earlier in the quarter, for example).

All the computers seem to be working with the datalogger software with Duemilanove, Uno, and Leonardo Arduino boards, so I think we’re ready for Thursday’s lab.

My co-instructor loaned me one of the boards he designed for EE103L, the lab connected with the Signals and Systems course.  The board consists of a clock generator (using an LM555 with jumperable capacitors and a 1-turn trimpot and a couple of D flip-flops), an 8-bit analog-to-digital converter and an 8-bit digital-to-analog converter.  The idea is to hook up a signal generator to the input, and look at the output on the scope.  Artifacts of discretization in time and voltage should be visible, and aliasing can be observed as the input frequency is increased or the sampling frequency decreased. The board has a space on it for wiring up 4th-order Butterworth low-pass filter, but that is not done on the board he loaned me, nor is it needed for the lab that the EE103 students do.

He did one thing on the board that  makes it a little hard for me to play with at home: he did some initial signal conditioning using op amps with a dual-rail supply, so he expects two power supplies externally (which he regulates to ±5v on the board). Because he has the linear regulators, I don’t have to worry about providing matching supplies, but I need about 8v, as there is a 1.7v dropout from the regulator and a diode drop from a protection diode he added, so I’ll need at least 7.5, and preferably 8v.  I have a big 12v battery (which I often use to drive my 6.6v regulated supply), and I can use a wall wart for the other supply, so I should be able to fake the power setup at home.

He also expects the signal generator to be properly centered at GND, so I’ll have to add a DC-blocking capacitor and resistor to my non-centered function generator.  Using the Bitscope function generator would be a bad idea, because it is already discretized (though in finer steps than the 8-bits of this board).

The lab itself is a bit hokey: the students are to use just the frequency of the input sine wave (which they can adjust) and the observations of the discretized signal on the scope to determine the sampling frequency.  This looks to me more like a 20-minute or half-hour lab than one that will fill the full 3-hour lab slot, so I’ll have to think of more things for the students to do—perhaps using the sampling on the Arduino in addition to the board.


« Previous Page

%d bloggers like this: