I’ve recently moved into a new flat, and to celebrate I bought a WiFi card for my PC rather than relying on a power line LAN adaptor – plug sockets are a valuable resource in a Victorian flat conversion and so shouldn’t be wasted on such trivial things.

Unfortunately, with my lovely new card freshly installed my connection was erratic at best, disconnecting more or less at random and generally being a first-class first-world problem. In a fit of internet-deprived mania I decided to investigate, the first act being to crash out a quick CAD drawing of the flat layout in Sketchup:

The card and router aren’t massively conveniently close to one another, so I had a go at modelling the expected WiFi hotspots/coldspots in the flat. Now, there are many ways to model this kind of thing – the most sophisticated would be start solving the inhomogenous Helmholtz equation

where represents some property of the WiFi radiation, i.e. the electric or magnetic field produced by the router, and is the source function, i.e. the router itself. The wavelength of the electromagnetic waves produced at 2.4GHz is approximately 12cm, and the computational grid required to resolve these would need to be more than an order of magnitude finer, which would start to place a computational demand too many on my poor overburdened laptop.

Happily, upon perusal of industry-standard methods for this sort of computation (e.g. http://www.awe-communications.com/Propagation/Indoor/Empirical/index.htm), decent results are obtained with simple ray-tracing. That is, treating the router as if it emits discrete ‘rays’ of WiFi radiation and bouncing them around/transmitting them as they hit walls.

I don’t know how to go from a Sketchup model to Matlab, and trying a random Matlab .stl reader somehow tried to use 50GB of RAM, so in the best traditions of the field I bodged my way through. Namely, I took a screenshot (!!) of the drawing and created a monochrome mask in ImageJ, where white == walls

To get reflections working I also need to know the angle of the walls. Once inside Matlab this is simple, I can take the gradient of the image in two orthogonal directions and find the angle corresponding to the peak gradient. The following image displays this – orange for horizontal walls, purple for vertical walls and white for diagonal walls:

Now, I choose a position for the router and this is the starting position for a set of rays. They propagate in straight lines until they reach a wall – reaching a part of the image of the flat where ‘wall == 1’ – and they are reflected according to

.

As they propagate a ‘flux map’ is built up which records the contribution of each ray to the WiFi flux which would be recorded at each point if a detector were present. Importantly, if the ray has propagated a distance , its flux is reduced by in accordance with uniform 3D propagation. After 20 rays the map looks like this:

And after 2000 we have something a little more filled-in:

As expected, only a small number of rays make their way into the WiFi-starved bunker where I keep my poor suffering PC, though happily I appear to get a direct line-of-sight to my bedside table near the diagonal wall. The kitchen (right-middle) also seems to do quite well from all of the reflections, suggesting I should buy that internet-connected coffee machine…

Now we have this nice little model lets play with the router position a little.