Friday, 21 April 2017

UK general elections - progressive alliance?


Another UK general election is coming. Again in the media a so-called progressive alliance is being talked about (e.g. Guardian). The background is that in the UK in general the conservative-right has normally held together in one party, whilst the liberal-left has been fragmented. And in a winner-takes-all voting system, the liberal-left has been badly hit over the years - but I want to know HOW badly.

Normally in the past it has simply been a case of Labour + Liberal (Democrats). Although these days one could probably add in other parties to the mix, like Green and maybe say SNP, Plaid Cyrmu, etc.


So, in 18/19 general elections, progressive parties received the largest vote share -- although there was a Conservative government in 9/19 cases and a Conservative-led government in 1 case. So this confirms in numbers that the voting system favours the Conservatives.

It is rare for the progressive parties to even go below 50% - e.g. it happened in 2015 presumably because (a) the LibDems were punished for going into a coalition with the Conservatives and (b) UKIP's vote-share rose lots (and it seems that UKIP has a mix of right-left-conservative voters).

EDIT: Andy requested the seat info too, so here it is:



Wednesday, 1 March 2017

Sleep tracker for baby

Aim: Track baby's sleep using images from baby monitor.

Camera: D-Link DCS-825L
   Example image 17.5 kb, 640x352 pixels, 96x96dpi, 24bit.




Method, use the change in image filesize as a proxy for baby movement:
  • Capture image using wget from local network 192.168.1.2/image/jpeg.cgi
  • Crop the image using mogrify (imagemagick) to remove date and time from image.
  • An artefact of the above makes night-vision jpeg images in greyscale (and keeps lighted images in colour); we'll see later that this is useful metadata.
  • Repeat as often as possible (e.g. every second); although maybe it is possible to overload the camera.
  • Write to file with columns: Year, Month, Day, Hour, Minute, Seconds, FileSize, Greyscale

Analysis
  • The jpeg filesize varies from 0 to about 130 bytes from second to second, even with no movement.
  • Baby movements gives up to 400 bytes of variation.
  • Adult movement gives many hundreds or thousands of bytes of filesize changes.
  • We can cut off the awake-time evening and morning data when the night-vision was off (this is presumably when an adult was in the room putting the baby to sleep and collecting the baby in the morning).
  • Each morning plot (using octave) the night's movements:
    • Sleep was from 9pm until 7am, with help from parents around 04:30 to 05:00 (plus baby's own movements around 10pm, midnight, 2am, 4am):




Useful link:
  • D-Link forum: http://forums.dlink.com/index.php?board=427.0

Monday, 16 January 2017

Automated capture of radio communications

PART 2
(see also earlier blog post about this)

Aim: to log lake temperature

Method: similar to before, but with new device.

Device:
 * "SODIAL(R) New Wireless Digital Floating Swimming Pool Thermometer Bath Spa Temperature" bought from Amazon
 * Example result for 13.0degC was 01011000 01111010 00010010 10011111 10101111 00110011 1

Other notes on message:
 - there's a 'calibration' set of 8 before the main message
 - Then a long time at "1"
 - Then a long time at zero
 - Then main message
 - The start of each bit jumps from 0 to 1
 - After each bit there is a jump from 1 to 0
 - The 0 "on" is longer than the 1 "on"
 - The bits seem to be of different widths for "1" and "0"


Decoding:
  * Calibrated from 4 temperatures between 3 and 31degC. A linear relationship found between temperature and bits 15-24 (T = mx + c, where T is temperature (degC), m=0.1, c=-40, and x is the message in bits 15-24).

In Linux or Windows (or even Raspberry Pi):
    rtl_sdr -s 1e6 -n 3.2e7 -f 433.85e6 -g 40 output.dat
This should create a 32-second data sample at 433.85 MHz with a gain of 40dB and save the file to "output.dat".


In Octave:
  fid = fopen('output.dat','rb'); 
  y = fread(fid,'uint8=>double'); 
  y = y-127.5; 
  y = y(1:2:end) + i*y(2:2:end); 
  plot(abs(y));

Then many lines of Octave code to interpret and clean signal,
and then writes result to data log file with each row as follows: Year,Month,Day,Hour,Minute,Temperature(degC)



Helpful websites included:
  • http://electronics.stackexchange.com/questions/145714/what-encoding-is-used-in-this-signal
  • http://sdr.osmocom.org/trac/wiki/rtl-sdr
  • http://aaronscher.com/wireless_com_SDR/RTL_SDR_AM_spectrum_demod.html 

Wednesday, 4 January 2017

Moisture indoors

In Finland in winter, the indoor air is normally so dry that it causes problems with cracking/itchy skin. Ideal indoor moisture should be 30-50% relative humidity (NB. too high RH causes damp/mould), but easily indoor RH can get down to 10% in cold spells in Finland.

I have bought a sonic humidifier that has a 1 litre capacity and takes about a day to emit this moisture into the air. I want to know roughly how much effect this might have.

I'm going to ignore effects of sources/sinks/storage like showers/cooking/washing/ventilation.

If we imagine a starting point of 20C and 25% RH, then this is about 4 g/m^3.


Now let's imagine instantaneously and evenly adding all that 1 litre (1000 g) of water into the air in my flat (72 m^2 and about 3m tall, so volume of about 216m^3). This would be adding 1000/216 = 4.6 g/m^3.

So we would be roughly doubling the moisture content, and the RH would increase to about 50%. This would be a great result.

Future blog update...estimate the effect of time on this scenario by looking at the rate at which the humidifier works and the rate of ventilation in/out of the flat...

Sunday, 25 September 2016

Obtaining and deciphering radio messages


Aim: to obtain and decipher radio messages from household devices.

Test device: Clas Ohlson (WS2015) temperature sensor - typical household 433MHz device.

Receiver: USB dongle (e.g. hsy® USB 2.0 Digital-DVB-T-DAB FM RTL2832U FC0013B SDR TV Radio Receiver-Stick) on a Windows laptop.

Data study and capture: SDR# (SDR sharp), 8bit wave file made of a couple of seconds and filesize of a few megabytes.

Understanding the data: each clock-cycle has a level shift (0/1). Logic1 has a level shift within a clock cycle, whilst logic0 does not. Bits 21-35 are temperature (scaled as +50 x 128). Useful website was http://ala-paavola.fi/jaakko/doku.php?id=wt450h

Data processing: done 'myself' in Octave -- the key command was wavread('FILENAME.wav'). But also some 'debouncing' was done to infill the many dropped "1" values. Plus all of the 6 messages were taken (2 channels, 3 messages per channel) after some synchronizing.

Hardware:
  
Software, SDR#:

Software, Octave:
Each minute 3 near-identical 36-bit messages sent:
  
Example, zoom in on first 5 bits of first message (notice the many 'dropped' "1" values): 
 
After tidying and then converting the binary message to a normal (decimal) value the result is found: 
 



See also Part 2





Tuesday, 13 September 2016

Winter wonderland

All winters are cold and snowy in Finland, but some much more than others.

Weather station at Helsinki Airport in Vantaa.
"Cold days" are with maximum temperature below 0C.
"Snow days" are simply days with at least some snow on the ground.
Winters are shown such that e.g. "2010" on the graph means the winter of 2009/10 (e.g. November 2009 --  April 2010).

Source: Finnish Meteorological Institute.

Summer days

I had the impression that this year had lovely summery weather. it did, and I enjoyed it lots. But apparently it was only about the same as the long-term (30-yr) average (of about 50 days per year), and even this year was cooler than some of the recent warmer summers that Helsinki's had in the last decade or so.
Weather station at Helsinki Airport in Vantaa.
"BBQ days" are with maximum temperature above 18C, at least 4 hours of sunshine and no rain.
"Hot days" are with maximum temperature above 25C.

Source: Finnish Meteorological Institute.