Localising Online Data – baby steps

While I’m intending to build a simple seismometer in the near future, there’s a lot of data already available online. Generally this seems to be available in two forms : near real-time output of seismometers and feeds of discrete events. I’ve not yet started investigating the former as the latter seems an easier entry point to start coding around.

I’m based in northern Italy, and as it happens there are some very good resources online for this region (hardly surprising, as earthquakes are a significant threat to life & property in Italy). A hub for these is the Istituto Nazionale di Geofisica e Vulcanologia (INGV).

Web Services

The service with the snappy name Event Federation of Digital Seismograph Networks Web Services  allows queries with a variety of parameters, returning data in a choice of three formats : QuakeML (a rich, dedicated XML), KML (another XML, Google’s version of GML) and text. Hat tip to the folks behind this, it’s Open Data (CC Attribution).

The INGV also offers a preset translation of the previous week’s events in Atom format (augmented with Dublin Core, W3C Geo & GeoRSS terms for event datetime and location). This is a minimal version of data from the Web service, but contains all I’m interested in for now: event magnitude, location & time. (I also have a personal bias towards Atom – it’s the first and I think only RFC in which my name appears 🙂

Relocating the Event

The potential utility of this project is about the risk of seismic events felt at a specific location. The feed gives the magnitude of the event at epicentre. It may be reasonable to process the raw data to reflect this.

Whether or not it will be better to use such data raw (i.e. separate  inputs for magnitude, latitude & longitude) or pre-processed as input to neural nets remains to be seen. But to flag up high risk at the target location, some combined measure is desirable.

The true values depend on a huge number of factors (for more on this see e.g. The attenuation of seismic intensity by Chiara Pasolini). As a first attempt at a useful approximation I’ll do the following:

  1. restrict data to events within 200km of the ‘home’ location
  2. apply an inverse-square function to the magnitude over the distance

Both are guesstimates of the relative event significance. Although major events beyond 200km may well have significant impact locally, for the purposes of prediction it seems reasonable to exclude these. For these purposes the data is going to be fed to a machine learning system which will be looking for patterns in the data. Intuitively at least it seems to make sense to reduce the target model to that of local geology rather than that of the whole Earth.

The recorded magnitude of events (as in the Richter magnitude scale) is more or less a log10 of the event power. Compensations to this made by measuring stations to allow for their distance aren’t exactly straightforward. But seismic shaking is very roughly similar to sound, and the intensity of sound at a distance d from a point source is proportional to 1/d^2. This may be wildly different from the true function even under ideal conditions. But it does introduce the distance factor.

(If you’re interested in looking into the propagation side of this further, the ElastoDynamics Toolbox for Matlab looks promising).

Anyhow, I’ve roughed this out for node.js, code’s up on github. A bit of tweaking of the fields was needed (e.g. the magnitude appears in the text of the <title> element). It looks like it works ok, but I’ve only done limiting testing, shoving the output into a spreadsheet and making a chart. The machine I’m working on right now is old and has limited memory, so is a bit slow to do much of that.

elfish

The red dot is the home location.

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…

 

 

Signal Generator for Free; Notch Filter Progress

So I’m trying to put together an analog filter to cut the mains hum from a ELF/VLF radio receiver.
The sig gen built into the BitScope DSO is very limited, only offering certain fixed frequencies. This isn’t a huge amount of use for evaluating a notch filter circuit. Neither was the use of a white noise source as input to the circuit with a freq domain trace at the output, the notch wasn’t visible (had a bit more smoothing been available in BitScope DSO, this should have worked).

img_20161231_114937

I thought my easiest next step would be to put together an analog sweepable oscillator on the breadboard. But then, while falling asleep, I had a Eureka moment: the laptop I’m using for the DSO display has a soundcard! I’m running Ubuntu on the lappie, and the Audacity audio recording/processing tool has the facility for generating swept-frequency signals. So I attached jumper leads to a mini jack plug and stuck that in the headphone socket, bingo!

By generating a 1 second sweep, 20Hz-200Hz, in Audacity and loop-playing it, I got a reasonably respectable view of the filter response in the freq domain display of the DSO.

img_20170104_115751

Next up I just need to tweak the resistor values to focus the notch bang on 50Hz. Putting pots in parallel with the current values will allow me to find these values. However, silly me, I don’t have a multimeter to check the pot values. I did see one in a hardware shop for AUS$11 the other day, and given that’s about the price of a pint of beer here, I guess I have no excuses.

Seeing the Signals (& BitScope BS10, first impressions)

tl;dr

The BitScope BS10 and associated software makes a useable but basic scope, but its real potential is probably in its other facilities: simple data acquisition across various platforms (including Raspberry Pi) and the ability to monitor logic levels alongside analog signals.

img_20170105_100440

Trying to do any signal-oriented electronics without an oscilloscope is like trying to drive blindfolded. OK, it is possible to develop audio systems with just a multimeter and an amplifier, but you are literally missing a sense. I did have an old analogue, CRT scope years ago, but gave it away when I moved to Italy. I’ve only done a tiny bit of electronics dev since then (simple guitar effects) and have got away with ears, just.
But my latest project will involve a lot of unknown signals, there’s no way I can make progress without a scope.
Standard scopes nowadays are Digital Storage Oscilloscopes (DSOs). The storage side is sweet, it’s possible to save snapshots of traces and often capture the raw data contained in them. But with Digital comes a caveat. Analog scopes tend to give a fairly true representation of the signal, in the given context (bandwidth, levels etc). Anything spurious, such as over-level clipping is immediately visible. Digital scopes rely on analog to digital conversion (A/D), which introduces factors such as the sample rate, filtering and resolution. Out-of -range signals presented here can produce misleading displays.

Requirements

Most of what I want to look at is in the audio frequency range, which is well covered by pretty much any scope worth its salt. For example, my old analog one went up to a 1MHz timebase, comfortably encompassing the nominal 20Hz-20kHz of audio. But because I’m going to be looking at circuits that may pick up radio frequency signals, a higher bandwidth could be useful. Being able to go down to DC will be useful too, for lower frequency signals and detecting unwanted offsets etc.
The signal levels I’m interested in are relatively low voltage, so there are no special requirements here (at circuit input some signals will be very low amplitude, but as the target systems will need to amplify these anyway, this shouldn’t be an issue).
For convenience, I want at least two simultaneous traces to be available – most circuits I’m likely to be looking at will feature an input and output.
Additional it will be pretty essential to examine signals in the frequency domain.
Finally, the scope has to be affordable.

Options

Benchtop DSO

This is the most obvious solution. These are available starting at around $500 – not a trivial amount, but definitely worth considering for such a vital piece of kit.

Computer Soundcard

Right at the low budget end is the use of a computer sound card and appropriate software. Remembering now, I realise I fibbed about developing guitar effects without a scope, I did actually use a soundcard and various (free) VST plugins to look at the signals.
But this approach is quite limited, and, well, clunky. It isn’t really viable to make accurate measurements, there’s no range changing switches built in, bandwidth and resolution can be overly limited (e.g. few sound cards go down to DC).

BitScope

This is an A/D converter which attaches to a USB port and has dedicated DSO software. The BS10 has excellent specs on paper, though they are dependent on host computer performance. The software will run on MS Windows or Linux and notably a Raspberry Pi. An Android version appears to be in the pipeline. Physically the BS10 is a small box which comes with a bunch of clip leads. It has two analog inputs, an analog output and and 8 logic inputs. A variety of applications were downloadable from the site, the key one being BitScope DSO. Once I’d realised this had to be run with sudo (to give access to /dev/ttyUSB0) it worked a treat.
The controls in the application aren’t entirely intuitive, after a couple of days getting used to them I’m still unsure e.g. how to adjust offset. For equipment like this, I’m afraid an on-screen user interface will never be as convenient as hardware knobs you can twiddle.
The DSO application also offers a frequency domain display (for one or both channels) as well as a basic signal generator. The freq display is very nice to have, though control of parameters is rather limited. For example, an arbitrary zoom would have been good, as would a variety of smoothing/averaging options.
Similarly the built-in signal generator is nice to have, but even more limited. It offers a range of fixed frequencies, producing a sine or square wave. This is OK for quick checks, but that’s about it.

Fortunately there’s a fairly trivial way of providing a versatile sig gen in the same setup at virtually zero cost. Whatever the host machine for the BitScope, chances are it has a soundcard. Hook a couple of jumpers leads to a jack plug, pop it in the headphone out socket, fire up Audacity and bingo!

img_20170104_115751
So as a substitute for a benchtop DSO, the BS10 is adequate but not outstanding. Call it 7/10. Given the price compared to dedicated hardware this seems reasonable.
However, chances are anyone working with analog signals in this day and age are likely to have digital aspects to their circuits. I haven’t tried this yet but from the docs the 8 channel logic monitor capability of the BS10 looks like it should be very useful in future.
For my current project, while I need the DSO facilities for circuit development, the BS10 should offer a very good foothold into another part. Again though I haven’t yet tried this, it also appears to be a very versatile data acquision system for recording signals. This can be done from within the DSO app or programmatically (with hooks from Python, I believe). The latter part I’m rather looking forward to, a hackable signal capture unit is very nice to have. I don’t yet know how sophisticated I need this side of my project to be, but the BS10 certainly is an option. Alternately I may develop with this interface, then flip to the cheaper BitScope Micro for production.
All in all then, the BitScope BS10 scratches a lot of itches.