Gas station without pumps

2016 February 29

Fourteenth weight progress report

Filed under: Uncategorized — gasstationwithoutpumps @ 22:41
Tags: , , , , , ,

This post is yet another weight progress report, continuing the previous one. I’m doing even worse this month than before, remaining in my target range for only 9 out of 29 days.

weight-2016-Feb-29

My exercise for February was fairly high (averaging 5 miles/day bicycling), and I was good about my raw-fruits-and-vegetables-for-lunch diet during the week, but I ate too much at my evening meals and on weekends.  I now want to lose 6 pounds, which, even with the strict discipline I had last year at this time, would take me 6 weeks.

2016 February 27

Applying for Mini Maker Faire round 3

Filed under: Uncategorized — gasstationwithoutpumps @ 20:10
Tags: , , , ,

I’ just submitted my application for the Santa Cruz Mini Maker Faire, as mentioned in Santa Cruz Mini Maker Faire 2016Applying for Mini Maker Faire, and Applying for Mini Maker Faire round 2.

The banner will still be a yard of 56″-wide “Performance Piqué” fabric for about $18, but I’ve changed the design:

Dr_K_banner_622x400

 

I’m still not happy with the design, but it is better than the previous one. I have time to work on it more before I have to order the banner, so I welcome suggestions. Should it be made simpler? busier? different colors? Should it include photos?  Are there other circuits I should include? Should I scale the circuits to have the same line widths? or make them have a wider variation in size? (Note: everything but the PteroDAQ logo is scalable graphics, so I can make things as big or small as I need to, and still get the 150dpi resolution needed for fabric printing.)

I’ve pretty much given up on writing an exciting one-paragraph blurb to go with the application and will go with something rather bland, just so I can get the application submitted.  Sometimes it is better to be done with a less perfect result than to keep fussing and miss a deadline.  Here is what I’ve submitted:

See your pulse on a home-made optical pulse monitor!
Record air pressure waveforms using Arduino or Teensy boards with free PteroDAQ data acquisition software!
Play with a bright LED stroboscope and desk lamp, made with custom-designed PC boards!
Use oscilloscope and function generators!
Watch demos of a home-made electrocardiogram (EKG)!

I did not submit a picture with the application, because I couldn’t think of a good one to submit—they wanted a URL for one that is on-line, which would probably mean something from this blog.  Ah, well, if they accept my application (which I assume they will), then I’ll be able to ask them what sort of picture they want and see if I can find something that is useful.

2016 February 26

Applying for Mini Maker Faire round 2

Filed under: Uncategorized — gasstationwithoutpumps @ 22:29
Tags: , , , ,

I’m getting closer to applying for the Santa Cruz Mini Maker Faire, as mentioned in Santa Cruz Mini Maker Faire 2016 and Applying for Mini Maker Faire.

I have a title for the display:

Dr. K’s Applied Electronics

and an initial design for a table banner (to be printed as a yard of 56″-wide “Performance Piqué” fabric for about $18):

PteroDAQ-cover-PteroDAQ-650x409

I have the design at high enough resolution for fabric printing, which is recommended to be a 150dpi.

I’m not real happy with this design—the book cover is boring and anemic, and the cover should probably have a dark border.  The PteroDAQ logo is better, but the colors of the logo and the book don’t fit well together.  The banner also doesn’t include Dr. K’s Applied Electronics, which is a nice name for a Maker Faire, but not one I’d currently want to put on the book.

Anyone have any ideas for improving the book cover or the banner?  

That leaves me with one main task: writing a one-paragraph blurb to go with the application, covering the things I plan to show:

  • The desk lamp and the strobe light (which use the same electronics hardware: only the firmware is changed to turn the dimmer into a strobe controller).  I can show both at once and have a few of the LED boards on display also. Maybe I should modify the firmware so that I can just move a jumper plug on the programming pins to switch between strobe and dimmer functions—I wonder if there is enough flash memory in the ATtiny 13A processor for that.  The strobe takes 364 bytes, and the dimmer takes 372 bytes, so even if no code can be shared (unlikely), they should be able to both fit in the 1kB flash.
  • An optical pulse monitor (with standalone display based on a 240×320 RGB ILI9341 TFT display I got from PJRC). I might want to make one that is more open than the wooden blocks I’ve been using, so that it is easier to see where you have to cover the hole to the phototransistor.  I might also want to try seeing if a green or yellow LED gives a better signal (I have a bright yellow LED that has a much narrower beam than any of my red LEDs). I’ve not tried using the display yet, but it sounds pretty easy to set up—I should have some time in the next week or two to try it out.
  • Function generators hooked up to an oscilloscope for Lissajous patterns?
  • A microphone and small amplifier hooked up to an oscilloscope? Note, I only have one analog oscilloscope, and it is a bit touchy to use—there was a reason for it being sold used on eBay! It also takes up a lot of table space—but it is the cliché icon of an electronics enthusiast or mad scientist. I could set up the Bitscope oscilloscope on my laptop, but it is not as iconic, and that would use up one of my 2 displays that could be used for PteroDAQ.
  • An EKG with PteroDAQ display? (It would need to be wired to me—too much trouble and expense to put electrodes on others)  I could also use the same standalone display design as for the optical pulse monitor, if I get that designed and built in time.  I don’t think I’ve got time to get the software working and build a case for a wearable EKG—I wonder if I can find a case that works with the TFT display.
  • Aquarium air pump, soft tubing, and pressure sensor hooked up to PteroDAQ?  (people can play with pinching the tubing to see the effect of pressure changes)   I usually use the pressure sensor with a blood pressure cuff or a breath mouthpiece, but the cuff is too much trouble to work with if there are many people, and I have no good way to clean the mouthpiece between users.
  • The PC boards I’ve designed.
  • Some of the tools a hobbyist needs (soldering iron, bread boards, wire strippers, …).
  • Laptop and iMAC for PteroDAQ displays.

I’ve decided against

  • Displaying the nerf-gun prototype (not pressurized) and the soda-bottle rocket launcher (again not pressurized).  These are a bit off the main theme of electronics and take up a too much space.
  • Having kids make LED “throwies” out of CR2032 batteries, LEDs, magnets, and electrical tape. I’d have to spend a lot on parts and spend all my time helping kids put together their throwies, not to mention the ecological disaster of using so many disposable batteries.

I will also want to hand out business cards that point people to this blog, PteroDAQ, and my book. I still have to design the cards. I haven’t decided whether they will be “professional” or “fun” designs, nor what graphics I want on them (other than not the book cover). Probably I’ll do one PteroDAQ-only card with the logo, the URL, and a brief description of PteroDAQ.  I’ll probably do another one for my book, with the book cover, the URL (or even a limited-time reduced price coupon), and a very brief blurb. I don’t know what to do about advertising this blog, if anything.

The bulleted list of things I want to show has to be alluded to in the “Project Description”, which “will also be used on [my] Maker sign”. So I need something simultaneously catchy and descriptive. Here are some key phrases:

  • See your pulse on a home-made optical pulse monitor!
  • Record air pressure waveforms using Arduino or Teensy boards with free PteroDAQ data acquisition software!
  • Bright LED stroboscope and desk lamp, with custom-designed PC boards!
  • Home-made electrocardiogram (EKG)!
  • Microphone amplifier!
  • Use oscilloscope and function generator!

Can anyone suggest some catchier things to put in the blurb?  I want to submit this weekend, if I can. (And before a writing teacher points it out, I’m aware that the list of key phrases is a mixture of noun phrases and imperative sentences, and so fails the “grammatically parallel” test.  I’ll probably fix things to be all imperative sentences, but I’m still trying to figure out the content, and not worried so much yet about copy editing.)

Digital filter lecture

Filed under: freshman design seminar — gasstationwithoutpumps @ 00:00
Tags: , , ,

On Wed 2016 Feb 24, I gave a lecture in the freshman design seminar on digital filters, covering about 3 weeks worth of material in an hour.  Needless to say, this was a very rushed and handwavey introduction to digital filtering, but it should be enough that the students can (with some additional scaffolding) implement bandpass filters for the pulse monitor project and the ultrasonic rangefinder project.

On Monday, I had covered the notion of digital signals as having discrete values and discrete times with a uniform sampling frequency, so I started with a signal x_0, x_1, \ldots , x_t and introduced the z-transform X(z) = x_0 + x_1 z^{-1} + x_1 z^{-2} +\cdots .  I explained that this was a linear transform, so that if we multiplied x by a constant, we would multiply X(z) by the same amount, and that the z-transform of the sum of two signals was the sum of their transforms.

I also showed that the signal 0, x_0, x_1, \ldots, which is x delayed by one tick, has the z-transform z^{-1} X(z).

I claimed (without proof) that linear filters consisted of delay elements, multiplication by constants, and addition, so that the z-transforms of the input (X(z)) and output (Y(z)) were related by a transfer function: H(z)= Y(z)/X(z), and that H(z) is a rational function for linear filters.

I first showed them a finite-impulse-response (FIR) filter:

Small finite-impulse response filter. (Block diagram drawn with http://www.draw.io/)

Small finite-impulse response filter. (Block diagram drawn with http://www.draw.io/)

I showed them how this filter had H(z) = b_0 + b_1 z^{-1} + b_2 z^{-2}, and could be implemented easily in pseudocode:

    x0 ← new value
    y ← b0 * x0 + b1*x1 + b2*x2
    x2 ← x1
    x1 ← x0

I explained, briefly, what an impulse response was (the values put out by a filter whose input is 1 at time 0 and 0 at all other times), and showed that the filter coefficients were the impulse response.

I also showed them a biquad filter element:

This biquad filter element uses the type 1 direct implementation, which has the advantage of not having any internal overflows, as long as the inputs and outputs remain within bounds. (Block diagram drawn with http://www.draw.io/)

This biquad filter element uses the type 1 direct implementation, which has the advantage of not having any internal overflows, as long as the inputs and outputs remain within bounds. (Block diagram drawn with http://www.draw.io/)

I gave them a simple implementation of the biquad element:

    x0 ← new value
    y ← (b0 * x0 + b1*x1 + b2*x2 - a1*y1 -a2*y2)/a0
    x2 ← x1
    x1 ← x0
    y2 ← y1
    y1 ← y0

I pointed out that multiplication and addition (of integers) was cheap on the Teensy boards, but division or floating-point arithmetic is expensive. Because of binary representation, division by powers of two is cheap, so we can keep the computation fast if we restrict a0 to powers of 2.

I showed how the recurrence relation in the code could be rearranged with simple algebra to get the transfer function H(z) = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{a_0 + a_1 z^{-1} + a_2 z^{-2}}. Somewhere in the lecture I mentioned that the poles of H(z) (that is, the zeros of $latex a_0 + a_1 z^{-1} + a_2 z^{-2}$) had to remain within the unit circle to keep the filter from oscillating, but I didn’t explain why.

I told the students that we would represent sinusoids with e^{j\omega t} = \cos(\omega t) + j \sim(\omega t), giving a brief explanation of the advantages of using exponentials rather than trig functions and reminding them of the popular abbreviation using angular frequency \omega = 2 \pi f instead of frequency f.

I claimed, without proof, that the response of a filter to a sinusoid with angular frequency \omega was just H(e^{j \omega}). I then shared with them a gnuplot script for plotting the response of a biquad element:

#band-pass for pulse monitor
fs = 60
A0= 256
A1= -388
A2= 141
B0 = A0
B1 = 0
B2 = -B0

A0_2 = 256
A1_2 = -449
A2_2 = 199

unset arrow
set arrow nohead from 40000,-20 to 40000,20

unset label
pole1a = ( -A1 + sqrt(A1*A1 - 4 * A0 * A2)) / (2*A0)
pole1b = ( -A1 - sqrt(A1*A1 - 4 * A0 * A2)) / (2*A0)
set label sprintf("pole magnitude %.3f", abs(pole1a)) at 1,-3
set label sprintf("pole1a at %.3f + %.3f j", real(pole1a), imag(pole1a)) at 1,-5
set label sprintf("pole1b at %.3f + %.3f j", real(pole1b), imag(pole1b)) at 1,-7


pole2a = ( -A1_2 + sqrt(A1_2*A1_2 - 4 * A0_2 * A2_2)) / (2*A0_2)
pole2b = ( -A1_2 - sqrt(A1_2*A1_2 - 4 * A0_2 * A2_2)) / (2*A0_2)
set label sprintf("pole2b at %.3f + %.3f j", real(pole2b), imag(pole2b)) at 1,-17
set label sprintf("pole2a at %.3f + %.3f j", real(pole2a), imag(pole2a)) at 1,-15
set label sprintf("pole magnitude %.3f", abs(pole2a)) at 1,-13

set title sprintf("Design of biquad filter, fs=%3g Hz",fs)

set key bottom right
set ylabel "gain [dB]"
unset logscale y
set yrange [-30:*]

set xlabel "frequency [Hz]"
set logscale x
set xrange [0.01:0.5*fs]

set grid xtics
set mxtics 10

j=sqrt(-1)
biquad(zinv,b0,b1,b2,a0,a1,a2) = (b0+zinv*(b1+zinv*b2))/(a0+zinv*(a1+zinv*a2))
gain(f,b0,b1,b2,a0,a1,a2) = abs( biquad(exp(-j*2*pi*f/fs),b0,b1,b2,a0,a1,a2))
phase(f,b0,b1,b2,a0,a1,a2) = imag(log( biquad(exp(-j*2*pi*f/fs),b0,b1,b2,a0,a1,a2)))

set samples 5000

plot \
    20*log10(gain(x,B0,B1,B2, A0,A1,A2)) \
	title sprintf("%.0f (1 + %.0f z^-1 + %.0f z^-2)/(%.2f+ %.3f z^-1 + %.3f z^-2)", \
			B0, B1/B0, B2/B0, A0, A1, A2), \
    20*log10(gain(x,B0,B1,B2, A0_2,A1_2,A2_2)) \
	title sprintf("%.0f (1 + %.0f z^-1 + %.0f z^-2)/(%.2f+ %.3f z^-1 + %.3f z^-2)", \
			B0, B1/B0, B2/B0, A0_2, A1_2, A2_2) lt 3

I walked them through the code and showed them the result:

This is a pair of bandpass filters designed for a pulse monitor. The red curve may be a better choice, as it does not have such a sharp peak around 1.5Hz, but still reasonably suppresses the high frequencies and the DC drift.

This is a pair of bandpass filters designed for a pulse monitor. The red curve may be a better choice, as it does not have such a sharp peak around 1.5Hz, but still reasonably suppresses the high frequencies and the DC drift.

I showed them why any bandpass biquad has essentially the same numerator: we want to have a zero at DC (frequency 0, so at e^{j 2 \pi 0}=1) and at the Nyquist frequency $e^{j 2 \pi \frac{1}{2}}=-1$, so the numerator is always a multiple of (1-z^{1})(1+z^{-1})= 1-z^{-2}.

I also showed them the effect of having just the numerator (setting the denominator polynomial to 1), using both log and linear frequency scales to show the peak at half the Nyquist frequency (one quarter the sampling frequency):

A linear frequency scale make the symmetric frequency response of the FIR filter 256 (1–z^-2) clear.

A linear frequency scale make the symmetric frequency response of the FIR filter 256 (1–z^-2) clear.

I told them that I did not really know the details of how to choose specific filter parameters, and shared with them the code I used from the scipy.signal package for choosing the parameters:

#!/usr/bin/env python3

from __future__ import print_function, division

from scipy import signal
from cmath import sqrt  # complex square root

print("set parameters by giving name=value lines:")

sampling_freq = 30 # Hz
low_cutoff = 0.3        # Hz
high_cutoff = min(150, 0.49*sampling_freq) # Hz
fixed_point_scaling=64

while True:
    print("sample=",sampling_freq, "low=", low_cutoff, "high=", high_cutoff,
        "scale=", fixed_point_scaling)

    hi_over_Nyquist = high_cutoff/(0.5*sampling_freq)
    lo_over_Nyquist = low_cutoff/(0.5*sampling_freq)

    filter_float = signal.bessel(1,
                        [lo_over_Nyquist,hi_over_Nyquist], 
                        btype="bandpass")
    A= [int(x*fixed_point_scaling+0.5) for x in filter_float[1]]
    discr = A[1]*A[1] -4*A[0]*A[2]
    poles= [(-A[1]+sqrt(discr))/(2*A[0]), (-A[1] -sqrt(discr))/(2*A[0])]
    
    print("\tA=",A, "B=[1,0,-1]", "poles=",poles)
    
    line=input("param=value?")
    fields = line.split("=")
    if len(fields)==0: continue
    if len(fields)!=2:
        print("No parameter change found, exiting")
        break
    keyword=fields[0].strip().lower()
    value=float(fields[1])
    if keyword=="low" or keyword=="lo":
        low_cutoff = value
    elif keyword=="high" or keyword=="hi":
        high_cutoff = value
    elif keyword=="sample" or keyword=="freq":
        sampling_freq = value
    elif keyword=="scale":
        fixed_point_scaling=int(value)
    else:
        print("unrecognized keyword:", keyword)

I only walked them through a little of this code (mainly showing the scaling of frequencies to the Nyquist frequency, since that is what the signal package wants, and the call to the bessel function to get a Bessel filter). I explained that the fixed_point_scaling parameter was to get more resolution in the parameters when doing integer arithmetic, but didn’t really have time to explain what that meant. I did demonstrate setting the parameters to get one of the filters shown in the graph above.

On Friday, I plan to give them a little code snippet that I use:

static volatile     int32_t x_0, x_1, x_2;
static volatile     int32_t y_0, y_1, y_2;

// filter parameters for biquad bandpass filter

// selected for approx 0.66--6Hz with 60Hz sampling
#define SAMPLE_FREQ	(60)	// sampling frequency in Hz
#define a0  (256)
#define a1  (-388)  
#define a2  (141) 

#define gain (1)
  // b0= - b2= gain*a0
  // b1=0

#define DELAY_XY (x_2=x_1, x_1=x_0, y_2=y_1, y_1=y_0)
#define GENERAL_BANDPASS (y_0 =  ((gain*a0)*(x_0-x_2) -a1*y_1 -a2*y_2)/a0, DELAY_XY)

To use the filter, I include

    x_0=analogRead(MONITOR_PIN);
    GENERAL_BANDPASS;

in an interrupt routine that runs once every 60th of a second. I’ll also have to show them how to use the IntervalTimer in the Teensyduino software development kit to set up the interrupt routine.

2016 February 25

Santa Cruz Shakespeare announces 2016 season

Filed under: Uncategorized — gasstationwithoutpumps @ 22:21
Tags: , , ,

I attended the season announcement party for Santa Cruz Shakespeare tonight, at which they announced their line up for the season.  They really need a blockbuster season this year, to help pay for the $1,000,000 construction of the new “Grove at Delaveaga Park” performance space, for which they have a 2-year lease.  Naturally, they picked very well known and popular plays:

  • Hamlet
  • Midsummer Night’s Dream

For the Fringe play by the interns (which is often as good or better than the plays by the professional actors, except for the inevitable intern who can’t project well enough for outdoor theater—but they’ve had that problem sometimes with professional actors), they chose a less well-known play:

Virginia Woolf’s Orlando, adapted as a play by Sarah Ruhl.

According to the play’s web site, it was first performed in 2010, so it is a relatively recent work.

Mike Ryan is continuing the practice of gender-balanced casting, which should work well for the couples in Midsummer Night’s Dream—that play is nearly gender-balanced as is. 

For Hamlet, the title role will be played by a woman.  I don’t know whether she will be “Princess of Denmark” or whether she will be playing a male role. I think that Hamlet could be a female role, though the parts of the plot involving Ophelia would change somewhat in tone.  If Hamlet becomes a female role, what about Horatio? Also, Rosencrantz and Guildenstern could be male, female, or one of each, equally plausibly. I’m curious to see how they work this out.

I’ve seen an all-female production of Hamlet in Santa Cruz (April 2012, produced by San Francisco State University, and presented by Jewel Theatre), in which the roles retained their original gender, despite an all-female cast—it was a good production, particularly for student work.  I suspect that SSC will try a more challenging adaptation, in which some of the roles change gender, rather than cross-casting the actors.

Of course, the point of having this season-announcement party for “Producer’s Circle” donors was to ask people to give to the capital campaign, in addition to their annual giving for the operating expenses.  They’ve raised about 67% of what they need, but that still leaves about $330,000 to raise in the next month or two.  I think that they’ll be going public with the capital campaign soon, once they’ve got a few more big donors to make the remaining “ask” seem more feasible.

They are getting a no-interest loan, I believe, backed by donor pledges, so that they can start construction as soon as the money is promised.  The idea is that people can pledge money to be given over the next three years, and the loan makes the money available immediately for the upfront construction costs.  My wife and I have already donated to the 2016 budget and were planning to donate to the 2017 budget, and we’ll probably give something to the capital campaign, but we haven’t figured out how much yet.

The planning permits are approved, I believe, so they are ready to start work on the site as soon as the money is available. They had planning documents at the party, and I spent some time leafing through them.  They look pretty good, but it doesn’t seem like there will be any aisle lighting (though I supposed they could add non-permanent rope lights or equivalents).  There wasn’t aisle lighting at the Festival Glen either, and its lack did not seem to cause  any problems.

They’re starting their season a little later this year (July 12), with the hope that the delayed start will give them enough time to finish building everything.

Next Page »

Blog at WordPress.com.

%d bloggers like this: