Tuning an LRC circuit

A short notepad on some electronic stuff I have been reading up on via Electronics Demystified: this time about tuning an LRC (series) circuit (i.e. one with capacitance, inductance and resistance).

In these circuits, the resonant frequency is found when the effects of capacitance and inductance cancel each other out.

Inductive reactance is given by 2\pi\textit{f}L (where \textit{f} is the AC frequency and L is the inductance), while capacitive resistance is \frac{1}{2\pi\textit{f}C} where C is the capacitance.

So to cancel these out: 2\pi\textit{f}L = \frac{1}{2\pi\textit{f}C} ,  and as we may assume L and C are fixed this requires finding the resonant frequency \textit{f}_{r} :

\frac {1}{2\pi\sqrt{LC}}


From The Selfish Gene to Alan Turing: the Enigma

As I spend a lot of time in the gym (honestly) I have decided to use that a little more productively and listen to decent non-fiction audio books – and I have just finished listening to Richard Dawkins’s The Selfish Gene.

Cover of "Alan Turing: The Enigma"
Cover of Alan Turing: The Enigma

I quite enjoyed the book (or the recording) in the end – certainly added to my knowledge of genetics (not that that would be tough) and made a convincing case for its central argument: that genes the fundamental replicators of the biological world and it is their ‘drive’ to selfish self-preservation that shapes so much of our world. In fact my biggest criticism of the book is the way it anthropomorphises genes – a weakness reflected in the title itself. Genes are not selfish really – they are molecules that, statistically, interact with other molecules in a way that ensures their molecular formation survives. The book’s unwillingness to discuss anything but the most minimal amount of maths means Dawkins refuses to discuss that perspective in anything but the briefest of terms.

I also found his explanation of intelligence unconvincing, but this is a tricky and exceptionally difficult subject and I don’t have an original idea to counter Dawkins with.

And, of course, there is no discuss of the chemical processes that allow these proteins to shape their ‘machines’ or their phenotypes generally.

But, yes, it’s worth reading or listening to.

Next up? Andrew Hodges‘s Alan Turing: The Enigma. This, at 30 hours, is almost twice as long as Dawkins’s book, so suspect will be listening to this into August (unless I go mad for the gym) – will be interesting to see how, if at all, the maths are dealt with.

Magenta is not a ‘real’ colour and other mysteries

I have never paid that much attention to colour theory, I know how to mix red, green and blue programatically in various languages and environments to get what I want and that’s about it.

But an article I have just read on how colour really works is fascinating.

The first thing that made me sit up and think is the observation that magenta is not a ‘real’ colour – in the sense that there is no wavelength of light that corresponds to magenta. (I suppose I have always thought of it as a ‘light violet’, but it’s not really.)
magenta square
Of course the colour is “real” but its reality is not based on simple physics – that square is simply made up from (if you are using an old fashioned CRT monitor) equally bright blue and red dots. The “colour” is manufactured in your brain. It is what is known as an “extra spectral” colour and of course their are many of these we see in daily life: just think of brown.

The way the brain handles colour is fascinating – this optical illusion – which I have seen before but which continue to amaze me – is a great example. Squares A and B could not possibly be the same colour – but, in fact, they are: your brain automatically corrects for the shadow.

Chess squares

What they didn’t teach me at ‘A’ level (or at university!)

English: Button image for use in templates - I...
English: Button image for use in templates – Impedance (Photo credit: Wikipedia)

I have always found the concept of impedance in an electrical circuit bearing an AC load something of a mystery.

At ‘A’ level it was just handed out ex cathedra but explained very poorly (and certainly not in any physical sense).

Even at University where in my first term (the first term of second year students as I made the mistake of going straight into year two of the four year course – a mistake my university career never really recovered from) I did a pretty intensive course on DC circuits, it was never explained (astrophysicists presumably not needing to know much more).

Now, though, it matters again. Impedance and other electronic effects are very important in considering the physical layer of network on chip systems – something at the heart of my PhD research.

So I bought Electronics Demystified – not normally the sort of book my inner intellectual snob would even contemplate, but I needed to get up to speed and yet not spent a lot of time on the physics.

The book is indeed somewhat simplistic and very short on any sort of physics-based explanation, but lo-and-behold, in chapter two it explains simply that complex impedance is an electromagnetic effect. Maybe I missed it, but I just do not recall anyone ever pointing this basic point out before. I don’t claim I have a full understanding now, but I do know what is at the core.

I am also left, once again, wondering why we teach magnetism so poorly when plainly it is the equal partner of electricity, which we teach an awful lot about (or, to be fair, we did – this was some years ago!)

The Fifty Shades of Grey phenomenon

Fifty Shades of WTF?! VOL. "Have You Read...
Fifty Shades of … (Photo credit: Instant Vantage)

When did you first become aware of “Fifty Shades of Grey”? Perhaps if you are a man rather later than if you are a woman… about six weeks ago I noticed that this book – which I had heard of (possibly because I had seen someone reading it on the Tube) was being talked about in social networks and since then the volume of chatter has risen and risen and risen.

On Saturday the BBC reported that last week alone it sold over 200,000 copies in just the UK. But today they also reported that the book is not good news for book shops.

The book is certainly cheap to buy online – but I suspect embarrassment is also a big factor in wanting to buy an electronic copy. Hopefully that means this is just a blip and not a decisive moment in the decline of bookshop sales in Britain.

Relive the ZX81 experience on your desktop

BINSIC – my reimplementation of ZX80 or ZX81 (Timex Sinclair 1000 or 1500 for US readers) BASIC is now available for download in binary form – look at the page on the site: Binsic Is Not Sinclair Instruction Code.

It comes with Conway’s Game of Life for the authentic black and white text based feel too.

(Source code is also available here)

Life: rewritten

Well, what else was I going to do? This works and that means I think BINSIC does too. It’s not quite a fully functional BASIC – try as I might I cannot get GOTO or even GOSUB to work inside loops (though I might do better if plough on with the GOSUB stuff), but I’ll hopefully launch it all tomorrow evening.

10 REM Game of Life
20 PRINT "Conway's Game of Life"
30 PRINT "Copyright Adrian McMenamin, 2012"
35 PRINT "adrianmcmenamin@gmail.com"
40 PRINT "Licensed under the GPL version 3"
50 DIM A(48, 70)
60 DIM B$(24)
70 PRINT "Please enter your pattern"
75 PRINT " - up to 24 lines of 70 characters"
80 FOR I = 1 TO 24
90 INPUT B$(I)
95 LET T = 0
97 IF B$(I) = "DONE" THEN LET T = 1
98 IF T = 1 THEN LET B$(I) = ""
100 IF T = 1  THEN GOTO 150
110 PRINT B$(I)
120 NEXT I
150 REM Parse Input
160 LET P = 0
170 LET G = 0
175 LET Y = 0
177 LET Q = 0
180 FOR Y = 1 TO 24
190 LET Z = LEN B$(Y)
210 IF Z = 0 THEN NEXT Y
220 FOR Q = 1 TO Z
222 LET A(Y, Q) = 0
225 IF MID$(B$(Y), Q, 1) = " " THEN LET A(Y + 24, Q) = 0
230 IF MID$(B$(Y), Q, 1) <> " " THEN LET A(Y, Q) = 1
232 IF MID$(B$(Y), Q, 1) <> " " THEN LET A(Y + 24, Q) = 1
234 IF MID$(B$(Y), Q, 1) <> " " THEN LET P = P + 1
240 NEXT Q
250 FOR Q = Z + 1 TO 70
260 LET A(Y, Q) = 0
265 LET A(Y + 24, Q) = 0
270 NEXT Q
280 NEXT Y
300 REM Display Map
340 PRINT "Generation ", G, " Population is ", P
350 FOR M = 1 TO 24
360 FOR N = 1 TO 70
370 IF A(M + 24, N) = 1 THEN PRINT "*";
375 IF A(M + 24, N) <> 1 THEN PRINT " ";
380 NEXT N
390 NEXT M
400 REM Map next generation
410 FOR M = 1 TO 24
420 FOR N = 1 TO 70
430 LET A(M, N) = 0
440 IF M + 1 < 25 AND A(M + 25, N) = 1 THEN LET A(M, N) = A(M, N) + 1
450 IF M - 1 > 0 AND A(M + 23, N) = 1 THEN LET A(M, N) = A(M, N) + 1
460 IF N + 1 < 71 AND A(M + 24, N + 1) = 1 THEN LET A(M, N) = A(M, N) + 1
470 IF N - 1 > 0 AND A(M + 24, N - 1) = 1 THEN LET A(M, N) = A(M, N) + 1
480 IF M - 1 > 0 AND N - 1 > 0 AND A(M + 23, N - 1) = 1 THEN LET A(M, N) = A(M, N) + 1
490 IF M - 1 > 0 AND N + 1 < 71 AND A(M + 23, N + 1) = 1 THEN LET A(M, N) = A(M, N) + 1
500 IF M + 1 < 25 AND N - 1 > 0 AND A(M + 25, N - 1) = 1 THEN LET A(M, N) = A(M, N) + 1
510 IF M + 1 < 25 AND N + 1 < 71 AND A(M + 25, N + 1) = 1 THEN LET A(M, N) = A(M, N) + 1
520 NEXT N
530 NEXT M
540 LET P = 0
600 FOR M = 1 TO 24
610 FOR N = 1 TO 70
611 LET ZZ = 0
612 LET SC = A(M, N)
612 IF A(M + 24, N) = 1 THEN LET ZZ = 1
613 LET RES = 0
614 IF ZZ = 0 AND SC = 3 THEN LET RES = 1
615 IF ZZ = 1 AND (SC = 2 OR SC = 3) THEN LET RES = 1
616 LET A(M + 24, N) = RES
617 LET P = P + RES
650 NEXT N
660 NEXT M
700 PAUSE 50000
800 LET G = G + 1
900 GOTO 310

A problem with Life

Bill Gosper's Glider Gun in action—a variation...
Bill Gosper’s Glider Gun in action—a variation of Conway’s Game of Life. This image was made by using Life32 v2.15 beta, by Johan G. Bontes. (Photo credit: Wikipedia)

I had hoped to “launch” BINSIC – Binsic Is Not Sinclair Instruction Code – my BASIC-as-a-DSL project built using Groovy, this weekend. For the launch I wanted to publish a jar file (so usable by everyone with Java) that ran the version of Conway’s Game of Life (seemed very appropriate for both general – Life being the ultimate hacker meme – and personal – I once wrote a version of Life in Z80 machine code for the ZX80 – reasons) found in Basic Computer Games – but I don’t think I am going to manage it now

The problem is that the code in the book is totally banjaxxed. It uses variables before they are declared and in general looks as though either some lines have been transposed or some code has been omitted altogether. It is certainly plain that the printout of the running program in the book does not reflect the code found on its pages. In any case hacking at this code reveals the full horror of BASIC and how difficult it is to maintain code that is not even in blocks, never mind any other sort of order.

So I have two choices – refactor the BASIC I have in quite a big way to get it to run, or find some new code instead.

But the exercise has not been completely wasted. While hunting down the bugs in David H Ahl’s code I have found more than a few in BINSIC itself.

Leonardo DiCaprio to play Alan Turing?

I hadn’t realised this before (update: err, actually I did – I wrote about this in October 2011 too, oops) but apparently Leonardo DiCaprio is to play Alan Turing in “The Imitation Game“, a biopic.

Leonardo DiCaprio at the Body of Lies film pre...
Leonardo DiCaprio at the Body of Lies film premiere in London (Photo credit: Wikipedia)

It’s fantastic news, not just because the idea of the film itself is appealing but because DiCaprio is surely one of the greatest film actors of this or any other generation. I sense that he’s never quite had the recognition he deserves because his first big role, in Titantic, was rather soft and slushy, but he is so good that even when he is in an otherwise mediocre film – J Edgar is a recent example – he lifts it to a higher plane.

In honour of Alan Turing

There is something great about the fact that the man who arguably did more than anyone else to preserve the freedoms that the reactionary right claim they want to protect was a gay scientist. Which do they hate more, the science or the homosexuality?

This was the best article I read bout Turing all week (thanks to the BBC who have done a good job all week) – Gay codebreaker’s defiance keeps memory alive

Sometimes those who wish to discount the importance of those who struggle to change society try to do that by explaining moments of inflection as random events – attempts to explain Rosa Parks‘s defiance as the action of a woman who was just too tired to move is a classic example – so it was good to read that Turing was no meek, put upon scientist, but a man with the courage to defy his oppressors.