<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Naxxfish</title>
	<atom:link href="http://naxxfish.eu/feed/" rel="self" type="application/rss+xml" />
	<link>http://naxxfish.eu</link>
	<description>Computer Systems Engineer</description>
	<lastBuildDate>Sat, 07 Jan 2012 15:51:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>A Walk through a Broadcast Audio Processor</title>
		<link>http://naxxfish.eu/2011/a-walk-through-a-broadcast-audio-processor/</link>
		<comments>http://naxxfish.eu/2011/a-walk-through-a-broadcast-audio-processor/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 00:42:43 +0000</pubDate>
		<dc:creator>naxxfish</dc:creator>
				<category><![CDATA[Broadcasting]]></category>

		<guid isPermaLink="false">http://naxxfish.eu/?p=586</guid>
		<description><![CDATA[Recently, CSR FM have aquired a Soundweb London BLU-100 (which I&#8217;ve raved about in the previous post). Amongst the myriad of things which it can do, it can also do some quite complex signal processing. Currently, the CSR FM airchain goes from program output (via a switcher), to a DSPXmini FM processor &#8211; which processes [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, CSR FM have aquired a Soundweb London BLU-100 (which I&#8217;ve raved about in the previous post).  Amongst the myriad of things which it can do, it can also do some quite complex signal processing.  Currently, the CSR FM airchain goes from program output (via a switcher), to a DSPXmini FM processor &#8211; which processes the audio and compresses it so that it&#8217;s of uniform loudness, then on to a 50W FM transmitter (of which we&#8217;re only using 25W).</p>
<p>Unfortunately, the FM processor does not have an audio output on it, only a MPX signal which goes directly to the transmitter (which has fancy things like stereo pilot and RDS encoded into it directly) &#8211; as such in order to do our online stream we have to have a FM tuner tuned into the frequency, which then gets distributed to a few places, including a Delta 44 on the encoder machine which then goes out to the online stream.</p>
<p>This isn&#8217;t ideal, for a couple of reasons.  Firstly, any FM signal gets a bit distorted no matter how close you are to the transmitter (it&#8217;s directly below it in the rack, in fact).  Secondly, the FM signal adds &#8216;clipping&#8217;, which is essentially cutting the peaks off waveforms flat.  You&#8217;d normally say this is distortion &#8211; and it is!  However, over FM, being an analogue medium, this actually sounds good and can add to the loudness of the station if done right.</p>
<p>But when going over a digital medium, it sounds horrible (and sounds like the input on the soundcard has been saturated).  It&#8217;s especially bad when you encode it into a lossy codec such as MP3 &#8211; the square edges of the waveforms have lots of high frequency components (check out <a href="http://www.youtube.com/watch?v=AjlHBx0zV7c">this video demonstrating how using the Fourier series a square wave</a> is made up of an infinite number of sine waves of increasing freuquency).  An MP3 encoder tries to compress the audio by removing &#8216;useless&#8217; information, that is frequencies that the human ear is less sensitive to.  If you throw in lots of high frequency components, it ends up thinking that these are important frequencies when in fact there is much more valuble information that it can compress in different parts of the spectrum.</p>
<p>So, we can come to the conclusion that using a clipped audio source for lossy digital transmission is not good.  This applies to online streaming as well as other digital media like DAB, DVB or XM broadcasting.</p>
<p>Therefore, we need a separate audio processor which does everything that our FM processor does, except without the clipping.  If we had a better processor &#8211; such as an Orban Optimod &#8211; it would have two outputs, one with clipping and one without.  Unfortunately we don&#8217;t have that much money to spend on processing, especially with the Studio 2 project ongoing.  So, therefore I decided that we might try to build our own processor using the BLU-100.</p>
<p>In essence, a broadcast processor has a few general stages which it uses to make the audio output of the station sound uniform and punchy.  Namely, these are -</p>
<ul>
<li>Wideband processing (gating, AGC, compression)</li>
<li>Multiband AGC</li>
<li>&#8216;Enhancement&#8217;</li>
<li>Multiband limiting/compression</li>
<li>Final limiting/brickwall limiting</li>
</ul>
<p>A bit like this:</p>
<p><a href="http://naxxfish.eu/wp-content/uploads/heierarchy1.png"><img class="aligncenter size-full wp-image-590" title="heierarchy" src="http://naxxfish.eu/wp-content/uploads/heierarchy1.png" alt="" width="1031" height="177" /></a></p>
<p>&nbsp;</p>
<p>My mission is to implement this using London Architect.  I have pretty much all the components I need in the audio processing section of my BLU-100, so lets give it a shot!</p>
<p><span id="more-586"></span></p>
<p><a href="http://naxxfish.eu/wp-content/uploads/wideband.png"><img class="aligncenter size-full wp-image-595" title="wideband" src="http://naxxfish.eu/wp-content/uploads/wideband.png" alt="" width="473" height="208" /></a></p>
<p>So this first section does some basic AGC and compression.  AGC standing for Automatic/Average Gain Control.  It acts a bit like a person riding the gain on a mixer, trying to make everything be at a set level.  In order to prevent &#8216;suck up&#8217; &#8211; that is, making background noise louder, there is a threshold at which it will stop trying to increase the gain.  This AGC is done by the two levellers in the diagram.  Unfortunately, they&#8217;re not stereo linked &#8211; this means it&#8217;s possible for them to apply different amounts of gain to the left or right channel, potentially affecting stereo image.  That&#8217;s rather unfortunate, but at the moment I don&#8217;t have a solution to this.  The gate will further reinforce the &#8216;freezing&#8217; by reducing the gain further after a given threshold.  This is set pretty low, just in case someone has some really quiet programme material &#8211; really all it does it cut out any noise from total silence (which is required, from time to time).</p>
<p>The compressor will reduce the dynamic range of the signal a little bit, and compensate for overshoot on the levellers (if they bring up the gain, then something really loud happens, they take a bit of time to react to this &#8211; the compressor will kick in and reduce the gain a little bit faster than the levellers will).</p>
<p><a href="http://naxxfish.eu/wp-content/uploads/mb-agc.png"><img class="aligncenter size-full wp-image-593" title="mb-agc" src="http://naxxfish.eu/wp-content/uploads/mb-agc.png" alt="" width="633" height="339" /></a>This beast is the multiband AGC.  This does what the wideband AGC does, except it splits it off into separate bands of frequencies before doing so.  The stereo crossover block is what splits up the frequencies.  I have found that designing an effective crossover is a bit tricky &#8211; it can take quite a bit of tweaking to get it to be transparent.  When I started tweaking, I put all of the levellers into bypass and solo&#8217;d each band on the mixer.</p>
<p>I have decided to use a 5-band design here &#8211; this seems to be fairly standard in broadcasting.  It allows us to get the most out of the high end, which is important when making your audio sound clean, crisp and &#8216;sparkly&#8217; &#8211; though overdone it can sound harsh and screechy (think blackboard + nails).  My settings for this are around about 0-200Hz for Low, 200Hz-750Hz Mid Low, 750Hz-2.6kHz Mid High, 2.6kHz-10kHz High, 10kHz up Super High.  Or something like that (a lot of tweaking was involved, I can&#8217;t remember the exact frequencies!).  A bit of gain correction was applied to the signals, owing to the fact they have different energies.  Getting the right crossover curves was tricky &#8211; if you get the wrong ones and set the crossover points wrong, you end up cancelling out frequencies, giving a comb effect which can sound nasty.</p>
<p>The levellers are set with a fairly low threshold, and a reasonable amount of maximum gain.  Tweaking these levellers is quite time consuming, and rather tricky.  Getting them to add gain to the right frequencies without making things sound too unbalanced is tricky.  Ideally, you don&#8217;t want the settings across the board to be too different &#8211; this can wreak havoc on your stereo image.  Again, annoyingly there&#8217;s no sidechain input on the levellers, so they&#8217;re independent left and right.  I&#8217;ve linked the controlls left and right, but as before &#8211; this doesn&#8217;t make any promises they&#8217;ll apply the same thing to both channels!</p>
<p>The mixer at the end mixes all the bands back together.  You can apply some fine tuning here, gently tweaking what bands you want to be preferred.</p>
<p>Next up, the magical &#8220;enhance&#8221; stage.</p>
<p><a href="http://naxxfish.eu/wp-content/uploads/enhance.png"><img class="aligncenter size-full wp-image-591" title="enhance" src="http://naxxfish.eu/wp-content/uploads/enhance.png" alt="" width="540" height="334" /></a>I&#8217;ve looked through a lot of processors &#8211; and they all seem pretty mysterious when it comes to this stage.  Most, if not all, provide you with an EQ that lets you provide your output with a signature sound.  In this case this is done by the parametric EQ on the far right.  The EQ adds a little extra bass (about +3dB at 65Hz) and takes out a few frequencies that can make voices sound a bit boomy.</p>
<p>What I&#8217;ve not shown here is there&#8217;s a bunch of meters attached at various points.  These meters are used to dynamically control things, such as the EQ.  The idea is that a combination of meters can let me work out whether the output is speech or music, and tweak the EQ accordingly.  Music will sound better with a more generous bass boost &#8211; whereas speech won&#8217;t benefit so much.  I&#8217;ve also added a few extra little bits that make our style of music sound a little nicer &#8211; adding to the station&#8217;s branding.</p>
<p>You will notice two sections which look fairly similar &#8211; one which has a low pass filter then a delay going into the mix, the other with a high pass.  The idea of this is to add to stereo image.  In radio, you want to sound loud, wide and big to keep people tuned in.  One way of doing this is to widen your stereo image.  The technique I&#8217;m using here is one method of stereo widening, which Wikipedia calls a <a href="http://en.wikipedia.org/wiki/3D_audio_effect">3D Audio Effect</a>.  This essentially amounts to taking the each side of the signal, delaying and attenuating it a bit, inverting the phase then adding it back to the opposite side.  I have found, however, that doing this can make voices sound a bit&#8230; strange.  Old Dr Who villeins come to mind.</p>
<p>Apparently, humans are more sensitive to the directionality of high frequency sounds than low (makes sense, they diffract about less in normal environments) &#8211; as such I&#8217;ve decided to not apply the effect to the midrange at all &#8211; just the high (from about 7kHz and up).  The delays are set slightly differently, making it sound more spactious (almost a basic reveb).    I&#8217;ve also done this to the low bass, just to add a bit of extra fat, wide bass.  The difference between these two delays (and the amount they are above the undelayed signal) is what a few processors I&#8217;ve seen call &#8216;width&#8217;.</p>
<p>Both of the levels that these two effects come in at are controlled by meters &#8211; they are mixed in at about a maximum of -10dB on the mixer, and a minimum of -36dB (almost inaudble).  Again, a lot of tweaking to get this right was involved.  But when it&#8217;s done right, it sounds pretty excellent.</p>
<p>And once we&#8217;ve added this mysterious loveliness, we&#8217;re almost there &#8211; onto the multiband limiter!</p>
<p><a href="http://naxxfish.eu/wp-content/uploads/mb-lim.png"><img class="aligncenter size-full wp-image-594" title="mb-lim" src="http://naxxfish.eu/wp-content/uploads/mb-lim.png" alt="" width="711" height="312" /></a>This is surprisingly similar to the mutliband AGC &#8211; in fact, it&#8217;s almost exactly the same, except the tasty filling between the crossover/mixer sandwich.</p>
<p>This time, we&#8217;ve got 5 stereo compressors (yay, stereo!).  These are set up much like any compressor for each of the 5 bands.  The bands picked for the limiter were slightly different, and more evenly spaced to control the full spectrum a bit better.</p>
<p>The low bands are quite heavily compressed, to give that tight bass sound that you want from pop and rock tracks, with a fairly high ratio and a medium threshold (I think they were around the -10dB mark with 8:1 ratio on the last tweak).  Appropriate amounts of makeup gain are applied, and you have some very energetic bass.  The midrange is less heavily processed, but still compressed a little bit to keep things equalised.  The high end is very heavily processed, very low threshold (around -20dB) and a very high ratio (about 14:1) with lots of makeup gain (about +10dB I think?).  This gives you the typical full trebble and bass sort of sound, which sounds decent over many different kinds of speakers.</p>
<p>The dynamic range of the input has been very very squashed at this point &#8211; aiming for everything to fit within about 3dB of range.  The final push is to give it a little extra in the final limiter.</p>
<p><a href="http://naxxfish.eu/wp-content/uploads/final-lim.png"><img class="aligncenter size-full wp-image-592" title="final-lim" src="http://naxxfish.eu/wp-content/uploads/final-lim.png" alt="" width="315" height="222" /></a>This is the simplest stage &#8211; consisting of just a compressor and two limiters.  Again, the limiters aren&#8217;t stereo &#8211; but in this instance we&#8217;re not that bothered.  The compressor is configured with a very high ratio and a high threshold (about -1.01dB) and the fastest attack time possible.  This should nicely clip the top of any remaining peaks which have made it through the other stages.</p>
<p>Anything that the compressor doesn&#8217;t catch, the limiters will cause them to hit a brick wall &#8211; with a faster attack time and a threshold set at about -0.3dB, they will almost guarantee that the final output will never ever be saturated.</p>
<p>&nbsp;</p>
<p>And that&#8217;s pretty much it!  The auctual configuration is pretty straightforward &#8211; but configuring the parameters to be just right is the tricky bit.  There are some parts which could certainly be improved (if I ever find a solution to making the mono objects stereo, that&#8217;ll be excellent), but for the last week I&#8217;ve been tweaking this system and have finally started homing in on a good sounding output, with a range of about 4dB (which is perfectly acceptable for an online stream, I&#8217;d say).</p>
<p>This is quite an experiment, and I&#8217;m not totally sure this is the right thing to do at all &#8211; but the results are sounding pretty good so far, so it can&#8217;t be that far wrong!</p>
]]></content:encoded>
			<wfw:commentRss>http://naxxfish.eu/2011/a-walk-through-a-broadcast-audio-processor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I </title>
		<link>http://naxxfish.eu/2011/i/</link>
		<comments>http://naxxfish.eu/2011/i/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 23:12:49 +0000</pubDate>
		<dc:creator>naxxfish</dc:creator>
				<category><![CDATA[Broadcasting]]></category>

		<guid isPermaLink="false">http://naxxfish.eu/?p=581</guid>
		<description><![CDATA[NOTE: This is most definitely not a tutorial, I&#8217;m mostly making it up as I go along. So, yeah &#8211; recently my radio station has acquired a rather lovely BSS Audio London Soundweb BLU-100.  It&#8217;s a &#8220;sound management&#8221; device, which (on the main unit) has 12 inputs (6 stereo) and 8 outputs (4 stereo), as [...]]]></description>
			<content:encoded><![CDATA[<p><strong>NOTE: This is most definitely not a tutorial, I&#8217;m mostly making it up as I go along.</strong></p>
<p>So, yeah &#8211; recently my radio station has acquired a rather lovely <a href="http://www.bssaudio.com/productpg_soundweblondon.php?product_id=65">BSS Audio London Soundweb BLU-100</a>.  It&#8217;s a &#8220;sound management&#8221; device, which (on the main unit) has 12 inputs (6 stereo) and 8 outputs (4 stereo), as well as 12 logic inputs and 6 logic outputs.  You can also add <a href="http://www.bssaudio.com/productpg.php?product_id=67">break-in</a> and <a href="http://www.bssaudio.com/productpg_soundweblondon.php?product_id=61">break-out</a> boxes to get even more inputs and outputs.  You can also hook two of them together with CAT5e and have 48 channels of audio going over it from one side to another.  Oh and did I mention it also has an Ethernet and RS232 interface?</p>
<p>But what does it do?  The question is rather what <em>doesn&#8217;t </em>it do.  What we&#8217;re going to be using it for is mainly routing audio around the radio station, and doing on-air switching (i.e. feeding the transmitter with audio from the right studio at the right time), as well as doing the processing for the online stream.</p>
<p>It is programmed using a (free) program called<a href="http://www.bssaudio.com/software.php?software=HiQnet+London+Architect+v3.08+R2&amp;Submit=Go"> London Architect</a>.  This program allows you to build up the configuration of the device by providing you with all the building blocks you need (source selectors, mixers, EQ, compressors, limiters to name but a few) and lets you join them up in any way you can imagine.  It&#8217;s quite reminiscent of LabView, except for audio &#8211; to give you an idea.  You can then send it the configuration over the network, and tweak the values using the same program.  It&#8217;s pretty intuitive, and an extremely powerful tool.</p>
<p><span id="more-581"></span></p>
<p><strong>Audio Processing</strong></p>
<p>This thing has so many options for audio processing.  For our purposes, our main use for this unit is to route audio from one place to another.  For example, we want to route audio from Studio 1 to Studio 2, or vice versa. All that&#8217;s required to do this is to drop in a matrix router object, hook all the inputs and outputs up and then set where the signals get routed to.  The particularly handy thing is you can define preset groups &#8211; for example a group of presets which alter what is sent to Studio 2.  You can then set up a preset for every audio input (changing the source each time) &#8211; and then later you can recall the preset remotely (say, over IP) and the audio will instantly get routed to the right place.</p>
<p>But you can do more than that!  There&#8217;s also EQs, and compressors, and levelers, limiters, crossovers, mixers, AGC mixers, and more.  With these blocks it&#8217;s possible to build up pretty complex designs &#8211; right now I&#8217;m working on a broadcast processor which includes a multiband AGC, and a multiband limiter, along with a stereo field expander and bass enhancer (I think that project is probably a post in it&#8217;s own right).</p>
<p>The only thing that&#8217;s slightly annoying is not all of the objects are stereo.  For example, limiters only have one input and one output.  Not great for stereo signals.  You can link the controls together, but they are still controlled by individual channels.  Really, in that situation you need to be able to have a mix of both left and right which control the device so that it applies the same processing to both left and right (to avoid weirdness) &#8211; some of them have sidechain inputs, but not all of them unfortunately.</p>
<p>You also have to be a bit careful not to let the internal channels clip &#8211; which whilst there is a good bit of headroom, it distorts rather nastily.  Also the compressors do suffer from distortion if you try to squash the waveform too much &#8211; but then at those extreme settings you&#8217;d expect that sort of thing of any compressor, especially a digital one.</p>
<p>The DSP power available is more than sufficient for our purposes.  So far, even with the most complex design (in terms of DSP power, anyway) I&#8217;ve only just about managed to use 50% capacity.  I may hit a barrier when I start putting everything together, but considering what can be done with it that&#8217;s pretty darn impressive.</p>
<p><strong>Digital Logic</strong></p>
<p>At the moment we&#8217;ve got a <a href="http://www.sonifex.co.uk/redbox/rboa3_ld.shtml">RB-OA3</a> which does that job through the use of offer and accept buttons in the studios.   You can either &#8220;offer&#8221; control of the air chain (that is, what eventually feeds into the transmitter) and &#8220;accept&#8221; it.  This is all run on standard 5V logic &#8211; you use push button switches and LEDs to operate it, which are in the studios.  It&#8217;s essentially a <a href="http://en.wikipedia.org/wiki/Finite-state_machine">finite state machine </a> hooked up to some relays which switch the audio, not dissimilar to a hifi pre-amp.</p>
<p>With that in mind, we want to migrate away from this switcher to the Soundweb, as this offers the ability to do this switching over IP (and potentially in an automated fashion).  However, it&#8217;d be nice to have an intermediate stage whilst we&#8217;re re-training our presenters how to use the new system (which will likely involve touchscreens in the studios instead of buttons) so that the switching works the way it always used to using the existing hardware.</p>
<p>Turns out London Architect also provides similarly powerful tools for building up logic, as well as audio processing.  It has AND, OR, NAND, NOR, NOT gates, counters, truth tables, clock sources (logic pulses, as they&#8217;re called) amongst other things which can be arranged in such a way to develop pretty complicated things.</p>
<p>The most powerful is surely the truth table object, which maps a give set of binary inputs into another given set of binary outputs.  For those digital electronics boffins out there, you might recognise this behaviour of that of a logic array.  And, yes, you can build almost anything with these truth tables &#8211; the only limit is the number of inputs and outputs you can have (I think it&#8217;s limited to 12 inputs or outputs).  So universial is this tool, a chap from <a href="http://www.radiofrance.fr/">Radio France</a> decided to write what essentially is a truth-table compiler.  You write code, in what suspiciously looks like VHDL, and it will compile that into the data to feed into a truth table.  You then wire it into your logic circuit and import the values it generates into the lookup table.   It&#8217;ll turn that truth table into a state machine (with some of the outputs feeding back into the inputs to indicate the current state), which can transition between states depending on what inputs you give it.</p>
<p>Aha! That sounds familiar!  Once I drew out the bubble diagram for the RB-OA3 &#8211; I could then write down all the states and transitions into this language and compile it into a truth table.  So that&#8217;s exactly <a href="http://www.bssaudio.com/phpBB2/viewtopic.php?t=781">what I did</a>.  All that I needed to do then was wire up the inputs and outputs to the appropriate I/O pins (a very straightforward task), have it fire off audio routing presets when certain states were reached and voila!  Not only that, but we could also finally get the On Air light working in the studios (hurrah!).</p>
<p>&nbsp;</p>
<p>So, to summarise: this thing is absolutely awesome.  Every small radio station should have one.  It&#8217;s a shame we&#8217;ve only got 2, both being installed &#8211; would like to have one to play with occasionally.  I have a theory I could use one to control a fridge&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://naxxfish.eu/2011/i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unnecessary Maths: My Milkshakes Bring Over a Million Boys to the Yard</title>
		<link>http://naxxfish.eu/2011/unnecessary-maths-my-milkshakes-bring-over-a-million-boys-to-the-yard/</link>
		<comments>http://naxxfish.eu/2011/unnecessary-maths-my-milkshakes-bring-over-a-million-boys-to-the-yard/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 23:10:10 +0000</pubDate>
		<dc:creator>naxxfish</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Random!]]></category>

		<guid isPermaLink="false">http://naxxfish.eu/?p=558</guid>
		<description><![CDATA[Canterbury is home to the Shake Shed, an awesome little shop that sells delicious milkshakes.  They will make you a shake with anything from chocolate chip cookies to sherbert lemon, to strawberry jam to Star mix &#8211; and you can have up to 3 flavours.  Not only that, they&#8217;ll do it with a smile! One [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://naxxfish.eu/wp-content/uploads/IMAG0128.jpg"><br />
</a>Canterbury is home to the <a href="http://www.shakeshed.com/">Shake Shed</a>, an awesome little shop that sells delicious milkshakes.  They will make you a shake with anything from chocolate chip cookies to sherbert lemon, to strawberry jam to Star mix &#8211; and you can have up to 3 flavours.  Not only that, they&#8217;ll do it with a smile!</p>
<p><a href="http://naxxfish.eu/wp-content/uploads/IMAG0139.jpg"><img class="aligncenter size-full wp-image-560" title="The Shake Shed!" src="http://naxxfish.eu/wp-content/uploads/IMAG0139.jpg" alt="" width="768" height="460" /></a></p>
<p>One day I was walking past and saw a sign outside, boastfully promising that there&#8217;s over a million different milkshakes to choose from.  I wondered &#8211; is it actually over a million?</p>
<p><span id="more-558"></span></p>
<p>So I asked.  Unfortunately, this wasn&#8217;t something that the people working on the till at the time knew off the top of their head.  Also, they didn&#8217;t know how many different flavours they had.  Time to do things the hard way&#8230;.</p>
<p>First things first, we need to know how many different flavours there are.  Lets get counting &#8230;.</p>
<p><a href="http://naxxfish.eu/wp-content/uploads/IMAG0127.jpg"><img class="aligncenter size-full wp-image-561" title="IMAG0127" src="http://naxxfish.eu/wp-content/uploads/IMAG0127.jpg" alt="" width="768" height="460" /></a><a href="http://naxxfish.eu/wp-content/uploads/IMAG0128.jpg"></a></p>
<p><a href="http://naxxfish.eu/wp-content/uploads/IMAG0128.jpg"><img class="aligncenter" title="IMAG0128" src="http://naxxfish.eu/wp-content/uploads/IMAG0128.jpg" alt="" width="768" height="460" /></a></p>
<p><a href="http://naxxfish.eu/wp-content/uploads/IMAG0130.jpg"><img class="aligncenter size-full wp-image-564" title="IMAG0130" src="http://naxxfish.eu/wp-content/uploads/IMAG0130.jpg" alt="" width="768" height="460" /></a></p>
<p><a href="http://naxxfish.eu/wp-content/uploads/IMAG0131.jpg"><img class="aligncenter size-full wp-image-565" title="IMAG0131" src="http://naxxfish.eu/wp-content/uploads/IMAG0131.jpg" alt="" width="768" height="460" /></a></p>
<div><a href="http://naxxfish.eu/wp-content/uploads/IMAG0136.jpg"><img class="aligncenter size-full wp-image-566" title="IMAG0136" src="http://naxxfish.eu/wp-content/uploads/IMAG0136.jpg" alt="" width="460" height="768" /></a></div>
<p>OK, so, they said milkshakes &#8211; so I&#8217;m not counting anything hot chocolate, or anything else.  Just milkshake flavours.  And, by my reckoning, they have 182 different items that you can have in your milkshake (yes, I really did just count them).</p>
<div><a href="http://naxxfish.eu/wp-content/uploads/IMAG01351.jpg"><img class="aligncenter size-full wp-image-567" title="Shake Shed Prices" src="http://naxxfish.eu/wp-content/uploads/IMAG01351.jpg" alt="" width="768" height="460" /></a></div>
<p>So then, as we can see above you can have between 1 and 3 flavours in your milkshake, and it can be one of two sizes.  You also have the choice between Skinny, Standard, Creamy and Soya milk.</p>
<p>Lets start simply.  Lets say our total number of flavours is <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> &#8211; there are <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> possible combinations with one flavour &#8211; simple enough</p>
<p>There are then <img src='http://s.wordpress.com/latex.php?latex=n%5E2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n^2' title='n^2' class='latex' /> combinations of two flavours. However, that&#8217;s all possible combinations, including ones where both flavours are the same &#8211; so we minus <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' />, which is the same as the first figure (as both are the same, it effectively counts as the same as 1 flavour)</p>
<p>And then <img src='http://s.wordpress.com/latex.php?latex=n%5E3&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n^3' title='n^3' class='latex' /> combinations of 3 flavours &#8211; again, we can minus <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> as the number where all 3 are the same.  But then we also have  <img src='http://s.wordpress.com/latex.php?latex=n%5E2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n^2' title='n^2' class='latex' /> combinations where two of the 3 are the same &#8211; i.e. we count 2 of the 3 to be &#8220;one&#8221; flavour, and use the previous figure of how many 2 combination shakes and eliminate them.</p>
<p>Add them all together, you get: <img src='http://s.wordpress.com/latex.php?latex=n%20%2B%28%20n%5E2%20-%20n%29%20%2B%20%28n%5E3%20-%20n%20%5E2%20-%20n%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n +( n^2 - n) + (n^3 - n ^2 - n)' title='n +( n^2 - n) + (n^3 - n ^2 - n)' class='latex' />,  let <img src='http://s.wordpress.com/latex.php?latex=n%20%3D%20182&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n = 182' title='n = 182' class='latex' /> and it comes out to be <strong>5,995,444</strong>.  Waaay over our over 1 million already.  But that&#8217;s not the end of the choices: we can also choose from 4 different milks: multiply that by 4 and you get</p>
<blockquote>
<p style="text-align: center;"><strong><em>23,981,776 combinations</em>. </strong></p>
</blockquote>
<p>Almost twenty four million possibilities. 48 million if you count regular and large as being different.  However, quite a few of them will be horrible, because they contain black jacks (I mean, really? Liquorice? And milk?)  But, I wonder, how many of them will contain one given flavour?</p>
<p>We can say in the case of 1 flavour shakes, only 1 out of <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' />will have blackjacks in it.  Easy enough.  In the case of 2 flavour shakes, there will be <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> out of <img src='http://s.wordpress.com/latex.php?latex=n%5E2%20-%20n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n^2 - n' title='n^2 - n' class='latex' /> flavours which have blackjacks as one of the two flavours.  And then, finally, there will be <img src='http://s.wordpress.com/latex.php?latex=n%5E2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n^2' title='n^2' class='latex' /> out of <img src='http://s.wordpress.com/latex.php?latex=n%5E3%20-%20n%5E2%20-%20n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n^3 - n^2 - n' title='n^3 - n^2 - n' class='latex' />.  Adding it all together, that means that <img src='http://s.wordpress.com/latex.php?latex=1%20%2B%20n%20%2B%20n%5E2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='1 + n + n^2' title='1 + n + n^2' class='latex' /> will have a particular flavour in it.  Let <img src='http://s.wordpress.com/latex.php?latex=n%20%3D%20182&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n = 182' title='n = 182' class='latex' /> again, and that gives us 33,307 combinations in which a particular flavour features.  Ew.  That&#8217;s a lot of manky blackjack milkshakes.  Or, looking at it positively, that&#8217;s a lot of potentially yummy banoffee pie milkshakes.</p>
<p>Lets throw in some more numbers here.  I&#8217;d say that the average diameter of a milkshake cup is about 8cm, and about 12cm tall.  And probably contains about 330ml of milkshake (at a guess).</p>
<p>If you were to put every possible milkshake combination in a line, the line would be long enough to go between London and Birmingham 10 times.  If it was a straight line, unrestricted by water, it&#8217;d get you about 1/3rd of the way into the Atlantic Ocean.  Likewise (if you have a few million milkshake floatation devices) the line would be able to go from Canterbury to Fes in Morocco.</p>
<p>If you piled them up one on top of another (as if you are trying to build some kind of milky space elevator), the top milkshake would be at an altitude of 2,877 km high &#8211; which is about between 6 and 10 times higher than the orbit of the <a href="http://en.wikipedia.org/wiki/International_Space_Station">International Space Station</a>.</p>
<p>If you poured out all of the possible milkshakes into a bucket, it would weigh about 7,900 tonnes, and be enough fluid to fill 3 <a href="http://en.wikipedia.org/wiki/Olympic-size_swimming_pool">Olympic Sized Swimming Pools</a>.</p>
<p>If it takes you about 1 minute to drink an entire milkshake, then it&#8217;d take you almost 63 years of solid drinking to get through every single combination.  That&#8217;s not including toilet breaks.  And, y&#8217;know, having a life (not that I can really talk, I&#8217;m spending my spare time doing maths for no reason.  At least I don&#8217;t need to pee the entire time).</p>
<p>&nbsp;</p>
<p>And out of all those combinations, the only one for me is Banoffee Pie.  Yummm&#8230;.</p>
<p><strong>UPDATE!</strong>: I did a piece on <a href="http://www.csrfm.com/">CSR FM</a> based on this post! <a href="http://podcasts.csrfm.com/speech/UnnececaryMaths-Milkshakes.mp3">Unnececary Maths &#8211; Milkshakes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://naxxfish.eu/2011/unnecessary-maths-my-milkshakes-bring-over-a-million-boys-to-the-yard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://podcasts.csrfm.com/speech/UnnececaryMaths-Milkshakes.mp3" length="4730372" type="audio/mpeg" />
		</item>
		<item>
		<title>Unnecessary Maths: McDonalds Marketing</title>
		<link>http://naxxfish.eu/2011/unnececary-maths-mcdonalds-marketing/</link>
		<comments>http://naxxfish.eu/2011/unnececary-maths-mcdonalds-marketing/#comments</comments>
		<pubDate>Thu, 12 May 2011 02:32:11 +0000</pubDate>
		<dc:creator>naxxfish</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://naxxfish.eu/?p=549</guid>
		<description><![CDATA[So I was in McDonalds today (lets not go into why) and found a piece of marketing that included some numbers. It said McDonald&#8217;s Litter patrols cover over 120,000 miles every year in the UK and Ireland. We are about the environment! (or something to that effect) I decided to break this down a bit. [...]]]></description>
			<content:encoded><![CDATA[<p>So I was in McDonalds today (lets not go into why) and found a piece of marketing that included some numbers.  It said</p>
<blockquote><p>McDonald&#8217;s Litter patrols cover over 120,000 miles every year in the UK and Ireland. We are about the environment!</p></blockquote>
<p>(or something to that effect)</p>
<p>I decided to break this down a bit.  After doing a bit of <a href="http://www.mcdonalds.co.uk/static/pdf/ourworld/openfarms/open-farms-newsletter-uk.pdf">research</a> I found that there were 1,200 restaurants in the UK and Ireland (60% of which are franchisees).  So, that makes each store cover 100 miles per year.  Divide that by 365 and we get 0.2739 miles per day covered in each day.  That&#8217;s about 440 meters every day.</p>
<p>Consider also that this is covered by presumably more than one person, and performed more than once a day.  Lets say for arguments sake that on average, there are 2 patrols every day.  So we cut out 440m in half to 220m.</p>
<p>The problem with this is it is a linear distance.  This tells us little about how much area is actually covered by the litter patrols.<a href="http://naxxfish.eu/wp-content/uploads/mcdonalds2.png"><img class="aligncenter size-full wp-image-552" title="mcdonalds" src="http://naxxfish.eu/wp-content/uploads/mcdonalds2.png" alt="" width="400" height="216" /></a></p>
<p>The actual distance travelled is dependant on the location of the restaurant.  If the restaurant is on a long street, then the distance travelled in each run would be approximately 4x the radius.  If it were located somewhere with more complex roads and alleys, this would be substantially more.  However, we can at least agree on that the distance travelled in one patrol is at least 4 times the furthest away that they get from the store.</p>
<p>So, we divide our 220m by 4.  That means that, roughly, the litter patrols go about 50m either side of the front door, twice a day</p>
<p>Now you break it down, it down I wonder why that sounds impressive.</p>
<p>&nbsp;</p>
<p>I suppose if you inflate any number enough, it can seem impressive.  For example, my heart has beaten over 58026240000 times since I was born.  Wow!  And it never stopped once!  (well, not for very long anyway).  You&#8217;ve <a href="http://discovermagazine.com/1995/apr/whatagas494">probably farted</a> about 456.25 liters of gas in the last year.  Lets say that&#8217;s mostly <a href="http://mistupid.com/chemistry/aircomp.htm">air</a>&#8230; that&#8217;s over 500g of farts!  And 16g of CO2.  I wonder how much of the UK&#8217;s CO2 emissions due to farts is generated by McDonalds employees going on litter patrols&#8230;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://naxxfish.eu/2011/unnececary-maths-mcdonalds-marketing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CSR FM Tech Blog</title>
		<link>http://naxxfish.eu/2011/csr-fm-tech-blog/</link>
		<comments>http://naxxfish.eu/2011/csr-fm-tech-blog/#comments</comments>
		<pubDate>Sun, 01 May 2011 22:31:38 +0000</pubDate>
		<dc:creator>naxxfish</dc:creator>
				<category><![CDATA[Broadcasting]]></category>

		<guid isPermaLink="false">http://naxxfish.eu/?p=544</guid>
		<description><![CDATA[So, I decided that CSR Technical Services needed a blog. So now it does! Here&#8217;s a copy of my first post there, about the recent issues we&#8217;ve had with the Station Switcher Here at CSR, we have a number of different places which we might want to broadcast from.  For example, we have two studios [...]]]></description>
			<content:encoded><![CDATA[<p>So, I decided that <a href="http://tech.csrfm.com/">CSR Technical Services</a> needed a blog.  So now it does!  Here&#8217;s a copy of my first post there, about the recent issues we&#8217;ve had with the <a href="http://tech.csrfm.com/?p=9">Station Switcher</a></p>
<p>Here at CSR, we have a number of different places which we might want to broadcast from.  For example, we have two studios (Studio 1 at the University of Kent, Studio 2 at Christ Church University) a sustainer service and we often perform Outside Broadcasts which require taking a signal from another source again.</p>
<p>Therefore, we have an airchain which includes a station switcher (specifically two <a href="http://www.sonifex.co.uk/redbox/rboa3_ld.shtml">Sonifex Redbox OA3</a> daisychained together to give us 5 possible audio sources).  In order to allow presenters to switch the station output between the sustainer service and the studio output, we provide two buttons &#8211; offer and accept.  The station switcher allows the operator of a studio to &#8220;offer&#8221; to take control from other studios, and &#8220;accept&#8221; control for other studios.  The sustainer, since there is no human present, cannot offer to take control &#8211; therefore a special case is given whereby the studios may force it to take control by holding the offer button then pressing accept.</p>
<p>The buttons (and indicator lights) are connected to the station switcher via a D-sub connector, which goes into a control interface. This is fine &#8211; however we wanted to be able to control the switcher from within Engineering where the switcher is located.  Thus, many years ago, one of the Tech crew built a 2U rackmount box which allowed us to &#8220;press&#8221; the offer and accept buttons remotely.  It essentially consisted of a box with a bunch of push to make buttons mounted on the front panel.</p>
<p>However, there was one slight issue &#8211; Studio 2 is at a remote site, and obviously we can&#8217;t run a piece of wire from the buttons half way across Canterbury to the switcher!  Therefore, we made use of the remote GPIO pins on the <a href="http://www.stl-ip.com/">MDO STL-IP </a>units which we use to transport audio to and from Studio 2.  This allows us to send digital signals (i.e. high or low) over IP &#8211; we connected up a switch box at Studio 2, plumbed this into the GPIO ports which were replicated up at Kent.  However, the signals which came from the STL-IP unit were not the same as the ones required by the switcher.  Therefore, in our custom made box we had to build some level shifting circuitry which converted the levels to ones which the switcher could accept.</p>
<p>This circuit was built on veroboard, and looked a lot like this:</p>
<p><img class="aligncenter" title="Station Switcher" src="http://farm6.static.flickr.com/5229/5675075167_fb3b34e93f.jpg" alt="" width="299" height="500" /></p>
<p>The chip at the bottom is a octal darlington array, the one at the top a hex inverter. This successfully shifts the level, and everything worked perfectly for the time which we had Studio 2 online.</p>
<p>This all worked just fine up until recently &#8211; however when we took out the STL-IP boxes for maintainance we discovered a slight flaw.  Since the STL-IP box was disconnected, the inputs on the CMOS inverter were floating.  This caused the control signals to the switcher to fluctuate wildly &#8211; this in turn caused the switcher to constantly give Studio 2 control of the switcher!  This was not good (thankfully we have backups in place to prevent this being a showstopping problem).</p>
<p>The solution: attack the insides of the switch box with a hacksaw, remove the circuit, and disconnect it permenantly.  Now, it shall never bother us again.</p>
<p>Until we need to work out how to remotely put Studio 2 on air.</p>
]]></content:encoded>
			<wfw:commentRss>http://naxxfish.eu/2011/csr-fm-tech-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How many ways can I say &#8230;</title>
		<link>http://naxxfish.eu/2011/how-many-ways-can-i-say/</link>
		<comments>http://naxxfish.eu/2011/how-many-ways-can-i-say/#comments</comments>
		<pubDate>Sun, 24 Apr 2011 01:13:58 +0000</pubDate>
		<dc:creator>naxxfish</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://naxxfish.eu/?p=518</guid>
		<description><![CDATA[My friend Kitty asked me a simple question the other evening: What is the total number of unique messages you can fit into 140 characters (i.e. a tweet) This seems like potentially quite a simple question. So, lets say you have a set of valid characters called , and a maximum message length of (in [...]]]></description>
			<content:encoded><![CDATA[<p>My friend <a href="http://quixotic.eu">Kitty</a> asked me a simple question the other evening:</p>
<blockquote><p><strong>What is the total number of unique messages you can fit into 140 characters (i.e. a tweet)</strong></p></blockquote>
<p>This seems like potentially quite a simple question.  So, lets say you have a set of valid characters called <img src='http://s.wordpress.com/latex.php?latex=C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C' title='C' class='latex' />, and a maximum message length of <img src='http://s.wordpress.com/latex.php?latex=l&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='l' title='l' class='latex' /> (in this case, equals 140).  For all messages consisting of one character, you have size of <img src='http://s.wordpress.com/latex.php?latex=C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C' title='C' class='latex' /> possibilities.  For two characters, you have <img src='http://s.wordpress.com/latex.php?latex=C%5E2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C^2' title='C^2' class='latex' /> possibilities &#8211; all the way up to <img src='http://s.wordpress.com/latex.php?latex=C%5El&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C^l' title='C^l' class='latex' />.  In math-speak:</p>
<img src='http://s.wordpress.com/latex.php?latex=%5Cdisplaystyle%5Csum_%7Bn%3D1%7D%5El%20C%5En&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\displaystyle\sum_{n=1}^l C^n' title='\displaystyle\sum_{n=1}^l C^n' class='latex' />
<p>Which, given that we know that the general formula for a geometric progression to be :<br />
<img src='http://s.wordpress.com/latex.php?latex=%5Cdisplaystyle%5Csum_%7Bk%3D0%7D%5E%7Bn%7D%20ar%5Ek%20%3D%20%5Cfrac%7Ba%281-r%5E%7Bn%2B1%7D%29%7D%7B1-r%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\displaystyle\sum_{k=0}^{n} ar^k = \frac{a(1-r^{n+1})}{1-r}' title='\displaystyle\sum_{k=0}^{n} ar^k = \frac{a(1-r^{n+1})}{1-r}' class='latex' /><br />
<a href="http://en.wikipedia.org/wiki/Geometric_progression#Geometric_series">Geometric progression (Wikipedia)</a>
</p>
<p>
We can substitute <img src='http://s.wordpress.com/latex.php?latex=a%20%3D%201&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='a = 1' title='a = 1' class='latex' />, <img src='http://s.wordpress.com/latex.php?latex=r%20%3D%20C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='r = C' title='r = C' class='latex' /> and <img src='http://s.wordpress.com/latex.php?latex=k%20%3D%20i&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='k = i' title='k = i' class='latex' /> giving us<br />
<img src='http://s.wordpress.com/latex.php?latex=%5Cdisplaystyle%5Csum_%7Bn%3D0%7D%5E%7Bl%7D%20C%5En%20%3D%20%5Cfrac%7B1-C%5E%7Bl%2B1%7D%7D%7B1-C%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\displaystyle\sum_{n=0}^{l} C^n = \frac{1-C^{l+1}}{1-C}' title='\displaystyle\sum_{n=0}^{l} C^n = \frac{1-C^{l+1}}{1-C}' class='latex' />
</p>
<p>For the sake of argument, lets say tweets can only be 8-bit ASCII (I know, terrible assumption to make, but lets just run with this), so the size of <img src='http://s.wordpress.com/latex.php?latex=C%20%3D%20255&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C = 255' title='C = 255' class='latex' />.  We shall also let <img src='http://s.wordpress.com/latex.php?latex=l%20%3D%20140&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='l = 140' title='l = 140' class='latex' />, since that is the maximum length of a tweet.  The answer is &#8230;. a very big number.  According to <a href="http://www3.wolframalpha.com/input/?i=%281+-+255^%28140%2B1%29%29%2F%281+-+255%29">Wolfram Alpha</a>, it&#8217;s<br />
<img src="http://naxxfish.eu/wp-content/uploads/unique_tweets.gif" alt="" title="Number of unique tweets" width="493" height="141" class="aligncenter size-full wp-image-535" /></p>
<p>That&#8217;s about 8 followed by over 300 zeros, and that&#8217;s being conservative (not including unicode, for example).  However, what we have just calculated is in fact all possible messages.  Including &#8220;xSADFt5hagarnw&#8221;, or &#8221;   s sssss     akasf&#8221;.  I can&#8217;t think of many people who would tweet that &#8211; or in fact be able to logically distinguish that from any other sequence of random letters.  What we actually want to know is the proportion of legible tweets</p>
<p><a href="http://naxxfish.eu/wp-content/uploads/tweet-venn.png"><img src="http://naxxfish.eu/wp-content/uploads/tweet-venn.png" alt="" title="Tweet Venn diagram" width="433" height="304" class="aligncenter size-full wp-image-540" /></a></p>
<p>This in turn requires us to define what we mean by legible.  We could, naively, create a grammar for messages that they might follow.  You might say that they contain words separated by spaces.  Sometimes the words can start with a # or a @, they can end with punctuation (like . , ? ! etc).  But then, we are eliminating legible (but low quality) messages like &#8220;!!!LOL!!!&#8221; or &#8220;i &lt;3 my v1@gra&#8221;.  Our grammar starts becoming more complex to accommodate these exceptions.  </p>
<p>One possible approach would be to estimate a channel grammar by taking all of the current traffic on the channel and create an unweighted graph generated using minimal a priori information (i.e. that words are separated by words, and contain non-whitespace characters).  The graph would then contain a path for every single &#8220;word&#8221; on the channel &#8211; with each node representing a character and it&#8217;s position in the word.  Once this specific graph is created, one could group common nodes together and generalise the graph, reducing the number of redundant nodes.  </p>
<p>Once the graph has been generalised sufficiently, one could then use graph theory to calculate all valid routes through the graph (or, as it would be, chain) &#8211; imposing the limits on the number of possible characters.  </p>
<p>Chances are, it&#8217;ll still be a pretty darn huge number.  However, we know that will certainly be a subset of the number we calculated earlier.  By continuing to feed in data to the graph, you would then be able to adapt to new words being adopted in various languages.  The total number of unique tweets is dependent on the vocabulary of the users.  </p>
<p>So, I would say that the answer to the original question is in fact: <strong>it depends</strong>.  And, given the general lack of any real central repository of vocabulary that all users must adhere to (which is a clarphing relief), the only way to determine it is by looking at it!  </p>
<p>Unfortunately, not a very mathematically beautiful answer &#8211; but then anything to do with language rarely is &#8230;. </p>
]]></content:encoded>
			<wfw:commentRss>http://naxxfish.eu/2011/how-many-ways-can-i-say/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML-RPC Benchmarking</title>
		<link>http://naxxfish.eu/2011/xml-rpc-benchmarking/</link>
		<comments>http://naxxfish.eu/2011/xml-rpc-benchmarking/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 18:09:24 +0000</pubDate>
		<dc:creator>naxxfish</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://naxxfish.eu/?p=515</guid>
		<description><![CDATA[Hokay, so, for my report, I needed to do some benchmarking of how well my XML-RPC server could perform. So I threw together a quick little script with Twisted which allows me to make manylots of requests at once. It makes two files: times.csv (which contains the length of time each request takes) and errors.csv [...]]]></description>
			<content:encoded><![CDATA[<p>Hokay, so, for my report, I needed to do some benchmarking of how well my XML-RPC server could perform.  So I threw together a quick little script with Twisted which allows me to make manylots of requests at once.  It makes two files: times.csv (which contains the length of time each request takes) and errors.csv (which dumps any errors that are encountered along the way).  </p>
<p>This is litterally the first revision so it&#8217;s incredibly hacky, but it does work fairly nicely.  </p>
<p>To create the benchmarker object, you issue the following commands:</p>
<pre name="code" class="py">
benchmark = Benchmark(200, 5000, url_of_server,method_name, ['method','params','here'])
</pre>
<p>And then to make it go:</p>
<pre name="code" class="py">
benchmark.setupReqs()
reactor.run() # start the reactor!
</pre>
<p>Here&#8217;s the code that currently makes it work.  It&#8217;s not at all documented but you should kinda be able to see what it&#8217;s doing.  </p>
<pre name="code" class="py">
#!/usr/bin/env python

from twisted.web.xmlrpc import Proxy
from twisted.internet import reactor
import sys
import datetime

class Request():
       def __init__(self, url, method, params):
               self.url = url
               self.method = method
               self.params = params
               self.start_time = 0
               self.end_time = 0
               self.value =  ""
               self.error = ""
               self.finished = False
               self.error_file = open('errors.csv','w+')

       def addCallback(self, callback):
               self.callback = callback

       def addErrback(self, errback):
               self.errback = errback

       def makeRequest(self):
               proxy = Proxy(self.url)
               proxy.callRemote(self.method,*self.params).addCallbacks(self.retSuccess, self.retFail)
               self.start_time = datetime.datetime.now()

       def __returned(self):
               self.end_time = datetime.datetime.now()

       def retSuccess(self, value):
               self.__returned()
               self.finished = True
               self.value = value
               self.callback(self,value)

       def retFail(self, error):
               self.__returned()
               self.finished = True
               self.error = error
               self.error_file.write("Error: %s" % error)
               self.callback(self,error)

       def isFinished(self):
               return self.finished

       def getTime(self):
               return (self.end_time - self.start_time) # this should be a timedelta

class Benchmark():
       def __init__(self, concurrent = 10, total = 100, url = 'http://localhost:7080/XMLRPC', method = 'date', params=[]):
               self.url = url
               self.method = method
               self.params = params
               self.concurrent_reqs = concurrent
               self.total_reqs = total
               self.open_reqs = 0
               self.current_reqs = 0
               self.error_file = open('errors.csv','w+')
               self.req_times_file = open('times.csv','w+')

       def makeLog(self, filename):
               self.log_file = open(filename,'w+')

       def makeRequest(self):
               req = Request(self.url, self.method, self.params)
               req.addCallback(self.reqSuccess)
               req.addErrback(self.reqError)
               req.makeRequest()
               self.open_reqs = self.open_reqs + 1

       def printReqDetail(self, req):
               #print "Request time: %d ms" % req.getTime().microseconds
               delta = req.getTime()
               print delta

       def reqFinished(self, req):
               self.printReqDetail(req)
               self.open_reqs = self.open_reqs - 1
               self.current_reqs = self.current_reqs + 1 # completed requests
               if ((self.current_reqs + self.open_reqs) < self.total_reqs):
                       self.makeRequest()
               else:
                       if self.open_reqs == 0:
                               reactor.stop() # made as many requests as we wanted to

       def reqSuccess(self,req,value):
               self.reqFinished(req)
               #print repr(value)

       def reqError(self,req, error):
               self.reqFinished(req)
               #print 'error', error

       def setupReqs(self):
               for i in range(0,self.concurrent_reqs): # make the initial pool of requests
                       self.makeRequest()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://naxxfish.eu/2011/xml-rpc-benchmarking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NEBFAP</title>
		<link>http://naxxfish.eu/2011/nebfap/</link>
		<comments>http://naxxfish.eu/2011/nebfap/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 13:08:55 +0000</pubDate>
		<dc:creator>naxxfish</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://naxxfish.eu/?p=511</guid>
		<description><![CDATA[So, due to it being a UCAS day here at my Higher Education Institution, I have been forced to seek my sandwiches elsewhere.  So I sauntered off to the theater/cinema cafe which normally has fairly decent sandwiches and cappuccinos.  Having not been here in a while, I had forgotten the perplexing problem of NEBFAP. That is [...]]]></description>
			<content:encoded><![CDATA[<p>So, due to it being a UCAS day here at my Higher Education Institution, I have been forced to seek my sandwiches elsewhere.  So I sauntered off to the theater/cinema cafe which normally has fairly decent sandwiches and cappuccinos.  Having not been here in a while, I had forgotten the perplexing problem of <abbr title="Napkin Exists Between Food and Plate">NEBFAP</abbr>. That is to say, Napkin Exists Between Food and Plate. This is what the aftermath of my BLT looked like:</p>
<p><a title="IMAG0027.jpg by naxxtor, on Flickr" href="http://www.flickr.com/photos/naxxtor/5595193160/"><img src="http://farm6.static.flickr.com/5027/5595193160_9a37a684df.jpg" alt="IMAG0027.jpg" width="500" height="299" /></a></p>
<p>What is the purpose of putting a paper napkin underneath your food?  As you can see &#8211; the food has been sitting on it and as such has made it dirty &#8211; and thus unsuitable for wiping ones hands or face on.  So that surely can&#8217;t be the reason for placing it there.  Is it instead to insulate the food from the plate?  Perhaps to make it simpler to clean?  If that were the case, why would you insulate the sandwich but not the salad &#8211; which has loads of (excessively mustardy) dressing drizzled over it.  Equally, if it was to prevent the food from touching the plate: why would the plate not be clean in the first place? And a similar argument regarding the salad again applies &#8211; if the plate isn&#8217;t clean enough to touch the sandwich, why is it in direct contact with the salad?</p>
<p>Now, thinking about it critically and somewhat laterally, I can see a potential reason for this.  A napkin would soak up any excess oil or fat which may be coming from the food.  This may be desirable, for example, with a cheese toastie &#8211; it would absorb the fat and prevent the plate from becoming greasy &#8211; and as such prevent the bread from becoming soggy and laden with grease. </p>
<p>Equally, as you may have noticed when making toast in the morning &#8211; if you place a hot slice of toast on a cold plate, water tends to condense under the toast making it soggy if left for any reasonable period of time.  The solutions to this being toast racks, or my personal favorite, a House of Toast (whereby you balance two pieces of toast against each other a la a house of cards &#8211; try it!).  Or, if you are in the business of turning out toast-based food items at a high rate, you may well place a clean, absorbent cloth underneath the toast such that any condensation is absorbed without making the toast soggy.</p>
<p>Condensation and excessive moisture is a problem for hot foods, especially during microwave cooking.  For example, MicroChips(tm) (the microwavable potato chips &#8211; not the electronic devices) have a &#8220;crisping pad&#8221; at the bottom of the pack.  This is essentially a thin metallic sheet adhered to a piece of card.  It&#8217;s purpose in life is to get very hot very fast (as metals tend to do in a microwave) and prevent moisture from collecting at the bottom of the pack, making the chips soggy.</p>
<p>So how does this relate to the problem of <abbr title="Napkin Exists Between Food and Plate">NEBFAP</abbr>?  I can only assume that putting a napkin underneath sandwiches has become standard practice &#8211; given that a number of the items served may be served toasted or cold, it&#8217;s easier to train staff to put napkins underneath <strong>all</strong> sandwiches, rather than differentiate.</p>
<p>Mystery solved &#8230; ?  I think that science may be required to verify this theory &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://naxxfish.eu/2011/nebfap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multicasting with Twisted Python</title>
		<link>http://naxxfish.eu/2011/multicasting-with-twisted-python/</link>
		<comments>http://naxxfish.eu/2011/multicasting-with-twisted-python/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 23:10:24 +0000</pubDate>
		<dc:creator>naxxfish</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://naxxfish.eu/?p=504</guid>
		<description><![CDATA[Part of my MEng project work is to write some server code which allows alerts to be raised and broadcast to computers in a call center (something along the line of an alarm monitoring response centre &#8211; bunch of people in a room which respond to personal alarms in peoples homes). This is but a [...]]]></description>
			<content:encoded><![CDATA[<p>Part of my MEng project work is to write some server code which allows alerts to be raised and broadcast to computers in a call center (something along the line of an alarm monitoring response centre &#8211; bunch of people in a room which respond to personal alarms in peoples homes).  This is but a small part of the complete system &#8211; which I have been integrating it into.  </p>
<p>The main bulk of the server code which I have written is one giant XML-RPC server, using the Twisted Python framework.</p>
<p>The XML-RPC server itself was immensely easy to implement &#8211; using the <a href="http://twistedmatrix.com/documents/current/web/howto/xmlrpc.html">Twisted XML-RPC howto</a>.  In fact, not a single bit of coding that I have done has had anything to do with XML-RPC.  I could have written the application end-to-end without having any idea how XML-RPC works &#8211; which is fantastic because I don&#8217;t care that much for this application!  </p>
<p>The next thing that I had to do was write in a component that would allow me to send out real time alerts to listening stations.  I figured, since this will most likely be running in a call centre of some sort, I could take advantage of multicasting to achieve this.  Essentially, all of the &#8220;listening&#8221; clients will join a multicast group (in this case, 224.0.0.1).  Then, when the XML-RPC server receives a call to raise an alert, it will then send out a UDP packet saying that an alert has been raised to that multicast group.  </p>
<p>Integrating a custom UDP protocol with an XML-RPC server?  Whoa, that&#8217;s gotta be hard right?  Nope.  Not in the slightest.  I wrote my (not particularly exciting) alert broadcasting code:</p>
<pre name="code" class="py">

from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
from twisted.application.internet import MulticastServer

class AlertBroadcast(DatagramProtocol):
	def sendAlert(self,status,alert_id, alert_msg):
		self.transport.write("%d:%s:%s" % (alert_id, status, alert_msg), ('224.0.0.1', 1337))

	def startProtocol(self):
		self.transport.joinGroup('224.0.0.1') # join a multicast group
</pre>
<p>Then, in my main server building code, added this:</p>
<pre name="code" class="py">
        r = APIRoot() # my root API class, descended from xmlrpc.XMLRPC
        alert_broadcast = AlertBroadcast()
        alertAPI = AlertsAPI(conn,auth,alert_broadcast) # the class to handle raising, acking and clearing alerts
        r.putSubHandler('alerts',alertAPI)
        # and I create all the required objects for the main XML-RPC server, and add it to 'r' (the root)
	reactor.listenMulticast(0, alert_broadcast)
	reactor.listenTCP(7080, server.Site(r))
        reactor.run()
</pre>
<p>And that&#8217;s it.  That&#8217;s literally all there was to it.  Integrating a HTTP server, and a custom mutlicast UDP protocol &#8211; done!  </p>
<p>I like <a href="http://twistedmatrix.com/">Twisted </a>- it&#8217;s awesome. </p>
]]></content:encoded>
			<wfw:commentRss>http://naxxfish.eu/2011/multicasting-with-twisted-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Helpdesk Sleuthing</title>
		<link>http://naxxfish.eu/2011/helpdesk-sleuthing/</link>
		<comments>http://naxxfish.eu/2011/helpdesk-sleuthing/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 21:13:32 +0000</pubDate>
		<dc:creator>naxxfish</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://naxxfish.eu/?p=497</guid>
		<description><![CDATA[I had an interesting query today on Helpdesk at an institution which will remain anonymous (but will be blatantly obvious to the people who know me).  A student came to the helpdesk and was faced with a perplexing problem.  Their lecturer had given them a website which they were required to use as part of [...]]]></description>
			<content:encoded><![CDATA[<p>I had an interesting query today on Helpdesk at an institution which will remain anonymous (but will be blatantly obvious to the people who know me).  A student came to the helpdesk and was faced with a perplexing problem.  Their lecturer had given them a website which they were required to use as part of the course (and written in their course guide).  The problem was, they could get to this website from a public PC (which are available for student&#8217;s use), and when they were off campus &#8211; but not via the wireless service or the network connection in their student accommodation on campus.  Perplexing.</p>
<p>They gave me the website address. We shall say it is called diversebiocultures.org.  I went to the address on my workstation (which is on the staff network) and sure enough, it went through just fine.  Perhaps they&#8217;ve got some weird proxy settings on their laptop, I thought.  Checked them and there was no such thing &#8211; everything set up correctly for Internet access, and they could access every other site just fine.  So I took one of our laptops which are pre-configured to use the wireless service, and bam &#8211; connection didn&#8217;t go through.  That&#8217;s odd.</p>
<p>So I decide to investigate further.  I looked up the domain name and it resolved to an IP which I knew was in the University&#8217;s network.  Except it wasn&#8217;t that of our usual web servers &#8211; it was on another network which I didn&#8217;t recognise.  Knowing that it must be on the local network, I did a traceroute.  The route mapped out went out of the building which I was in, to another building on the campus and down to a distribution switch &#8211; from the name I could see what building it was in.  That&#8217;s strange, I thought, there&#8217;s no machine rooms in that building that would be capable of hosting any servers.</p>
<p>I did a reverse DNS on the IP.  It has a hostname on the University&#8217;s domain: cromwell.wont.ac.uk (we shall say).  So clearly someone had requested that at some point with Computing &#8211; and most likely it was a static IP.  But again, the hostname wasn&#8217;t one which I recognised as being a server.</p>
<p>To the robtex machine!  I discovered by looking it up on robtex.com that it was in fact running a number of domains and websites.  About 12 domains in total.</p>
<p>I then decided to poke it a bit further.  I managed to get an error page up which told me that it was running Apache/1.3.41 on port 80.  Interesting. I decided to give it a portscan.  It was running ssh (OpenSSH), http and https. So most likely a Unix box of some description &#8211; makes sense for a server. I did some more poking and looking at the server headers, and discovered it was running PHP 5.2.13, which (as of this writing) is a pretty new version of PHP.  Bit of a strange combination, an old version of Apache but a brand spanking new version of PHP.  And, more interestingly, with the extended headers, it informed me that it was a Darwin build of PHP &#8211; so it&#8217;s more than likely an OS X machine (i.e. an Apple Mac &#8211; probably a desktop machine).</p>
<p>After investigating the other websites which the machine was serving, I managed to find a few references to the &#8220;creator&#8221; of the websites, with a link to his home page.  Surprisingly (or not surprisingly) his home page wasn&#8217;t hosted on the same machine.  However, this did give me the full details of who owned this machine, and, presumably, maintained it.</p>
<p>So there&#8217;s an OS X machine on the University&#8217;s network serving several websites &#8211; including one which is required to participate in a module on a course.  And the reason it doesn&#8217;t work on the wireless service?  Because the firewall rules were never requested from Computing to allow that kind of access to the network which it was sitting 0n.  Because it&#8217;s a staff network &#8211; for staff desktops.</p>
<p>Ended up passing the query back to be escalated to the right people &#8211; here&#8217;s hoping this person decides to host his website on, shock horror, the University&#8217;s web servers.  Which funnily enough have no problems being accessed on the wireless service or in student accommodation.</p>
]]></content:encoded>
			<wfw:commentRss>http://naxxfish.eu/2011/helpdesk-sleuthing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

