# Gas station without pumps

## 2017 July 12

### Join the Day of Action for Net Neutrality on July 12th

Filed under: Uncategorized — gasstationwithoutpumps @ 07:57
Tags: ,

Today is the “Day of Action” for net neutrality—a day when people and businesses everywhere can speak up for the important role that regulation plays in ensuring freedom of speech.

JULY 12TH: INTERNET-WIDE DAY OF ACTION TO SAVE NET NEUTRALITY
The FCC wants to destroy net neutrality and give big cable companies control over what we see and do online. If they get their way, they’ll allow widespread throttling, blocking, censorship, and extra fees. On July 12th, the Internet will come together to stop them.

It may seem strange that regulation is important for freedom, but freedom of speech and freedom of the press requires that those who provide the infrastructure (historically the public marketplaces and parks, nowadays the internet) not be allowed to censor based on content or who is speaking.  This is precisely the principle of net neutrality, which does not allow ISPs to charge different fees or provide different services dependent on whose data is being sent.

My Internet Service Provider (ISP) is a small local one, and they are very strongly in favor of net neutrality—it is only the very large, monopolistic ISPs like Verizon that favor being allowed to take bribes to give some services preferred access to consumers.  Trump appointed a Verizon executive to remove net neutrality and concentrate power in the hands of the monopolists, but today is a time to push back and insist on freedom.

Go to Join the Day of Action for Net Neutrality on July 12th to find out more about net neutrality and to sign a petition asking Congress to defend it!

## 2017 July 11

### Disappointed in UCSC students

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

I was a bit disappointed with UCSC students this Spring. Not for academic reasons (my spring class had about the usual academic range, from not quite passing to quite bright, with most of the students working hard to get a reasonable performance). And not because of protests that students did or didn’t do (there were the usual number of student protests—some effective, some completely pointless)—Santa Cruz has a long tradition of protests, and a year without them would seem bland. What bothered me was the loss of a different tradition: that of participatory rather than spectator athletics:

Intercollegiate Athletics and Athletics Activities Access Fee

Shall the undergraduate and graduate students of UCSC enact a new fee of $38.50 per quarter to support the current and long-term operations of UCSC’s intercollegiate athletics program and provide access to students who meet Educational Opportunity Programs (EOP) criteria for athletic-related activities? This fee will sunset in 25 years (Spring 2042). Votes Percent Yes 4852 79.84% No 1967 20.16% Total Turnout 6819 % of Student population who casted vote 39.23% I can’t understand the logic of allowing a student vote to tax students for the next 25 years for anything but a capital project. The yes votes of 4852 people will affect the fees for about 100,000 future students who have no say in the process. I wonder how many of the other fees students pay are similarly ill-advised programs locked in place by ridiculously long sunset clauses. Note that this fee does not go towards improving sports and recreation facilities for most of the students, but almost entirely to support the coaches and travel for under 300 NCAA athletes: The fee will provide the NCAA Division III program with approximately$1.1 million beginning in fall 2017. Approximately \$160,000 will be generated to support athletic activities of student who meet EOP criteria, approximately 40 percent of the student body. The fee is scheduled to sunset is 2042.

In addition, the Chancellor has promised another half a million in general funds for athletics—money that could have been spent to hire instructors for about 50 instructors for courses, affecting over 1000 students.

Of course, the athletics coaches who pushed their teams so hard to campaign for the subsidy from the 15000 or so students who get no benefit from the fee are now not happy with the result:

Two head coaches and six assistants filed grievances Friday against UC Santa Cruz in a public move they hope sheds light on their frustration with the university’s relationship with its athletics department.

Earlier this week, acting athletic director Andrea Willer, the executive director of Office Of Physical Education, Recreation And Sports (OPERS) informed two head coaches and all of the school’s assistant coaches that their contracts would not be renewed.

The Chancellor had put a more positive spin on the new contracts:

A significant change is that our head coaches will now have three-year, full-time contracts. This is good news that I believe will contribute to the long-term health and stability of our athletics program.

The campus has offered new contracts to nine of our 11 head coaches for NCAA teams. The old ones expired June 30. The new contracts include full benefits and a 3 percent salary increase. The contracts started July 1.

For coaches who held other non-coaching duties, the contracts were for coaching only, with non-coaching responsibilities moved elsewhere in the unit.

Eight of the nine coaches signed the offers. The ninth chose to retire.

There are changes for assistant coaches, too. They will now have six-month contracts. Previously, contracts were for 12 months, with required three-month furloughs. Contracts for the assistants also expired June 30. All assistants have been encouraged to apply when the new positions are posted in an open recruitment. [email to faculty from Chancellor Blumenthal]

When I came to UCSC in 1986, they had no NCAA athletics (at least I wasn’t aware of any, though a campus press release says the program started n 1981)—the focus of the sports programs was on the intramural program, with participation encouraged for all students.  Those who wanted interscholastic competition could join club sports, and I believe that the fencing team was pretty good.  Club sports competed with all the other students clubs for resources and did not get special privileges (unlike the reserved time, space, and staff for NCAA athletics).  I’m all in favor of students participating in sports and other fitness activities (the average student has gotten a lot fatter and less fit over the past 30 years), but I don’t see any point to subsidizing 2% of the students to do sports for the rest.

Now, I don’t think that UCSC is becoming another athletic cesspool (like Baylor, University of South Carolina, Penn State, …).  For one thing, there is no big money in Division III athletics, so the possibilities of massive corruption are rather limited, and UCSC does not have a football team, which seems to be the biggest source of violence in university sports. Our athletes are still students first (they have a higher GPA than the student body as a whole), and there are no large spectator crowds at any of their games to get into the sort of drunken riots that some schools are subject to.

But there has been a marked loss of exceptionality for UCSC over the past 30 years, with UCSC becoming more typical of universities.  They now have fraternities and sororities, they now have subsidized athletics (to the detriment of intramurals and club sports), the library recently shredded a huge number of books [http://www.mercurynews.com/2016/12/24/montgomery-on-ucscs-outrageous-mass-destruction-of-books/], class sizes have soared, and the SAT scores of incoming students have dropped.

For a while UCSC used as a tagline “an uncommon commitment to undergraduate education”, which at the time was true. Although they still have a very high ratio of undergraduates to graduate students for a research university (about 9 to 1, where most research universities have more grad students than undergrads), a lot of the commitment to teaching has dissipated over the past 30 years.  Part of the problem has been packing in more students without proportionate growth in teaching facilities (I believe that UCSC has the highest student/classroom-seat ratio of any of the UCs), and part of the problem has been hiring faculty solely on their research credentials, paying no attention to whether they want to (or can) teach.

Some of you may have noticed that I have used third-person pronouns (“they”) rather than first-person (“we”) throughout this article.  That is I do not feel that I have had any say in the bad decisions that been reverting UCSC to the mean. This is not the UCSC I am part of, and I don’t want to be part of it.  I’ll probably be retired before UCSC gives up everything that made it unique and a pleasure to teach at.

## 2017 July 9

### Digital tone detection with Goertzel’s algorithm

Filed under: Robotics,Uncategorized — gasstationwithoutpumps @ 00:28
Tags: , ,

In Multiple-feedback bandpass active filter I built a simple active filter to be part of a tone-detection circuit (looking for 2kHz).  Although the filter worked, it did not have as much gain as I expected, its out-of-band rejection was not impressive, and centering it at 20kHz accurately would require adding a potentiometer to tune it. To make a full tone detector, I’d have to have a rectifier and low-pass filter (or some other envelope detector).

I thought that it would be simpler to do the whole thing digitally, as long as my input signal was large enough to be reasonably measured by an analog-to-digital converter.  I started designing a digital filter, with the intent of implementing the same block diagram: bandpass filter, rectifier, and low-pass filter.  Although I came up with a fairly simple filter that looked like it would work well, my son suggested a different approach.  If I don’t need the tone detection to be super-fast, I can process the data a block at a time, and use Goertzel’s algorithm to compute the power at the frequency of interest.  By playing with the block length and windowing functions, I can shape the detection to have different bandwidths and shapes, but with a far steeper rolloff than with the active filter.

Goertzel’s algorithm is a way to compute one coefficient of a discrete Fourier transform (DFT) efficiently with only real-number computation.  In fact, with judicious scaling, I was able to do the computation with just 32-bit integer arithmetic, which can be done very quickly on microcontrollers (like the K20 processor used in the Teensy3.2 boards).

The per-sample computation is just a digital filter with transfer function

$\frac{S(z)}{X(z)} = \frac{1}{1 - 2 \cos(\omega_0) z^{-1} + z^{-2}} = \frac{1}{\left(1 - e^{+j \omega_0} z^{-1}\right)\left(1 - e^{-j \omega_0} z^{-1}\right)}~,$

where $\omega_0 = 2\pi f_0/f_s$ is the center frequency in radians, with $f_s$ being the sampling frequency.  This filter is not quite stable (poles right on the unit circle), so we can’t run it continuously without danger of overflow.  However, if we run it for just N samples, it essentially computes one term of the DFT (with a little post-processing magic):

$y[n] = e^{j 2 \pi \frac{k}{N}} s[N-1] - s[N-2] ~.$

I chose a sampling rate of 16kHz, so that my 2kHz center frequency is $\omega_0=\pi/4$, and the coefficient for $z^{-1}$ is $\sqrt{2}$.

The algorithm I used is

sprev = 0
sprev2 = 0

for i in range(N):
x = int(round(2**15 * (1+cos(freq/fs*2*pi*i))))  # full-scale unsigned 16-bit sine wave for testing
x = x* window[i]//2**14
s = x + sprev*coeff//scale - sprev2
sprev2 = sprev
sprev = s

scaled_sp2 = sprev2//N
scaled_sp = sprev//N
scaled_power =  scaled_sp2 * scaled_sp2 + scaled_sp * scaled_sp - coeff * scaled_sp * scaled_sp2//scale

The square-root of two for the coefficient in the recurrence was represented by coeff=181 and scale=128. The block length (N) was chosen to be 160, so that a block would be processed every 10ms. A 100Hz update rate is fairly typical for systems that control mechanical devices (50Hz is often good enough), and is quick enough not to be a perceptible delay.

I also kept track of the maximum absolute value for s, to make sure that I never exceeded 32 bits anywhere in the computation.
Here is a plot of the scaled_power output, as a function of the sine-wave frequency:

With a rectangular window, the detector has a bandwidth of about 89 Hz, for a Q of 22.5, but the sidelobes are pretty big.

To suppress the sidelobes, I prescaled the signals by a Slepian window, which maximizes the energy in the mainlobe. The Slepian window was computed by the SciPy signal-processing package, scaled to be full-range unsigned 16-bit integers.  The width of the mainlobe is somewhat adjustable—I chose a setting that gave me a somewhat lower Q (wider bandwidth), so that the filter could tolerate some mistuning of the center frequency in the source.

The sidelobes are so small that they get rounded to 0 or 1, while 2kHz is about 384e6, a ratio of about 85dB. The half-power bandwidth is about 226Hz, for a Q of about 8.85.

I could reduce the Slepian width to 0.1, getting a bandwidth of 192Hz (Q of 10.4) and still have the sidelobes fully suppressed. Trying to get higher Q with a block length of 160 starts getting sidelobes, but increasing N allows smaller bandwidths.

I suppose that my next step is to implement this algorithm in C on a Teensy 3.2, connected to an ADC, and see how well it performs in the real world. It looks very promising.

## 2017 July 1

### Multiple-feedback bandpass active filter

Filed under: Robotics,Uncategorized — gasstationwithoutpumps @ 12:14
Tags: ,

I wanted to improve my understanding of active filters, beyond the very simple ones that I included in my textbook, so I decided to try implementing a bandpass filter using the multiple-feedback topology.  To make the design more concrete, I decided to make one that was centered at 2kHz, but firmly rejected 1.5kHz and 2.5kHz.

Here is the design I came up with. The top part is the filter, while the bottom is just a reference voltage buffer. I’ll derive the values below.

$I_1= (V_{in} -V_{m})/R_1$
$I_2= (V_{ref}-V_{m})C_{2} s = (V_{o}-V_{ref})/R_2$
$I_3= (V_{ref}-V_{m})/R_3$
$I_4= (V_{o}-V_{m})C_{1}s$
$I_1 + I_2 + I_3 +I_4 = 0$

We can simplify a bit, by replacing $V_{m}-V_{ref}$ with $-(V_{o}-V_{ref})/(\tau_2 s)$, where $\tau_2 = R_2 C_2$. Note that this corresponds to replacing the amplifier, R2, and C2 with an inverting high-pass filter.

It is conventional to recenter the voltages so that $V_{ref}$ is zero, which simplifies the algebra.  Doing that gives us

$(V_{in}+V_{o}/(\tau_2 s))/R_1 + V_{o}/R_2 + V_{o}/(\tau_2 s R_3) + V_{o}(1+1/(\tau_2 s))C_{1}s=0$

Multiplying both sides by $\tau_2 s$ and rearranging gives us

$-V_{in}\tau_2 s/R_1 = V_{o} \left(1/R_1 + \tau_2 s /R_2 + 1/R_3 + (\tau_2 s +1)(C_1 s)\right)$

$\frac{V_{o}}{V_{in}} = -\tau_2 s / \left({1+ \tau_2 s R_1/R_2 + R_1/R_3 + (\tau_2 s +1)(R_1 C_1 s)}\right)$

More correctly, that should be $\frac{V_{o}-V_{ref}}{V_{in}-V_{ref}} = \ldots$, but I’ll just talk about the gain $G$.

Defining $\tau_1 = R_1 C_1$ we get

$G = -\tau_2 s / \left(1+ R_1/R_3+ (\tau_2 R_1/R_2 + \tau_1) s + \tau_1\tau_2 s ^2)\right)$

$G = -(\tau_2 s/R_1 )/ \left(1/R_1+1/R_3+ (\tau_2 /R_2 + \tau_1/R_1) s + \tau_1\tau_2 s ^2/R_1)\right)$

If we have $C_1=C_2=C$, which is a common design constraint, we can simplify to

$G = -(R_2 C s/R_1 )/ \left(1/R_1+1/R_3+ 2 C s +C\tau_2 s ^2)\right)$

$G = -(R_2 /R_1 )/ \left((1/R_1+1/R_3)(Cs)^{-1}+ 2 +\tau_2 s)\right)$

We can define $R_p = R_1 || R_3 = R_1R_3/(R_1+R_3)$ and $\tau_p = R_p C_1$.  Then we have

$G = -(R_2 /R_1 )/ \left((\tau_p s)^{-1}+ 2 +\tau_2 s)\right)$

If we let $s = j \omega$, we get

$G = -(R_2 /R_1 )/ \left(2 +j (\tau_2 \omega-(\tau_p \omega)^{-1})\right)$,

whose magnitude is maximized when $\tau_2 \omega-(\tau_p \omega)^{-1}=0$ or $\omega = 1/\sqrt{\tau_2\tau_p}$, and at that maximum the gain is $- R_2/ (2 R_1)$.

The corner frequencies, where the gain drops by the square-root of 2 occur when the real and imaginary parts of the denominator have the same magnitude, or $\tau_2 \omega-(\tau_p \omega)^{-1}= \pm 2$. If we take only the positive values of $\omega$, we get $\omega = \left(\pm 1 + \sqrt{(\tau_p+\tau_2)/\tau_p}\right) /\tau_2$, for a bandwidth of $2/\tau_2$, or $1/(\pi R_2 C_2)$ Hz.

For C=10nF and R2=220kΩ, we get a bandwidth of 144.7Hz.  With R1=6.8kΩ and R3=300Ω, Rp=287.32Ω, with time constant 2.8732 µs, giving a center frequency of 2001.8kHz.  I built this filter and tested it with the Analog Discovery 2:

The overall match of the filter to the theory is pretty good.

But when we look in detail at the peak, we can see that the center frequency is off a little and the gain isn’t nearly as big as it should be. I suspect that the problem is poor matching of the very cheap 10nF capacitors.

I also tried exciting the filter with wideband noise from the Analog Discovery 2, and doing an FFT of the input and output to get a different view of the response:

The filter response looks a little larger taking the difference of FFTs (after averaging many FFTs, since each individual one has a lot of noise). Note the 60 Hz spike.

« Previous Page