A Quick and Dirty Audio Signal Generator

It was pretty clear that my ELFQuake setup would need fairly major mains hum filtering, especially since this location is very close to overhead power lines. This was emphasized the other day when I tried a little AM radio, all but two stations on MW were totally drowned out by hum.

When I was last experimenting with the filter circuitry I found the limited equipment I have rather frustrating. When it came to a signal generator, I didn’t have much joy using either a tablet app or the BitScope waveform generator. What I really wanted was a knob to twiddle for easy tweaking of the frequency. So a couple of days ago I spent a few hours knocking together a simple analog circuit. My requirements were essentially the twiddly knob and something approximating a sine wave. The constraints were the components I had at hand, and no desire to spend too much time over it.

What I came up with is as follows. The circuit starts with a simple triangle/square wave generator using standard analog computational elements based around op amps:

tri-osc

I’m using a TL084 quad op amp with a +/- 12v supply.

When the output of the left-hand op amp is negative, that will ramp up the integrator on the right until it flips the switch on the left (note positive feedback on that op amp). Then the integrator will ramp down until it flips the switch the other way. The frequency is simply determined by the resistors in the middle and capacitor C, as f = 1/2piRC. In practice I’ve got 6 values of C between 4u7 and 1n, producing a frequency range (measured) from about 5Hz to 200kHz. In the middle, with 100n, varying the pot in the middle gave a range from about 275Hz to 11kHz with what looked on the scope like a clean triangle wave. Switching to the top range gave a significant warping of the triangle, but I thought it might still be useful.

Next is a more interesting circuit, which modifies the triangle wave into something approximating a sine:

shaper

The transistors are just a couple of regular BC109s I happened to have a lot of. The transistors act as differential voltage to current converters with a nonlinear transfer function, with the op amp converting the currents back to voltages.

Here’s the cunning bit – the transfer function of the transistors is theoretically proportional to tanh, which looks like this:

TanhReal

Given the right scaling (and bias) this will have the effect of rounding over the upper and lower corners of the triangle waveform. This isn’t an entirely arbitrary choice of function. The first few terms of the Taylor Series for tanh are roughly the same as those for sine.

The actual component values were chosen pretty much by trial and error, adjusting values until the harmonic components appeared to be at a minimum on a frequency response display. Ideally the transistors should have been a matched pair in thermal contact and maybe some tweaking of the levels/balance/bias of this block might have made for a purer sine wave, but I was only after quick & dirty…

This is what the waveforms/freq plots look like (measured on a BitScope), first the square & sine from the first circuit block:

square

triangle

Here’s the shaped output:

sine

Though the 2nd harmonic is still about at the same level as the triangle, but the higher harmonics do seem significantly attenuated.

According to Wikipedia, the Total Harmonic Distortion (THD) of a square wave is around 48.3% – the high harmonic levels are clear on the trace above. For a triangle wave the value is around 12.1%. I’ve not done the sums to figure out the theoretical best achievable using the tanh shaping (homework anyone?), but there is a visible improvement in the displays above. I don’t know, maybe something around 5%..?

(Incidentally, the triangle wave generator can be easily modified to generate a ramp by slipping a diode in the feedback loop).

You may have noticed I’m using a quad op amp, but only 3 of them are in use. I contemplated using the 4th as a buffer or even as the heart of a switched filter. But more useful for me I reckon, and definitely more fun, was to deploy this in a white noise generator:

noise

The noise source is the reverse-biased emitter-base junction of another BC109 transistor. This is simply followed by a DC-blocking capacitor and the op amp set up to give a gain of 100. I think the capacitor I used is a 100n. There was a little bleeding through of the oscillator’s signal visible, but not enough to be troublesome. The output did look remarkably wideband, only really starting to drop off gradually around 50kHz.

noise

I then transferred everything to a piece of stripboard, and in true quick & dirty style mounted it on a scrap of wood:

vero

(Sorry about the blur). Incredibly, even though I put it onto the stripboard without any real planning, I only made one wiring mistake which took about 2 minutes to discover. But I was bitten by hubris when I wired up the capacitor switch – it’s a 2-pole, 6-way, and it took me ages to get the wiring right.

When I tested the sine wave output again there was a visible asymmetry – pointier on top, more rounded on the bottom. I think most likely I got the transistors the other way around. Rather than desolder/resolder them I tweaked the value of the shaper’s input resistor, adding a 1k in series with the 18k in the schematic above, which restored the balance.

So now I have another little addition to my little electronics workbench (big coffee table)…

desk

 

 

 

Advertisements

Hardware Issues

[work in progress 2017-04-15]

Hardware Overview

(I initially made a significant mistake in my radio reception plans, see Loops, Oops!)

I had hoped by now to have prototypes for a radio receiver and seismograph ready in hardware. What I have got on that front is an increased awareness of how tricky they are likely to be. I still think I’ve got a reasonable design for the sensor part of the seismograph.

Noise Annoys

On the radio side, the experiments I’ve done so far have only really shown that the signal/noise ratio I need to deal with is even worse than I imagined. This is largely due to my location. Although this is a very small village in the hills, everywhere you look are overhead mains power lines. To get a signal that won’t be swamped with noise I anticipate having to filter out at least mains hum at 50Hz and 100Hz (possibly even higher harmonics) in analog signal conditioning. A standard circuit that can do this job is the twin-T notch filter. By wrapping it around a couple of op-amps it can be bootstrapped, boosting the Q, hence the depth & narrowness of the notch can be increased. The big problem here is component tolerance. Metal film resistors are pretty good, having 1% accuracy, but capacitors are another story – anything better than 10% is quite specialist (and that’s not even taking into account effects of thermal variation). Some level of manual tweaking seems unavoidable, worst case 4 trim pots per filter (3 in the T, one for the feedback = Q).

My plan to make a receiver consisting of 3 orthogonal coils will have to remain on hold until I have some funds available (it sounds crazy, but wire looks like it’s going to be the greatest expense). I do have the bits to play with a single channel. And that’s also simpler.

Data Acquisition

I haven’t written it up yet, but once I’ve got usable analog signals from the radio, seismo and other* sensors, I want to use dedicated hardware to get them into the digital domain. Not only that, ideally I want this part of the system to make the raw data available on the Web. I think it makes sense to use a subsystem to collect the data independently of processing, to keep things modular. That way the subsystems can be developed in isolation and additionally the processing workload can be more distributed. So essentially I will have analog-to-digital converters (ADCs) attached to one or more small computers. The physical location of sensors is a consideration – away from sources of interference for the radio receivers, solidly attached to the ground for the seismic sensors. It is necessary in each case to have some of the signal conditioning circuitry local to the sensor (at least pre-amplification).

I then need to get the preconditioned signal from the sensors through the ADCs into the dedicated processing subsystems and on again to the part that will do the processing. The most elegant approach I can think of is also having the ADCs & dedicated computers local to the sensors, with the data being delivered to subsequent processing over WiFi. (Care will be needed in shielding the digital electronics to avoid interference).  An existing standard transfer protocol will be desirable (probably TCP or UDP), and from there it’s only a small step to proxying it onto the Web.

Given this setup, and the considerations of location, modularity and performance, it will make sense to use one ADC+computer subsystem for the radio receivers and one for the seismic sensors.

*  for reasons described below, I plan to eventually detect signals in 3D, ie. both the radio and seismic units having a N-S, E-W and vertical element. But most ADC boards have their number of channels as multiples of 2. Hence I intend to use 2 x 4 channel ADCs, and use the 2 spare channels for acquiring other environmental signals – provisionally acoustic noise (audio) and ambient temperature (again, there’s rationale below).

Two small species of small, inexpensive, general-purpose computers stand out from the marketplace: Raspberry Pi and Arduino. Now I’ve spent a lot of time around digital audio and rather naively assumed that suitable ADCs would be ten a penny. Not so.

For the radio signals, ideally I want to capture something roughly equivalent to fair quality audio, ie. say a bandwidth of 20kHz with 16 bit precision. ADCs that can do this are available of-the-shelf in the recording part of regular soundcards. Unfortunately, there doesn’t appear to be anything available that’s inexpensive and interfaces easily with either computer board (and I have read of issues with data transfer bottlenecks when using USB devices). However I have found a card that appears to fit the bill, for the Arduino : the Mayhew Labs Extended ADC Shield.

Progress (of sorts)

[work in progress 2017-04-15 – material was getting long so splitting off to separate pages]

General Status

In the last month or so I’ve done a little hardware experimentation on the radio side of things, along with quite a lot of research all around the subjects. I also had a small setback. About 3 months ago I ordered a pile of components, they never arrived, a screw-up by the distributor (I wasn’t charged). Unfortunately I don’t have the funds right now to re-order things, so although I do have the resources for some limited experimentation, I can’t go full speed on the hardware. (Once I’ve got a little further along, I reckon I’ll add a ‘Donate’ button to this site – worth a try!)

This might be a blessing in disguise. Being constrained in what I can do has forced me to re-evaluate the plans. In short, in the near future I’m going to have to rely mostly on existing online data sources and simplify wherever possible. This is really following the motto of Keep It Simple, Stupid, something I should maybe have been considering from the start.

 

Next Steps

Jam Jar Seismometer and a Springy Coincidence

One key aspect of this project is the detection of seismic events. Yes, I want to play with the online data from proper seismo stations, but as I’m primarily concerned with the earthquake risk at a given location, some kind of local system is very desirable.

A quick search of the Web for seismographs shows that one design seems most popular, essentially a heavy weight on the end of a swinging arm, with some restraint (& damping).

seismometeroverview

It’s relatively simple, but, is rather large and only captures earth movement on one axis. Amongst my project aims/constraints (which I’ve yet to write up) are to keep things small and to capture as much info as possible, within an emphasis on simplicity.

Yesterday, while enjoying a pint on a sunny afternoon in Maryborough, Victoria, I wrote down what I have in mind for my Version 1 sensor. Call it the:

Jam Jar Seismometer

img_20170112_122813

(Erm, ignore the top-left text, that was Mish brainstorming some unrelated promo text)

So essentially a ball of steel dangling from a spring in a jar of oil. On the horizontal axes it should act like a (damped) pendulum, on the vertical like a (damped) weight on a spring. Minimal physics.

To measure the movement of the ball, the obvious setup would be a coil and magnet, like an electric guitar pickup. But as it happens, the other day I bought a Hall Effect sensor, just out of curiosity on what natural magnetic fields it could pick up. (It has a built-in preamp and gives a linear output, sensitivity 1.3mV/G. Given the earth’s magnetic field is in the region of 0.5 Gauss, it should be sensitive enough to be interesting). These things are very small and fairly inexpensive (~$7). Having each backed by a little rare earth magnet should give a reasonable output. Not sure where I’ll source a big ball bearing, must have a suitable spring around somewhere. While veggie oil would probably be inert enough, mineral oil may be wiser. (Italian hardware shops sell a food-quality mineral oil for air-sealing demijohns of wine, that’ll be my plan A).

Trying this setup out will likely reveal silly or subtle flaws I’ve not thought of, but there are two sources of potential problems I can see right away. First is that the magnets will pull the weight towards themselves. Hopefully the physical issues should be fixable by using a different spring; electromagnetic, fixable in electronics/software.

The second thing that came to mind is the effect on the output of the Hall Sensors when the magnetic field is off-axis. I couldn’t see a mention of this in the data sheet. If the resting position of the ball is (0,0,0) in physical space, and a hella quake hits and pulls it to (1,1,1), will this be reflected in the output of the sensors?

I suspect that this would definitely be a problem were the goal to be to record the x,y,z signals as individual, absolute, calibrated values. But presumably the true measures will be some weird, probably non-linear function (over time) of the 3 detected values, so this shouldn’t cause information loss. As I intend to use a fairly deep neural net on this data, any weird polynomials will (hopefully) get flattened out so the processing system just sees the perturbations of interest.

Magnitude 3.0 Coincidence

enough to be noticed, but not weird enough to trigger a psychotic episode

So I sketched my plan yesterday morning. In the afternoon we visited a charity shop (Op Shop here down under) and I bought this book.

img_20170112_122903

I’ve looked at these kind of sums before, mostly around about 1987 when the book was published. But my maths is seriously rusty, and this is stuff I should really be fluent with. I did cover such material in school (in the contexts of analog electronics & acoustics) but in the days before Chaos Theory stuff threw a spanner in the works. After that I did a bunch of informal research & even magazine writing on chaos in analog systems, but never went far with the maths. Now, of 9 chapters in this book, 7 of them are written from a post-chaos perspective.

I digress. The coincidence is between my sketches above and what appears in the first chapter of this book:

img_20170112_123031

Page 6/277. I’ve a way to go yet…