Wednesday, 5 July 2023

Sweet Mystery

 This packet contains 12 sweets of 4 different colours (black, red, yellow and - my favourites - green). 

 

 
The number and order of the colours in each pack appears to be random (based on many, many samples 😉 ). If my calculations are correct and if they are really randomly distributed, one in every 4.2 million packets will contain 12 sweets of the same colour. Something I have often wondered about: how do the manufacturers avoid this? I can see a number of possibilities:  
 
  • Don't worry about it - it happens infrequently enough not to care
  • Optically scan each group of 12 sweets just before wrapping them and if they aren't sufficiently heterogeneous, don't wrap them - throw them back into the pot and try again. This only seems like it would be worth doing if they were optically scanning them anyway for other reasons (e.g. quality control)
  • They don't really throw all of the colours into one big pot and select them at random: they keep the individual colours separate right up to the packing stage and just shuffle the order in which they pick them to create the appearance of randomness.
Does anyone have any theories or insights? I'd love to know. In the meantime I'll keep eating them - purely in the interests of science, of course 🙂

Saturday, 3 June 2023

GIMP Start-up Hang

This was a pain-in-the-ass to troubleshoot, so I'm sharing the story here in the hope that it will help someone else.

I have GIMP installed on a Windows 10 machine. Out of the blue, it started hanging on start-up: the main window would appear, but then it would freeze for about 5 minutes. Uninstalling and reinstalling didn't help and no amount of Googling yielded any solution.

The first useful clue I got was after it did become responsive (finally, after the 5-minute delay) and I clicked on the "File" menu-item, causing it to hang again for another 5 minutes. That hinted that the problem was with the "Recently Used" file list.  So where does GIMP store the list of recently-used files? Nowhere obvious, it turns out: on Windows, GIMP stores its recently-used file list in C:\Users\%USERNAME%\appdata\Local\recently-used.xbel (which may be shared by other applications).  It is an XML-format file.  Sure enough, in there are a bunch of references to files on a network share that no longer exists:-

Contents of recently-used.xbel file, showing references to non-existent network share

I could probably have just deleted the entire file, but it was sufficient to just delete the <bookmark>...</bookmark> sections that referenced the now-absent network share.

I have to give a hat-tip Bing for leading me to the solution.  None of my Google searches along the lines of "where does gimp store its recently used file list" yielded any useful hints about where to look.  I was just about to start reading through the GIMP source-code - a daunting prospect - when I decided to try the same search on Bing:-

Bing search result referencing recently-used.xbel

Even though this result refers to GIMP running on Linux, it was enough: one quick search for a file called "recently-used.xbel" and I was away. And so the score stands at Bing 1, Google 0.

Wednesday, 6 January 2021

Window Repainting Delays in Windows 10

A weird Windows 10 problem this morning. When I booted up the PC, it appeared very "sluggish". There was no obvious reason for this: CPU and disk I/O were all very low. On closer examination, the problem was with window refreshes: things were working OK in the background, but the contents of windows weren't being repainted for several seconds after. Switching away from a window and switching straight back seemed to "trigger" an update that should have happened all by itself.  

Anyway, after a bit of Google searching, I happened upon a description of a similar problem and its solution that I don't think I would ever have come up with by myself.  Somehow, the screen refresh rate had been changed from 60Hz to 59Hz:-

 

 

Sure enough, changing this back to 60Hz resolved the problem immediately.

I hope this saves someone else some pain (or saves me reliving the pain if it happens again and I have forgotten what the fix was !)

Wednesday, 27 May 2020

40dB Stereo Pad + Balanced-to-Unbalanced

The 30/40dB pad from my previous post works fantastically well. I have been using it to bring the balanced line-level output from a mixing desk down to an acceptable level for the microphone input on my camera and the sound-quality is crystal-clear. 

But it is time for version 2.0.  The things I want to change:-
  • Stereo. Up to now, the cable I have been using to connect the pad to the camera simply connects the camera's L and R inputs together. It works fine, but the camera records two audio channels and I want to use them. 
  • The first version is nice and general-purpose: it provides balanced output, handy for feeding into a balanced microphone input, if I ever wanted to. But my camera doesn't have a balanced input, so a camera-specific version with unbalanced output to a more convenient connector (phono or 1/4" stereo) would make connecting up a little easier (although I do love how rock-solid XLR connectors are). I'm willing to sacrifice some generality for convenience here.
  • I don't really need it to have a switchable attentuation level.  The mixer has an output level fader and the camera has variable sensitivity on its microphone input. I'm willing to sacrifice the flexibility of a switchable attenuation level to reduce the (slight) risk that the contacts in the switch will become oxidised and noisy at some point.
Here is the schematic for version 2.0


The pad part is mostly the same as the earlier version.  I included some extra resistors (R1, R3, R6 and R8) that I have bridged with little wire links to give myself some flexibility.  If I want to increase the attenuation, I can snip the wire links which will increase the attenuation to around 45dB.  I had the board space (and the resistors) so it seemed a shame not to use it.  At the output, I have given myself a choice of either 1/4" stereo jack output or 2 x phonos.

If I had thought of it, I might have included a way to bypass the pad completely so that I could use this to connect two dynamic microphones (with balanced XLR outputs) directly to the camera input without any attenuation, but I didn't think of it (until now).  That's what version 3.0 is for, I guess.

This is what it looks like:-


I haven't tried it in anger yet, but initial testing is positive.  I'll report back once it has had its first proper outing.

UPDATE January 2021: I have been using this gadget regularly since May and it works absolutely perfectly: I am very happy with the result.  The amount of attenuation is applies is just about perfect and I haven't felt the need to snip the wires bypassing R1, R3, R6 and R8.  I do have about 12dB of attenuation dialed in on the camera's microphone input, bringing total attenuation up to about 42dB, which sounds about right and - more importantly - lands the recorded audio levels just about where I want them.

Tuesday, 21 April 2020

30dB/40dB Switchable Balanced Pad

I had a requirement to connect the (line-level) output from a small mixing desk into the microphone input on my camera (mic-level, obviously). I was using a DI box with a 30dB pad in it, but that required a 9V battery which was sure to run out at the most inopportune moment.  Since the camera didn't take balanced input anyway, there was no real need for the DI (in fact, the cable from the DI into the camera was wired as a balanced-to-unbalanced cable).  A little bit of internet research led me to http://www.uneeda-audio.com/pads/ which has all of the relevant information (but does require careful study !).  Based on that, here's what I came up with:-


This gives me the option of either 30dB or 40dB of attenuation, depending on the position of the switch (I find that with the in-camera gain turned down as far as it will go, 30dB is enough, but the flexibility is nice to have).  The input impedance seen by the mixer is about 27K at 40dB and about 6.8K at 30dB.  The output impedance presented to the camera is 220Ω.  It works pretty well.  I built it into a small plastic project box lined with copper foil (originally bought with the intention of shielding a guitar cavity):-



The resistors are of the metal film type to minimise thermal noise.

This is the end-result:-


It is fairly compact and rugged, completely noiseless and doesn't require any power.  

The justification for the choice of resistor values is as follows.  The general equation for gain (which will be negative) of a resistor divider network is:-
...where Ris the lower resistor in the circuit diagram and Ris the sum of the resistors labelled R1.n in the circuit diagram above.  So, for 30dB of attenuation, the switch is closed and the 10K resistors are bypassed and the equation becomes:-
With the switch open, the 10K resistors are included in series and the equation becomes:-


I could (possibly should?) have used a slightly lower resistor value than 10K to land a little closer to -40dB.  7.5K would have done it, but it had already been a long night.  a 30K resistor in parallel with each of the 10Ks would do the trick.

Monday, 1 April 2019

Experiments with a Smartphone Barometer

Modern smartphones have a wealth of sensors that provide all sorts of avenues for amusement for modern geeks.  One of them is a barometric pressure sensor, which is the topic of this post.  I have an app called Phyphox which provides direct access to the data from those sensors.

I was in London a while ago, working on the 18th floor of an office-block. There is an express lift which gets from the ground to the 18th floor (60m up) in 15 seconds non-stop. The locals tell me that when the lifts went in first, they used to be even faster but they hurt peoples' ears and had to be slowed down. I have no trouble believing that.

These graphs were produced using the Phyphox app on my phone, measuring the changes in air pressure with altitude (like the altimeter in a plane) as well as vertical acceleration.  This is from ground straight up to the 18th floor.
 

This from the 18th down, but with stops on the 17th and 16th (other people wanting to use the lift and messing with my experiment...no consideration !) - hence the "staircase" effect for the first 45 seconds or so.
 


A bit later on, I managed to capture a "clean" descent all the way from the 18th down to the ground:-
 

The cabin of an aeroplane is another interesting place to try this.  These were taken on the flight home during take-off and climb-out:


...and coming in to land:-


(I'm probably on a no-fly list now). You can see the cabin-pressure gradually drop from ground-level pressure to around 760hPa as the plane climbs and gradually increase from that back to ground-level pressure again as the plane comes in to land. The change is made gradually over the course of about 14 minutes each time.
 
Of course the cabin of the plane is pressurised and outside air-pressure at the cruising altitude of 36,000ft is far lower than 760hPa. The cabin pressure is equivalent to being at an altitude of around 2,300-2,400m (a good bit less than ⅓ of the way up Mount Everest).
 
The Phyphox app really is an awful lot of fun. It gives you direct access to all of the sensors on a modern smartphone (and there are lots of them) and lets you run experiments like these with them.

Sunday, 21 October 2018

Experiments with an AD633 Multiplier IC

Something I have always found a little confusing was the idea of signal mixing.  The source of my puzzlement probably has its roots in the audio world of mixing desks for combining the sound from instruments and singers for music recording or live performance.  These mixing desks are (or are supposed to be) additive: their output should be the simple arithmetic sum of all of the inputs, scaled according to how far the sound engineer pushes the fader.

In the RF world, mixing means something quite different.  When we mix RF signals, we (usually) specifically want them to interfere with each other to create frequencies that weren't present in either (because we're usually talking about two) of the original signals.  That is usually the last thing in the world you want to happen in the audio world, but it how a heterodyne radio works (more on this a little later).  For this to happen, the RF signals need to be mixed in a non-linear way, usually by multiplying them together.  It took a while before this difference dawned on me.

The maths behind mixing in the RF sense of the word is pretty straightforward.  It relies on the trignometric relationship:-

sin(a) ✕ sin(b) = ½sin(a+b) + ½sin(a-b)

In plain English, if two sinusoidal signals are multiplied together, the resulting signal will consist of two sinusoidal signals at the sum and difference of the two original frequencies. 

That has to be tried.

Inspired by some of the many great W2AEW videos (Alan is my hero!) - specifically this one and this one - I did some some experiments with multiplying a sine wave by a lower-frequency square wave using the diode-switching technique and got some interesting results.  However, the real fun was had with an Analog Devices AD633 multiplier IC.  Its a little beauty: it takes in two signals (differential) and outputs the result of multiplying them together (÷10).

Here is a 1KHz sine wave being multipled by a 800Hz square wave (the yellow trace is the result):-



Its pretty easy to see what's going on here - the inversions of the sine wave when the square wave changes state are pretty evident.

Here's 10KHz and 800Hz:-


Its a little less obvious here, but if you look carefully, you can still see the sine wave change phase by 180° when the polarity of the square wave changes. 

We'll come back to this in a bit.  For now, let's try multiplying two sine waves together, one at 10KHz and one at 800Hz.  In theory, the result will be a signal which is the sum of two new sine waves, one at 9.2KHz and one at 10.8KHz.


Bingo !!  The purple trace is the FFT and - sure enough - there are two (and only two) peaks at exactly the frequencies that the maths predicts.  Note also that there is none of the original 10KHz signal present (there is no 800Hz signal there either, although it would be off-screen to the left even if there was).

Returning to the 10KHz sine wave and the 800Hz square wave: a square wave consists of the sum of the odd harmonics of the fundamental.  So our 800Hz square wave has components at 800Hz and 2400Hz and 4000Hz etc.  So multiplying this by our 10KHz sine wave should produce an output with tones at 10KHz +/- (800Hz, 2400Hz, 4000Hz...).  Let's see if it does:-


Yep.  The cursors show the fundamental.  The horizontal divisions are 1.25KHz each, so you can see that the other tones are all about 1600Hz above and below the fundamentals.  Again, note that there is no sign of the original 10KHz signal at all...just at the theory predicts. 

"Why?", you might be tempted to ask.

The plan for the AD633 is to use it as the basis of a bat detector.  Bats' echo-location sounds are somewhere around 48KHz (at least the Pipestrelle bats that are common in Ireland) - far above the range of human hearing.  The idea is to mix the signal from an ultrasonic transducer (hopefully from lots of hungry bats) with - say - a 40KHz sine wave, thus hopefully shifting the bats' sounds into the human-audible range.  This is the same basic principle on which a heterodyne radio receiver works, with a local oscillator being mixed with the target RF signal to produce a intermediate frequency which is then detected with a high-Q filter.