WiFi strife

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:

Flat_layout

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

(\nabla^2 + k^2)\psi(\mathbf{x}) = f(\mathbf{x})

where \psi(\mathbf{x}) represents some property of the WiFi radiation, i.e. the electric or magnetic field produced by the router, and f(\mathbf{x}) 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

Flat_areaTo 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:

Flat_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

\theta_{ray} \rightarrow 2\theta_{wall} - \theta_{ray}.

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 L, its flux is reduced by L^{-2} in accordance with uniform 3D propagation. After 20 rays the map looks like this:

Flat_20rays

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

Flat_power

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.

Animation8bit

Advertisements

10 thoughts on “WiFi strife

    1. I have drawn your floor with amray. Maybe you want to move your router in realtime. Just press the “LOAD” button and use the following string in the text box.

      2XW47.82399999999999_66.2590396160002Z47.82399999999999_149.612Z72.624_149.612Z72.624_237.61199999999997Z47.82399999999999_237.61199999999997Z47.82399999999999_304.59952000000004Z147.03552_304.59952000000004Z147.03552_344.63536Z47.82399999999999_406.89455999999996Z147.03552_406.89455999999996Z147.03552_383.3016Z65.11552_406.89455999999996Z65.11552_439.0072Z85.75936_439.0072Z85.75936_506.80887999999993Z65.11552_506.80887999999993Z65.11552_660.40888Z210.98751999999996_660.40888Z210.98751999999996_406.89455999999996Z201.15711999999996_406.89455999999996Z222.86591999999996_406.89455999999996Z265.46431999999993_406.89455999999996Z364.17792_406.89455999999996Z364.17792_549.81688Z299.46111999999994_596.10168Z299.46111999999994_618.2200799999999Z322.39871999999997_618.2200799999999Z322.39871999999997_629.6888799999999Z364.17792_629.6888799999999Z364.17792_660.40888Z364.17792_188.8584800000001Z265.46431999999993_188.8584800000001Z265.46431999999993_116.15448000000012Z286.4159200000001_116.15448000000012Z286.4159200000001_169.4024800000001Z364.17792_169.4024800000001Z364.17792_63.23882616320016Z270.1742183168_63.23882616320016Z270.1742183168_76.32536921600018Z254.20401262080003_76.32536921600018Z254.20401262080003_66.2590396160002Z222.05842163438942_66.2590396160002Z222.05842163438942_58.5632285669024Z170.57750154631418_58.5632285669024Z170.57750154631418_66.2590396160002Z141.0496013863142_66.2590396160002Z141.0496013863142_58.5632285669024Z77.95804175751425_58.5632285669024Z77.95804175751425_66.2590396160002Z270.1742183168_259.234337287542Z270.1742183168_304.59952000000004Z229.1520012839144_304.59952000000004Z265.46431999999993_304.59952000000004Z265.46431999999993_355.70332928754186Y0_1Z1_2Z2_3Z3_4Z4_5Z5_6Z6_7Z5_8Z8_9Z9_10Z11_12Z12_13Z13_14Z14_15Z15_16Z16_17Z17_18Z19_20Z21_22Z22_23Z23_24Z24_25Z25_26Z26_27Z27_28Z28_29Z29_17Z22_30Z30_31Z31_32Z32_33Z33_34Z34_35Z35_36Z36_37Z37_38Z38_39Z39_40Z40_41Z41_42Z42_43Z43_44Z44_45Z45_46Z46_47Z47_48Z48_0Z49_50Z50_51Z52_53XS132.86408128391474_105.08792128754237

      Sorry for the spamlike looking post. But there is no other way of sharing this to the world at the moment. 🙂

      Like

      1. That’s HTML/JavaScript but converted from Java by a Google Converter (Google Web Toolkit).
        Happy you like it. Congratulations to your blog. There are a lot of extremely interesting posts!!

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s