<?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>full stack</title>
	<atom:link href="http://stuartowen.com/home/feed/" rel="self" type="application/rss+xml" />
	<link>http://stuartowen.com/home</link>
	<description>Electrical engineer, Android developer, rock skipping enthusiast.</description>
	<lastBuildDate>Wed, 19 Jun 2013 00:55:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>HoloCalc Chosen by MKBHD!</title>
		<link>http://stuartowen.com/home/holocalc-chosen-by-mkbhd/</link>
		<comments>http://stuartowen.com/home/holocalc-chosen-by-mkbhd/#comments</comments>
		<pubDate>Sat, 08 Jun 2013 03:28:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Mobile Development]]></category>
		<category><![CDATA[holocalc]]></category>

		<guid isPermaLink="false">http://stuartowen.com/home/?p=272</guid>
		<description><![CDATA[Awesome!]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.youtube.com/watch?v=yR0ZGltMUTM&amp;feature=youtu.be&amp;t=5m20s">Awesome!</a></p>
<p><iframe style="line-height: 1.714285714; font-size: 1rem;" src="http://www.youtube.com/embed/yR0ZGltMUTM" height="360" width="640" allowfullscreen="" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://stuartowen.com/home/holocalc-chosen-by-mkbhd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing HoloCalc</title>
		<link>http://stuartowen.com/home/introducing-holocalc/</link>
		<comments>http://stuartowen.com/home/introducing-holocalc/#comments</comments>
		<pubDate>Thu, 21 Mar 2013 13:48:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Mobile Development]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[holocalc]]></category>

		<guid isPermaLink="false">http://stuartowen.com/home/?p=213</guid>
		<description><![CDATA[Hey guys!  I&#8217;ve just released an update to my long-coming side project HoloCalc.  I&#8217;m in the middle of making a <a class="read-more" href="http://stuartowen.com/home/introducing-holocalc/">.....</a>]]></description>
				<content:encoded><![CDATA[<p>Hey guys!  I&#8217;ve just released an update to my long-coming side project <a href="https://play.google.com/store/apps/details?id=com.brogramming.HoloCalc&amp;hl=en">HoloCalc</a>.  I&#8217;m in the middle of making a page for it, but I figured I&#8217;d post here about it first.  HoloCalc is a modern, feed-based calculator that lets users re-use their older calculations and inputs.  I went for the slick Holo theme, and added a lot of recent UI innovations we&#8217;ve seen to its interface (try long pressing the sin button!).  You can download it from the Play store:</p>
<p><a href="https://play.google.com/store/apps/details?id=com.brogramming.HoloCalc"> <img class="aligncenter" alt="Get it on Google Play" src="https://developer.android.com/images/brand/en_generic_rgb_wo_60.png" /> </a></p>
<p>Anyway, I&#8217;d love to hear what you think, feel free to send me an email at <a href="mailto:feedback@axelerateapps.com">feedback@axelerateapps.com</a>.  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://stuartowen.com/home/introducing-holocalc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delta-Sigma ADC Basics</title>
		<link>http://stuartowen.com/home/delta-sigma-adc-basics/</link>
		<comments>http://stuartowen.com/home/delta-sigma-adc-basics/#comments</comments>
		<pubDate>Mon, 13 Aug 2012 19:04:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electrical Engineering]]></category>
		<category><![CDATA[Embedded Design]]></category>
		<category><![CDATA[ADC]]></category>
		<category><![CDATA[modulator]]></category>
		<category><![CDATA[sigma delta]]></category>

		<guid isPermaLink="false">http://stuartowen.com/home/?p=182</guid>
		<description><![CDATA[Delta-sigma ADCs.  Not a new technology by any means, yet still they are regarded by many embedded engineers as mysterious <a class="read-more" href="http://stuartowen.com/home/delta-sigma-adc-basics/">.....</a>]]></description>
				<content:encoded><![CDATA[<p>Delta-sigma ADCs.  Not a new technology by any means, yet still they are regarded by many embedded engineers as mysterious and magical.  In this post, I’ll go through the basics of delta-sigma ADCs, and delta-sigma modulation on a higher level.</p>
<p>Understanding delta-sigma ADCs’ benefits compared to different ADCs (SARs, dual slope, etc) will require a broader understanding of delta-sigma modulation and its application in creating an ADC.  The block diagram below describes a delta-sigma modulator (DSM) on a high level.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/08/dsm-high-level.png"><img class="alignnone size-full wp-image-184" title="dsm high level" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/08/dsm-high-level.png" width="628" height="242" /></a></p>
<p>The input signal goes through a subtractor, taking the difference of the input and the output signal (fed through an impulse generator).  Remember, this output is a binary density stream!  When the output signal is 0, the differences passes the input signal straight through to the integrator.  This integrator continues to sum the input until it triggers the compare that follows it (at 0), at which point the output changes from a 0 to Vref.  We can think of this as one, for simplicity, but keep in mind that this block diagram is not implementation specific, so 1 may not make sense for every case.  When the output signal changes to Vref, the impulse block it passes through causes a very large, negative result from the difference, and thus creates a step down in the integrator’s output, causing the compare result to go to 0 again.  All of this can be a little difficult to imagine, so the figure below demonstrates the DSM modulating a DC signal.  In theory, the output goes high for an infinitesimally small amount of time, but let’s assume that this is a clocked digital system with a non-infinite impulse function so that we have a useable output.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/08/dsm-timing-diagram.png"><img class="alignnone size-full wp-image-185" title="dsm timing diagram" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/08/dsm-timing-diagram.png" width="628" height="470" /></a></p>
<p>This difference of sums (delta-sigma, ho-ho!) creates a delta-sigma modulated density stream whose duty cycle is equal to Signal In/Vref.  So, if Signal In is 0.5 Vref, we will see a 50% duty cycle delta-sigma modulated density stream at the output.</p>
<p>I can imagine you saying, “OK, that’s cool, but I thought we were talking about delta-sigma ADCs?”  We are, though!  This delta-sigma modulation is most of the work required to make a delta-sigma ADC.  To make this delta-sigma modulator into an ADC, we must simply count the density output and supply a periodic sample pulse to capture the counter’s result and reset it.  This relationship is laid out simply in the block diagram below.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/08/del-sig-adc-high-level.png"><img class="alignnone size-full wp-image-183" title="del sig adc high level" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/08/del-sig-adc-high-level.png" width="550" height="164" /></a></p>
<p>This reveals one of the great benefits of the delta-sigma ADC: the process of delta-sigma modulating the input into a density stream and summing it in a counter reduces aliasing of high frequency signals into the pass band greatly.  This means the delta-sigma ADC is more resistant to out-of-band noise than other types of ADC.</p>
<p>A practical (simple) implementation of the delta-sigma ADC is implemented below.  As we can see, the elements from the basic DSM block diagram are created here in their analog counterparts.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/08/del-sig-ADC-application.png"><img class="alignnone size-full wp-image-186" title="del sig ADC application" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/08/del-sig-ADC-application.png" width="914" height="483" /></a></p>
<p>In coming posts, I’ll talk about the benefits and drawbacks of delta-sigma ADCs as compared to other common ADCs (SAR, dual slope, etc.), and also how better, higher order delta-sigma ADCs can be made.  Thanks for reading!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://stuartowen.com/home/delta-sigma-adc-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Digital/Density Hardware Discrete Fourier Transform &#8211; The Basics</title>
		<link>http://stuartowen.com/home/digitaldensity-hardware-discrete-fourier-transform-the-basics/</link>
		<comments>http://stuartowen.com/home/digitaldensity-hardware-discrete-fourier-transform-the-basics/#comments</comments>
		<pubDate>Fri, 03 Aug 2012 06:01:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electrical Engineering]]></category>
		<category><![CDATA[Embedded Design]]></category>

		<guid isPermaLink="false">http://stuartowen.com/home/?p=162</guid>
		<description><![CDATA[I&#8217;ve been on a bit of a bender with density signals lately, so today I&#8217;m writing about a method for <a class="read-more" href="http://stuartowen.com/home/digitaldensity-hardware-discrete-fourier-transform-the-basics/">.....</a>]]></description>
				<content:encoded><![CDATA[<p><span style="line-height: 1.714285714; font-size: 1rem;">I&#8217;ve been on a bit of a bender with density signals lately, so today I&#8217;m writing about a method for doing Discrete Fourier Transforms (</span><a style="line-height: 1.714285714; font-size: 1rem;" href="http://en.wikipedia.org/wiki/Discrete_fourier_transform">DFTs</a><span style="line-height: 1.714285714; font-size: 1rem;">) using digital logic and density signals.  Before I get started, I have to give credit where it is rightfully due: much of my learning about density signals so far has come from </span><a style="line-height: 1.714285714; font-size: 1rem;" href="http://electronicdesign.com/article/analog-and-mixed-signal/signal-processing-in-the-density-domain-part-i-">a</a><a style="line-height: 1.714285714; font-size: 1rem;" href="http://electronicdesign.com/article/analog-and-mixed-signal/signal-processing-in-the-density-domain-part-ii-">series</a><a style="line-height: 1.714285714; font-size: 1rem;" href="http://electronicdesign.com/article/analog-and-mixed-signal/signal-processing-in-the-density-domain-part-iii-">of</a><a style="line-height: 1.714285714; font-size: 1rem;" href="http://electronicdesign.com/article/analog-and-mixed-signal/signal-processing-in-the-density-domain-part-iv-">articles</a><a style="line-height: 1.714285714; font-size: 1rem;" href="http://electronicdesign.com/article/analog-and-mixed-signal/signal-processing-in-the-density-domain-part-v-">by</a><span style="line-height: 1.714285714; font-size: 1rem;"> a colleague of mine, </span><a style="line-height: 1.714285714; font-size: 1rem;" href="http://www.cypress.com/?id=2201">Dave Van Ess</a><span style="line-height: 1.714285714; font-size: 1rem;">.    They&#8217;re a great read, and give wonderful insight into a different way of thinking about signal processing.  Also, the core idea of mixing density signals to facilitate a DFT is also his, this post will merely be an exploration of the process on a larger scale, as well as possible applications of the process.</span></p>
<p>There are many tools for signal processing of density signals (some more useful than others), but only a few will be used in this post: multiplication (aka mixing), modulation, and filtering (aka decimation, aka quantification, aka counting).</p>
<h4>Multiplication (Mixing)</h4>
<p>As you may or may not know, multiplying two signals in time &#8220;<a href="http://en.wikipedia.org/wiki/Electronic_mixer">mixes</a>&#8221; them.  For non-sinusoidal signals, mixing is somewhat difficult to picture, but when at least one of the two signals is a sinusoid, it becomes much easier.  If we take signal one with most of its spectral energy centered around f1, and signal two, which is a pure sinusoid at f2, and mix them, we would see the same spectrum form signal one, but shifted by plus and minus f2.  If we assume the two signals are sinusoidal, we&#8217;d see <a href="http://2.bp.blogspot.com/-hMvlTUI4API/TnxZidk2gRI/AAAAAAAAC1I/j9I11wQ3imY/s1600/AMmod.gif">this</a> in the time domain, and <a href="http://www.vk2zay.net/article/file/624">this</a> in the frequency domain.  What you really need to know is that you can mix a signal down to baseband (aka 0 Hz) to effectively filter and quantify the amount of signal at the mixing frequency.  This is also called demodulation, and is usually used for tone detection, SONAR, and a multitude of other cool applications.</p>
<p>Anyway!  Multiplication, which is traditionally done in large digital multipliers in hardware, can be done in a single logic gate in density.  It should be noted, though, that 0 in density doesn&#8217;t equate to 0; 0 in-fact equates to -Vref, where as 1 equates to +Vref.  This can usually be ignored, but makes the first quadrant of the multiply make sense: 0 times 0 is 1.  1*0 is 0, 0*1 is 0, and 1*1 is 1.  This functionality is equivalent to an XNOR gate, meaning we can mix density signals with just this XNOR gate.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/08/mixing.png"><img class="alignnone size-full wp-image-168" title="mixing" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/08/mixing.png" width="502" height="130" /></a></p>
<h4>Modulation (Analog or Digital to Density)</h4>
<p>Modulation is largely covered in an <a href="http://stuartowen.com/home/?p=148">earlier blog</a> post I wrote.  In short, it is the process of converting a digital signal to a density signal.  There are many ways of doing this, but delta-sigma modulation (the modulator shown below) is the best in this application.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/08/dsm.png"><img class="alignnone size-full wp-image-167" title="dsm" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/08/dsm.png" width="543" height="244" /></a></p>
<h4>Filtering (Density to Digital)</h4>
<p>Filtering is the process of quantifying a density signal into a digital signal.  Traditionally, quantification of a density signal is traditionally done in a counter, which doesn&#8217;t really sound much like a filter.  But it is!  Counting the density stream removes the high frequency variations that &#8220;come out in the wash&#8221; when counted and quantified, thus making this counting of the density signal acts as a low-pass filter.  Other more clever forms of filtering (converting from density to digital) are likely possible, but are not explored in this post.  The diagram below shows an example counter, with the density stream controlling its enable, a clock driving it at the density data rate, and another signal representing the decimation rate controlling the reset.  In theory, this decimation signal would also be inverted and tied to the gate of a latch or flip flop following the counter output, so that the final digital value could be captured.  It is important to note that the input signal is at the data rate, and the output data is at the decimated rate.  For example, if we are outputting a full-scale 8-bit value, we will be counting 256 separate density bits to quantify it.  This means our output data rate will be 256 times slower than our input data rate.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/08/counter.png"><img class="alignnone size-full wp-image-166" title="counter" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/08/counter.png" width="538" height="163" /></a></p>
<p>&nbsp;</p>
<p>This post is getting a bit long, so I&#8217;ll leave it off here.  If you&#8217;re clever, you might be able to pick it out from the diagram at the top of this post, otherwise, I&#8217;ll be posting the rest of the process soon.  Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://stuartowen.com/home/digitaldensity-hardware-discrete-fourier-transform-the-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Density Signals and Delta-Sigma Modulation, Part I</title>
		<link>http://stuartowen.com/home/density-signals-and-delta-sigma-modulation-part-i/</link>
		<comments>http://stuartowen.com/home/density-signals-and-delta-sigma-modulation-part-i/#comments</comments>
		<pubDate>Mon, 30 Jul 2012 09:21:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electrical Engineering]]></category>
		<category><![CDATA[Embedded Design]]></category>
		<category><![CDATA[modulator]]></category>
		<category><![CDATA[sigma delta]]></category>

		<guid isPermaLink="false">http://stuartowen.com/home/?p=148</guid>
		<description><![CDATA[Recently I’ve been quite taken by the idea of density signals.  These are similar to digital signals, but are instead <a class="read-more" href="http://stuartowen.com/home/density-signals-and-delta-sigma-modulation-part-i/">.....</a>]]></description>
				<content:encoded><![CDATA[<p>Recently I’ve been quite taken by the idea of density signals.  These are similar to digital signals, but are instead represented by a single bit for any given point in time.  A very common example of this is the output of a pulse-width modulator (PWM), which may drive an RC low-pass filter to create a simple digital to analog converter (DAC), facilitate some motor control, etc.  PWMs are commonly made with a single counter with a compare.  The continually counting counter’s compare output will be high during a given pulse width based on the compare result, and thus give the desired duty cycle.  Let’s say we want to create a DAC from this PWM.  We can do this as described above, by tying a resistor and capacitor to the output to create a low-pass filter.  The capacitor will act as the energy storage for the DAC, and the PWM’s duty cycle will define the output voltage of the DAC, assuming a sufficiently quick period for PWM.  The diagram below demonstrates this configuration.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/07/PWM-DAC.png"><img class="aligncenter" title="PWM DAC" src="http://stuartowen.com/home/wp-content/uploads/2012/07/PWM-DAC.png" alt="" width="440" height="191" /></a></p>
<p>&nbsp;</p>
<p>Very simply, the counter produces a signal of sufficiently high frequency such that the filter output is effectively a DC representation of the duty cycle described by the following equation.</p>
<p style="text-align: center;"> <a href="http://stuartowen.com/home/wp-content/uploads/2012/07/ouput-equation.png"><img class="alignnone size-full wp-image-153" title="ouput equation" src="http://stuartowen.com/home/wp-content/uploads/2012/07/ouput-equation.png" alt="" width="196" height="29" /></a></p>
<p>This is pretty cool and all, and allows us to create a decent DAC.  We can create analog signals using this PWM by changing the compare value in time, at a rate of at most once per counter period.  Again, this is called pulse width modulation, and it allows us to convert a digital signal &#8211; the one that controls the counter compare value – into a density signal, a string of bits whose duty cycle (or density!) describes its amplitude.  This conversion is between a single, quantized value and a string of bits representing this value is called modulation.  So, what is this delta-sigma modulation, and why is it so cool? Well, let’s look at a different way to make this DAC as s demonstration.</p>
<p>Let’s say that, instead of using a counter with a compare, we instead use an adder and a register to create our density signal.  This is done by registering the adder output and feeding it back into one of its inputs, and taking our digital duty cycle value (as a fraction of the adder width) and feeding it into the other adder input.  The overflow output of the adder will be our density stream output.  This whole circuit is shown in the following diagram.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/07/DSM-DAC.png"><img class="size-full wp-image-152 aligncenter" title="DSM DAC" src="http://stuartowen.com/home/wp-content/uploads/2012/07/DSM-DAC.png" alt="" width="619" height="222" /></a></p>
<p>&nbsp;</p>
<p>Ok, so what does this do?  Let’s look at a simple example: we will use a common 8-bit adder, and we will use a duty cycle of 50%.  To do this, we place 128 in the duty cycle register, which causes the adder to overflow every other operation.  For a duty cycle of 25%, we use 256/4 = 64, which causes the adder to overflow every 4 operations.  For a duty cycle of 75%, we use 256*3/4 = 192, which causes the adder to overflow 3 out of every four operations.  Why is this desirable?  Because it moves the modulation frequency as high as possible for each given duty cycle, ensuring that digital feed-through at the filter output is minimized, giving you a maximally smooth output.  This modulation scheme is called Delta-Sigma Modulation (DSM).  It is useful for DAC creation, but is particularly useful in analog to digital converters (ADCs), as I will discuss in a later blog post.</p>
<p>To test these claims, I’ve created a couple simple <a href="http://stuartowen.com/blog_posts/density_dsm_i/modulator.py">python classes</a> for the PWM and DSM, and tested them with a modulation period of 256 and a duty cycle of 1/8.  The time domain results are as expected, with the PWM producing a single high and single low pulse for each period, and the DSM producing many high and low pulses, as frequently as possible for this decimation period, as shown in the below plots.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/07/DSM-vs-PWM-time-domain.png"><img class="size-full wp-image-150 aligncenter" title="DSM vs PWM time domain" src="http://stuartowen.com/home/wp-content/uploads/2012/07/DSM-vs-PWM-time-domain.png" alt="" width="815" height="615" /></a></p>
<p>Of particular interest is the resulting frequency spectrum, though.  We can see in the below diagram that the PWM has many more low-frequency components, which are much more likely to get through the RC low-pass filter in our DAC.  The DSM, on the other hand, has its energy in much higher frequencies, which are much less likely to bleed through the low-pass filter.  We see this in the figure below.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/07/DSM-vs-PWM-frequency-domain.png"><img class="size-full wp-image-149 aligncenter" title="DSM vs PWM frequency domain" src="http://stuartowen.com/home/wp-content/uploads/2012/07/DSM-vs-PWM-frequency-domain.png" alt="" width="815" height="615" /></a></p>
<p>DSM DACs are pretty cool, but DSM ADCs are much more impressive, and as the embedded world grows to embrace them, understanding them will be integral in utilizing them well.  I will explore these in a future blog post, as well as an exploration of signal processing on density signals.  Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://stuartowen.com/home/density-signals-and-delta-sigma-modulation-part-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simulating Noise in Python</title>
		<link>http://stuartowen.com/home/simulating-noise-in-python/</link>
		<comments>http://stuartowen.com/home/simulating-noise-in-python/#comments</comments>
		<pubDate>Sun, 10 Jun 2012 04:30:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electrical Engineering]]></category>
		<category><![CDATA[Embedded Design]]></category>
		<category><![CDATA[fir filter]]></category>
		<category><![CDATA[noise]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[simulation]]></category>

		<guid isPermaLink="false">http://stuartowen.com/home/?p=91</guid>
		<description><![CDATA[You know what’s great?  Simulating stuff, especially simulating a whole system.  There is one problem that usually shows up, though: <a class="read-more" href="http://stuartowen.com/home/simulating-noise-in-python/">.....</a>]]></description>
				<content:encoded><![CDATA[<p><span style="line-height: 1.714285714; font-size: 1rem;">You know what’s great?  Simulating stuff, especially simulating a whole system.  There is one problem that usually shows up, though: how do you supply realistic data, similar to that you’re seeing on your scope?  You can gather samples from the scope and feed it to the simulation, but doing tests on multiple data sets becomes tiresome and isn’t a robust solution.</span></p>
<p>So, how do you generate random noise for your simulation?  You can use the python random package, but the random functions give you spectrally generic results (flat, Gaussian, etc.).  What we want to do is take white, spectrally flat noise as an input and filter it to control its frequency spectrum.  Sounds pretty simple, but how do we create this magical filter with a completely arbitrary frequency response?</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/06/fir-filter-structure.png"><img class="alignnone size-full wp-image-101" title="fir filter structure" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/06/fir-filter-structure.png" width="602" height="345" /></a></p>
<p>Before we get too caught up in thinking about complex filters for a specific use case, it would be good to recall the FIR filter. It’s a simple filter that implements a weighted average to do its filtering.  Arriving at the filter coefficients is somewhat of a mystery to some people: these coefficients are usually found by using some filtering toolbox somewhere so people don’t have to worry their pretty little heads about how the filter actually works.  Luckily, the FIR filter is much easier to understand than its IIR relative.  The FIR filter is uniquely useful in this case because of how its filtering is related to its coefficients:  the filter’s coefficients are simply a summation of sine waves at the frequencies in the pass band.  Due to the rectangular nature of commonly desired filter spectrums (pass-bands), this summation usually ends up taking the shape of a sinc pulse.  The figure below shows the sine wave frequencies that define the pass-band for an arbitrary filter, and the following figure shows the summation of these sine waves.</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/06/sine-waves-diff-frequencies.png"><img class="alignnone size-full wp-image-98" title="sine waves diff frequencies" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/06/sine-waves-diff-frequencies.png" width="483" height="291" /></a></p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/06/sinc-summation.png"><img class="alignnone size-full wp-image-97" title="sinc summation" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/06/sinc-summation.png" width="483" height="291" /></a></p>
<p>Due to the discrete nature of the sine wave summation, the sinc pulse is somewhat deformed, but still adequately demonstrates typical FIR coefficients.  Thinking a little bit more about this, we realize that an FIR filter is really just convolution of your data with a summation of all the sine waves of frequencies inside the pass band.   Knowing this, we can step back a bit: if every signal is a summation of sine waves of varying frequencies, and we have a signal whose spectrum we are trying to use to filter data, why not just use the data itself as the FIR filter coefficients?  The solution for this problem doesn’t even require messing around with FFTs and IFFTs.  Now, our block diagram for the system is clear:</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/06/block-diagram.png"><img class="alignnone size-full wp-image-100" title="block diagram" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/06/block-diagram.png" width="581" height="348" /></a></p>
<p>All right, now, making it in Python!  You’ll need numpy and scipy to follow through this example. Matplotlib is also used for plotting purposes.  First, we’ll need to create an FIR filter class.  An FIR filter class exists in scipy, but it contains a lot of unneeded bloat for this application, and creating the class may help us understand FIR filters a little better.  Firstly, FIR filters have two attributes: coefficients and state variables.  State variables are stored data within the filter; for FIR filters, it is merely the last N inputs to the filter, where N is the number of coefficients used in the filter.  So, our class will start out as:</p>
<pre style="color: #000000; background-color: #ffffff; padding-left: 30px; background-position: initial initial; background-repeat: initial initial;"><span style="color: #800000; font-weight: bold;">class</span> firFilter<span style="color: #808030;">:</span>

    coefficients <span style="color: #808030;">=</span> numpy<span style="color: #808030;">.</span>array<span style="color: #808030;">(</span><span style="color: #808030;">[</span><span style="color: #808030;">]</span><span style="color: #808030;">)</span>

    stateVariables <span style="color: #808030;">=</span> numpy<span style="color: #808030;">.</span>array<span style="color: #808030;">(</span><span style="color: #808030;">[</span><span style="color: #808030;">]</span><span style="color: #808030;">)</span></pre>
<p>The filter class needs only two functions: __init__() and processSample().  The first is the constructor the for the class, which puts everything in the right place and sets up all the important variables, in this case assigning the filter coefficients and initializing the state variable list. __init__() should look like:</p>
<pre style="color: #000000; background-color: #ffffff; padding-left: 30px; background-position: initial initial; background-repeat: initial initial;"><span style="color: #800000; font-weight: bold;">def</span> <span style="color: #e34adc;">__init__</span><span style="color: #808030;">(</span>self<span style="color: #808030;">,</span> filterCoeffs<span style="color: #808030;">)</span><span style="color: #808030;">:</span>
    <span style="color: #800000; font-weight: bold;">if</span> <span style="color: #808030;">(</span><span style="color: #e34adc;">type</span><span style="color: #808030;">(</span>filterCoeffs<span style="color: #808030;">)</span> <span style="color: #808030;">=</span><span style="color: #808030;">=</span> numpy<span style="color: #808030;">.</span>ndarray<span style="color: #808030;">)</span><span style="color: #808030;">:</span>
        <span style="color: #696969;"># Save input filter coefficients</span>
        self<span style="color: #808030;">.</span>coefficients <span style="color: #808030;">=</span> filterCoeffs
    <span style="color: #696969;"># Initialize filter state variables</span>
    self<span style="color: #808030;">.</span>stateVariables <span style="color: #808030;">=</span> numpy<span style="color: #808030;">.</span>array<span style="color: #808030;">(</span><span style="color: #808030;">[</span><span style="color: #008c00;">0</span><span style="color: #808030;">]</span><span style="color: #808030;">*</span><span style="color: #e34adc;">len</span><span style="color: #808030;">(</span>filterCoeffs<span style="color: #808030;">)</span><span style="color: #808030;">)</span>
    <span style="color: #800000; font-weight: bold;">else</span><span style="color: #808030;">:</span>
        <span style="color: #800000; font-weight: bold;">raise</span> <span style="color: #e34adc;">TypeError</span><span style="color: #808030;">(</span><span style="color: #0000e6;">"Wrong type for filterCoeffs, "</span><span style="color: #808030;">+</span>
                <span style="color: #0000e6;">"should be numpy.ndarray."</span><span style="color: #808030;">)</span></pre>
<p>This allows anyone utilizing the class to create filters of arbitrary length.  Next, the processSample() function needs to do simply that: take an input value, process the filter, and return the result.  This amounts to popping the oldest sample from the state variables list and appending the newest sample.  Thanks to some optimizations in numpy, processing the filter can be done with a simple matrix multiplication and sum.  The processSample() function will look like:</p>
<pre style="color: #000000; background-color: #ffffff; padding-left: 30px; background-position: initial initial; background-repeat: initial initial;"><span style="color: #800000; font-weight: bold;">def</span> processSample<span style="color: #808030;">(</span>self<span style="color: #808030;">,</span> inputSample<span style="color: #808030;">)</span><span style="color: #808030;">:</span>

    <span style="color: #696969;"># Add new sample to state variables, remove oldest one</span>
    self<span style="color: #808030;">.</span>stateVariables <span style="color: #808030;">=</span> numpy<span style="color: #808030;">.</span>append<span style="color: #808030;">(</span>numpy<span style="color: #808030;">.</span>delete<span style="color: #808030;">(</span>self<span style="color: #808030;">.</span>stateVariables<span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span>
    inputSample<span style="color: #808030;">)</span>

    <span style="color: #696969;"># Calculate filter output</span>
    <span style="color: #800000; font-weight: bold;">return</span> sum<span style="color: #808030;">(</span>numpy<span style="color: #808030;">.</span>multiply<span style="color: #808030;">(</span>self<span style="color: #808030;">.</span>coefficients<span style="color: #808030;">,</span> self<span style="color: #808030;">.</span>stateVariables<span style="color: #808030;">)</span><span style="color: #808030;">)</span></pre>
<p>Simple, right?  Now that we’ve created our FIR class, we’ll need to create the noise shaping class that utilizes it.  It will need an instance of our new FIR class, as well as an array to hold the sampled noise data.  It’ll start out like:</p>
<pre style="color: #000000; background-color: #ffffff; padding-left: 30px; background-position: initial initial; background-repeat: initial initial;"><span style="color: #800000; font-weight: bold;">class</span> shaper<span style="color: #808030;">:</span>

    <span style="color: #696969;"># This list of doubles controls signal amplitude across the frequency</span>
    <span style="color: #696969;"># spectrum.</span>
    sampleNoise <span style="color: #808030;">=</span>numpy<span style="color: #808030;">.</span>array<span style="color: #808030;">(</span> <span style="color: #808030;">[</span><span style="color: #808030;">]</span><span style="color: #808030;">)</span>

    <span style="color: #696969;"># This is te FIR filter instance used to filter noise</span>
    noiseFilter <span style="color: #808030;">=</span> <span style="color: #e34adc;">None</span></pre>
<p>Similar to the FIR class, this one will only need a couple functions: __init__() and getNoise().  __init__() (the class constructor) will need the noise sample as a list, and will construct the FIR filter instance:</p>
<pre style="color: #000000; background-color: #ffffff; padding-left: 30px; background-position: initial initial; background-repeat: initial initial;"><span style="color: #800000; font-weight: bold;">def</span> <span style="color: #e34adc;">__init__</span><span style="color: #808030;">(</span>self<span style="color: #808030;">,</span> sampleData<span style="color: #808030;">)</span><span style="color: #808030;">:</span>
    <span style="color: #696969;"># Check sampleData is of correct type</span>
    <span style="color: #800000; font-weight: bold;">if</span> <span style="color: #808030;">(</span><span style="color: #e34adc;">type</span><span style="color: #808030;">(</span>sampleData<span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">in</span> <span style="color: #808030;">[</span><span style="color: #e34adc;">list</span><span style="color: #808030;">,</span> numpy<span style="color: #808030;">.</span>ndarray<span style="color: #808030;">]</span><span style="color: #808030;">)</span><span style="color: #808030;">:</span>
        self<span style="color: #808030;">.</span>sampleNoise <span style="color: #808030;">=</span> numpy<span style="color: #808030;">.</span>array<span style="color: #808030;">(</span>sampleData<span style="color: #808030;">)</span>

    <span style="color: #800000; font-weight: bold;">else</span><span style="color: #808030;">:</span>
        <span style="color: #800000; font-weight: bold;">raise</span> <span style="color: #e34adc;">TypeError</span><span style="color: #808030;">(</span><span style="color: #0000e6;">"Incorrect type for sample data"</span><span style="color: #808030;">+</span>
                        <span style="color: #0000e6;">".  It should be numpy.ndarray or list."</span><span style="color: #808030;">)</span>

    self<span style="color: #808030;">.</span>noiseFilter <span style="color: #808030;">=</span> firFilter<span style="color: #808030;">(</span>self<span style="color: #808030;">.</span>sampleNoise<span style="color: #808030;">)</span></pre>
<p>The getNoise() is even simpler.  It requires no input, and supplies a random, spectrally shaped noise sample:</p>
<pre style="color: #000000; background-color: #ffffff; padding-left: 30px; background-position: initial initial; background-repeat: initial initial;"><span style="color: #800000; font-weight: bold;">def</span> getNoise<span style="color: #808030;">(</span>self<span style="color: #808030;">)</span><span style="color: #808030;">:</span>
    <span style="color: #800000; font-weight: bold;">return</span> self<span style="color: #808030;">.</span>noiseFilter<span style="color: #808030;">.</span>processSample<span style="color: #808030;">(</span>random<span style="color: #808030;">.</span>random<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span></pre>
<p>Now, we can test our hypothesis!  To start, the sampled “noise” will be a sine wave of arbitrary frequency.  This will make verification much easier, and it’s very easy to generate.  It looks like:</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/06/source-data-and-spectrum.png"><img class="alignnone size-full wp-image-99" title="source data and spectrum" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/06/source-data-and-spectrum.png" width="815" height="615" /></a></p>
<p>Now, we can insert some code at the end of our python file to test out the noise generator:</p>
<pre style="color: #000000; background-color: #ffffff; padding-left: 30px; background-position: initial initial; background-repeat: initial initial;">mySampleData <span style="color: #808030;">=</span> <span style="color: #808030;">[</span>numpy<span style="color: #808030;">.</span>sin<span style="color: #808030;">(</span>numpy<span style="color: #808030;">.</span>pi<span style="color: #808030;">*</span>a<span style="color: #808030;">/</span><span style="color: #008c00;">10</span><span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">for</span> a <span style="color: #800000; font-weight: bold;">in</span> <span style="color: #e34adc;">range</span><span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">1024</span><span style="color: #808030;">)</span><span style="color: #808030;">]</span>

x <span style="color: #808030;">=</span> shaper<span style="color: #808030;">(</span>sampleData <span style="color: #808030;">=</span> mySampleData<span style="color: #808030;">)</span>

<span style="color: #800000; font-weight: bold;">from</span> matplotlib <span style="color: #800000; font-weight: bold;">import</span> pyplot as pp
<span style="color: #800000; font-weight: bold;">import</span> scipy

<span style="color: #800000; font-weight: bold;">for</span> i <span style="color: #800000; font-weight: bold;">in</span> <span style="color: #e34adc;">range</span><span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">5</span><span style="color: #808030;">)</span><span style="color: #808030;">:</span>
    data <span style="color: #808030;">=</span> <span style="color: #808030;">[</span><span style="color: #808030;">]</span>
<span style="color: #800000; font-weight: bold;"> for</span> i <span style="color: #800000; font-weight: bold;">in</span> <span style="color: #e34adc;">range</span><span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">1024</span><span style="color: #808030;">)</span><span style="color: #808030;">:</span>
        data<span style="color: #808030;">.</span>append<span style="color: #808030;">(</span>x<span style="color: #808030;">.</span>getNoise<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span>

    pp<span style="color: #808030;">.</span>subplot<span style="color: #808030;">(</span><span style="color: #008c00;">2</span><span style="color: #808030;">,</span> <span style="color: #008c00;">1</span><span style="color: #808030;">,</span> <span style="color: #008c00;">1</span><span style="color: #808030;">)</span>
    pp<span style="color: #808030;">.</span>plot<span style="color: #808030;">(</span>data<span style="color: #808030;">)</span>
    pp<span style="color: #808030;">.</span>title<span style="color: #808030;">(</span><span style="color: #0000e6;">"Generated Noise"</span><span style="color: #808030;">)</span>

    pp<span style="color: #808030;">.</span>subplot<span style="color: #808030;">(</span><span style="color: #008c00;">2</span><span style="color: #808030;">,</span> <span style="color: #008c00;">1</span><span style="color: #808030;">,</span> <span style="color: #008c00;">2</span><span style="color: #808030;">)</span>
    pp<span style="color: #808030;">.</span>plot<span style="color: #808030;">(</span><span style="color: #e34adc;">abs</span><span style="color: #808030;">(</span>scipy<span style="color: #808030;">.</span>fft<span style="color: #808030;">(</span>data<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span>
    pp<span style="color: #808030;">.</span>title<span style="color: #808030;">(</span><span style="color: #0000e6;">"Generated Noise Spectrum"</span><span style="color: #808030;">)</span>

pp<span style="color: #808030;">.</span>show<span style="color: #808030;">(</span><span style="color: #808030;">)</span></pre>
<p>This will generate 5 sets of simulated noise.  The length of noise generated can be arbitrary, but to avoid confusion, the output data will be of the same length as the input (different lengths makes the FFT result different between source and simulation data).   A single instance of this simulated noise looks like:</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/06/generated-noise-and-spectrum.png"><img class="alignnone size-full wp-image-94" title="generated noise and spectrum" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/06/generated-noise-and-spectrum.png" width="815" height="615" /></a></p>
<p>And 5 samples of this generated noise looks like:</p>
<p><a href="http://stuartowen.com/home/wp-content/uploads/2012/06/multple-noise-generations.png"><img class="alignnone size-full wp-image-95" title="multple noise generations" alt="" src="http://stuartowen.com/home/wp-content/uploads/2012/06/multple-noise-generations.png" width="815" height="615" /></a></p>
<p>As we can see, we’ve succeeded in creating a noise of arbitrary frequency spectrum.  Now we can add this noise to our input signal (or even simulate our input signal!) with a single function call: shaper.getNoise().  When using this class, make sure that you sample the noise data at the same rate that the system you’re simulating does, or decimate it down to the correct rate!  Using a different sampling rate will stretch or squish the noise spectrum and make it inaccurate.</p>
<p>Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://stuartowen.com/home/simulating-noise-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Knowledge as Interconnected Nodes</title>
		<link>http://stuartowen.com/home/knowledge-as-interconnected-nodes/</link>
		<comments>http://stuartowen.com/home/knowledge-as-interconnected-nodes/#comments</comments>
		<pubDate>Wed, 23 May 2012 19:01:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://stuartowen.com/home/?p=48</guid>
		<description><![CDATA[In this article I will rant about a subject that I know nothing about. I think I&#8217;ve got some pretty <a class="read-more" href="http://stuartowen.com/home/knowledge-as-interconnected-nodes/">.....</a>]]></description>
				<content:encoded><![CDATA[<p><span style="line-height: 1.714285714; font-size: 1rem;">In this article I will rant about a subject that I know nothing about. I think I&#8217;ve got some pretty good ideas, though.</span></p>
<p>What does it mean to know something? To know what a Lenovo Laptop is? To know how to play the guitar? Knowing something is very base in our minds as human beings, so basic that we barely question what it means to know something. How does our mind piece together data and conclude &#8220;I know X&#8221;? At the most basic level, via experience. The brain perceives events via its sensors &#8211; eyes, ears, tongue, skin, etc. &#8211; and stores data regarding those events in memory. Let&#8217;s say you ate some cake. It was one of those generic platter cakes you find at Safeway, so it was a bit dry and the frosting was sickly-sweet. The frosting was mostly white, but red letters spelled out a crude but funny in-joke for your co-worker, whose birthday you were celebrating. That last bit wasn&#8217;t so much a descriptor of the cake, but its importance will become apparent later. Now, when you think of cakes, specifically cheap platter cakes, what are the important characteristics you remember? Sweetness (sometimes too much!), rectangular shape, spongey inside that&#8217;s not as sweet, etc. Thinking of abstracted things (like a non-specific platter cake) doesn&#8217;t link to a bunch of pictures of cakes you&#8217;ve saved in your mind, it links to ideas that you&#8217;ve linked to platter cakes in the past. You can imagine each of these abstract objects as a node, whose defining characteristics are manifest as connections of certain strength or proximity to other nodes that characterize it.</p>
<p>Think of the platter cake as the node of interest: we know platter cakes. Platter cakes are connected to various nodes: it has a strong connection to sweet, a strong connection to celebration, and somewhat weaker connection to gross, etc. You can imagine that the abstract idea of platter cakes is portrayable as a long list of connected nodes and their affinities. For example, through a very convoluted memory of my own, platter cakes are also tied to 9/11. That 9/11 node connects to many other nodes, some of which may be ideas, some of which may be memories, but looking into the node that is 9/11 my brain automatically explores the other paths to a certain extent, filling out the idea of 9/11 that takes it past a series of characters to a collection of memories, ideas, and feelings. This description elicits images of the brain being a computer in a vast net of nodes (ideas, memories, etc) chasing nets around and receiving external stimulus via its sensors that may push it towards certain nodes, or even create new nodes.</p>
<p>This idea of knowledge as a connection of nodes also explains the &#8220;Eureka!&#8221; momemts that people experience. Their brain is sitting there, racing around its node-track, when some external stimulus pushes the brain in a certain direction. Perhaps it is puzzling about why objects are intrinsicly drawn towards the earth, and suddenly an apple strikes them in the head. In reaction, the brain examines the situation, checking out nodes connected to apples, etc, creating connections between nodes where it sees them, when suddenly, the track is completed! The disconnect between one set of nodes (theory) and another set of nodes (reality) had been connected via a short route! The brain races to compare other nodes in the close proximity, and discovers other connections that can be made. Sometimes, this leads the person to experiment more, gathering more data, and creating more connections until the idea is more complete and explainable to others in a way that will allow them to create the necessary nodes and connections. This even sheds some light on why two people that both &#8220;know about the same things&#8221; have trouble having in-depth communications about them. This is particularly true in the more abstract engineering practices.</p>
<p>Engineering itself is very much centered on individual contributors coming together to figure out problems. The problems discussed on the broad spectrum are usually not very abstract and are easy to imagine. Those problems share connections with very common nodes and connections, like those involving system architecture and communication. But, when the problem becomes deeper, and the separate parties have come to understand the same idea in different ways (described the same phenomena with different nodes and interconnects), it becomes difficult for them to have efficient conversation, as they spend time and effort fitting the other person&#8217;s ideas into their own web of nodes. When companies impose standards or hold large training sessions, engineers can much more easily discuss the topics due to the commonality of their node placement and interconnection.</p>
]]></content:encoded>
			<wfw:commentRss>http://stuartowen.com/home/knowledge-as-interconnected-nodes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sangria de Mayo and the Importance of Branding</title>
		<link>http://stuartowen.com/home/sangria-de-mayo-and-the-importance-of-branding/</link>
		<comments>http://stuartowen.com/home/sangria-de-mayo-and-the-importance-of-branding/#comments</comments>
		<pubDate>Sun, 20 May 2012 09:09:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Business]]></category>

		<guid isPermaLink="false">http://stuartowen.com/home/?p=39</guid>
		<description><![CDATA[Sangria de Mayo is a wonderful holiday that my friends and I love to celebrate.  It involves participants concocting and bringing <a class="read-more" href="http://stuartowen.com/home/sangria-de-mayo-and-the-importance-of-branding/">.....</a>]]></description>
				<content:encoded><![CDATA[<p>Sangria de Mayo is a wonderful holiday that my friends and I love to celebrate.  It involves participants concocting and bringing their own custom batches of <a href="http://en.wikipedia.org/wiki/Sangria">sangria</a>, a classic summertime alcoholic beverage.  Invariably, the best sangrias are designed from the ground up with a core motivation in mind.  This post is not about designing sangria, though.  It&#8217;s not about design choices at all.  It&#8217;s about marketing.</p>
<p>Sangria de Mayo was a recent pleasure of mine, as I&#8217;ve only attended the event in this year and the one previous.  Lets talk about the first one.  In keeping with my recent graduation from Washington State University, I figured I would show up to this party and show people how it was done right.  Sangria?  More like an opportunity to get people to drink hard A and wine at the same time.  So, I concocted the most imperceptibly alcoholic sangria I could &#8211; a mixture of Merlot, greapfruit, limes, lemons, vodka, and everclear.  Honestly, the taste that masked the alcohol was bearable at best.  In my excitement, I decided the beast needed a name: the hammer.  I&#8217;m sure you can infer why.  The real surprise was its amazing success:  I arrived at a party with a healthy supply of competitors; there were many flavors of delicious (sometimes beautiful) sangrias, and yet, mine was the first to run out.  Puzzling, in a singular instance.</p>
<p>Fast forward to a year later (tonight).  Sangria de Mayo is happening again, and I&#8217;d like to make a good showing.  Last time, though, my sangria was a bit abrasive: it was very much &#8220;in your face&#8221;.  You had to want it.  Instead, I chose to go for a white zinfandel base with sugar, fizzy energy mix, dissolved sugar, mikes hard lemonade, and everclear.  Even more everclear than last time.  And honestly, it was pretty good.  In keeping with its predecessor, and the pacman naming theme, I named the batch &#8220;Mrs. The Hammer&#8221;.  That&#8217;s all distracting from the point, though.  I showed up to the gala about 2 hours after it started (I can&#8217;t even call it fashionably late at that point &#8211; maybe Diablo 3 late?) and my batch of sangria was spent within the hour.  I received laments from other sangria makers that theirs hadn&#8217;t gone so quickly, even though they had shown up before I did.  Why was my sangria so popular in the presence of other, tastier sangrias?</p>
<p><img class="alignnone" title="Mrs The Hammer" src="http://i.imgur.com/QQCyF.jpg" alt="" width="600" height="800" /></p>
<p>&nbsp;</p>
<p>The answer is marketing.  Others brought their sangria in a plastic drink carafe, others in emptied water containers, etc.  The most extensive labeling in theirs was sharpie on plastic in Spanish.  Mrs. The Hammer, though, was scrawled dangerously on a strip of white duct-tape in rough letters.  Customers (party-goers) saw the label and felt something: something dangerous, something mysterious, and something that would obviously make them have a fuck load of fun.  Without even considering the marketing I did in person, the package itself screams &#8220;yeah, this will get you crunk.  And you will like it.&#8221; Add to that the mystique of the genesis story, and the subtle description of its making leading gradually from the white zinfandel to the raspberries and eventually to the everclear.  The sangria is the embodiment of that girl/guy you don&#8217;t want to date, but god damn do you want to go have a night out with.  The branding is consistent, it speaks to the target audience at the party (people trying to have a good time), and it creates something for people to talk about to each other.  Even if they are disdainful, it still furthers the mystique of Mrs. The Hammer.  It&#8217;s the naughty one.  It&#8217;s the one that, secretly or not, everyone wants.  It&#8217;s branding.</p>
<p>And that&#8217;s the story of why my probably mediocre sangria always gets finished first.</p>
]]></content:encoded>
			<wfw:commentRss>http://stuartowen.com/home/sangria-de-mayo-and-the-importance-of-branding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coverflows on Android</title>
		<link>http://stuartowen.com/home/coverflows-on-android/</link>
		<comments>http://stuartowen.com/home/coverflows-on-android/#comments</comments>
		<pubDate>Wed, 09 May 2012 20:51:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Mobile Development]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://stuartowen.com/home/?p=29</guid>
		<description><![CDATA[You know what&#8217;s a sweet user interface element?  Coverflows.  They aren&#8217;t that great for what they were initially used for: <a class="read-more" href="http://stuartowen.com/home/coverflows-on-android/">.....</a>]]></description>
				<content:encoded><![CDATA[<p><span style="line-height: 1.714285714; font-size: 1rem;">You know what&#8217;s a sweet user interface element?  Coverflows.  They aren&#8217;t that great for what they were initially used for: selecting albums to listen to based on their album cover.  Turns out people really do know what albums are called, or just want to see the artist/track title.  But!  You know what they are great for?  Selecting objects (in the software sense) with the identifier as a picture instead of text.  This is primarily limited to selecting photos, and even then, some may say that a simple grid is more utilitarian for this task, and I would tend to agree, but this doesn&#8217;t address a big problem with selecting from a grid: it&#8217;s ugly!  Google tried to do what it could with the Gallery app, but the grid of picture stacks still looks plain.  It also separates different categories (stacks) in a way that isn&#8217;t ideal.  Anyway, for the applications I am pursuing, I want something that places more emphasis on the content of each picture, which has led me to the coverflow.</span></p>
<p>The first, and largest, problem with this is: there isn&#8217;t any sort of standard coverflow implementation that has been made for android yet!  I&#8217;ve seen examples in which people expand the Gallery view &#8211; which by default displays a horizontal list of pictures &#8211; such that it would rotate the pictures based on their position.  This has a variety of problems associated with it, though:</p>
<ol>
<li>Object spacing within the list is constant.  What you want is to have rotated images have increased density.  This way, you can see the edge of many pictures to give the user more information about what is further down the line in the list.</li>
<li>The gallery extension is very slow!  Seriously.  My Galaxy SII couldn&#8217;t handle a 5 picture list.  And yes, the bitmaps being displayed were of appropriate resolution.</li>
<li>The extension of the gallery, while convenient, isn&#8217;t constructed around the objective of creating a coverflow.  Things like minimum object spacing, maximum object rotation, focal length, etc. are all very awkward adjustments to make.</li>
</ol>
<p>So!  What does this mean?  That I have to create a coverflow package, of course!  Due to the overtly 3D nature of the coverflow view, OpenGL ES2.0 will be utilized to create a lighter weight coverflow view with proper rendering of elements.  The topology of the package will be:</p>
<ul>
<li>Coverflow (extends GLSurfaceView)<br />
This will be the top level class through which users will interface with the coverflow, setting separation, rotation shaping, picture size, etc.</p>
<ul>
<li>CoverflowRenderer (extends GLSurfaceView.Renderer)<br />
This object will handle rendering of the coverflow, and will receive configuration specs from the parent Coverflow class.  It does the heavy lifting and will contain all the ugly code we don&#8217;t want the use to have to mess with.</li>
<li>CoverflowSquare<br />
The coverflow square class will contain all pertinent data required for each square in the coverflow: path to the picture to be displayed, size, byte buffers for rendering in OpenGL, etc.  It will contain limited APIs for updating byte buffers.</li>
</ul>
</li>
</ul>
<p>So far, I&#8217;ve got a cursory version of each of these made.  The coverflow renders the list with unity separation between pictures, rotates pictures based on position, and has a single pole IIR filter implemented to mimic the critically damped spring settling effect for when a user flicks it.  Oh!  It also ensures that it settles on an integer position, thus ensuring that a square is dead on, or &#8220;selected&#8221;.  The view is very snappy and is working exactly as expected.  Here is a washed out laptop webcam recording of the coverflow in aciton:</p>
<p><iframe src="http://www.youtube.com/embed/H_zEHKWy5j8" height="315" width="560" frameborder="0"></iframe></p>
<p>Going forward, I plan to clean up the code to increase usability, and implement more features to make the coverflow as pretty as it deserves to be.  When it gets to a respectable point, I&#8217;ll post the code somewhere so that others can utilize this view as well.</p>
<p>Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://stuartowen.com/home/coverflows-on-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Algorithm for Determining Optimal Multiplication via Shifts, Adds, and Subtracts</title>
		<link>http://stuartowen.com/home/algorithm-for-determining-optimal-multiplication-via-shifts-adds-and-subtracts/</link>
		<comments>http://stuartowen.com/home/algorithm-for-determining-optimal-multiplication-via-shifts-adds-and-subtracts/#comments</comments>
		<pubDate>Sat, 21 Apr 2012 20:56:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electrical Engineering]]></category>
		<category><![CDATA[Embedded Design]]></category>
		<category><![CDATA[dsp]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[embedded systems]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[iir]]></category>
		<category><![CDATA[signal processing]]></category>

		<guid isPermaLink="false">http://stuartowen.com/home/?p=9</guid>
		<description><![CDATA[Single pole IIR filters are a quick and dirty way to filter data in time or resource limited processing systems.  <a class="read-more" href="http://stuartowen.com/home/algorithm-for-determining-optimal-multiplication-via-shifts-adds-and-subtracts/">.....</a>]]></description>
				<content:encoded><![CDATA[<p><span style="line-height: 1.714285714; font-size: 1rem;">Single pole IIR filters are a quick and dirty way to filter data in time or resource limited processing systems.  These are particularly useful in embedded systems that don&#8217;t have access to dedicated multipliers.  These single pole IIR filters can be computed in only a handful of cycles in modern cores that have single cycle multipliers, but more limited cores without multipliers must be configured in a more cunning fashion to keep calculation time low.</span></p>
<p>The filter coefficient A is a factor of 1, assuming a stable filter.  The process for calculating these filters is simple:</p>
<ol>
<li> w1 = xn &#8211; yn-1</li>
<li> w2 = A * w1</li>
<li> yn = yn-1 + w2</li>
</ol>
<p>The multiply in this process is the tough part.  The classical definition of multiplication is a series of additions.  With numbers greater than 2, this process becomes inefficient very quickly.  Luckily, shifts allow for quick multiplies or divides by powers of two.  This can be expoited to implement multiplies or divides by other values via additions or subtractions of shifted data.  This allows us to create filters with cut-off frequencies in much finer locations.</p>
<p>Now comes the extra credit.  I was recently inspired to implement one of these filters in an extremely limited processing core, in which timing was uniquely limited by the system&#8217;s ADC sampling rate.  This timing limitation motivates a limited multiplication process.  As a human, finding the optimal organization of shifts, adds, and subtracts would not be hard for a given value.  For example, if I required an A value of 7/16.  The simple solution would be the addition of three shifted values; a shift right by 2, a shift right by 3, and a shift right by 4 could be added together to attain 7/16.  After little investigation, we can see that this may be optimized into the subtraction of a shift right by 4 from a shift right by 1.  In this way, we can represent a multiplication by a series of positive or negative divisions by powers of two.  For example, we can represent 7/16 as [0.5, -0.0625].</p>
<p>This is all well and good, but now assume that we want to be able to calculate these optimal multiplies for arbitrary values of A &#8211; for arbitrary cut-off frequencies.  This is of particular interest if you are creating a tool for use by others, that do not necessarily want to know the nitty-gritty of how to create the filter itself.  After some thought, it can be seen that this series of scaling values can be calculated successively.</p>
<p>First, the necessary number of bits required for a given accuracy must be calculated.  Once this has been calculated, an integer representation of the scaling value, as a fixed point number, may be calculated.  After this, the scaling list discussed before can be calculated by merely successively selecting the added or subtracted dividing power of two that brings the current remainder closest to zero.  For example, if we were to programmatically perform this process for a coefficient of 7/16:</p>
<p>7/16 &#8211; 1/16 = 6/16</p>
<p>7/16 &#8211; 2/16 = 5/16</p>
<p>7/16 &#8211; 4/16 = 3/16</p>
<p>7/16 &#8211; 8/16 = -1/16</p>
<p>7/16 &#8211; 16/16 = -9/16</p>
<p>It is apparent from the above calculations that subtracting 8/16, equivalent to a right shift of 1, brings the result closest to zero.  This does not yet yield a sufficiently accurate result, so we will take the remainder from the last calculation and perform it again:</p>
<p>-1/16 + 1/16 = 0/16</p>
<p>-1/16 + 2/16 = 1/16</p>
<p>-1/16 + 4/16 = 3/16</p>
<p>-1/16 + 8/16 = 7/16</p>
<p>-1/16 + 16/16 = 15/16</p>
<p>With an addition of 1/16, a shift right of 4, we reach zero, giving us a result of zero.  We invert the values selected to undo the negation implicit in this process to get a list of scaling values [0.5, -0.0625], just as we determined before.  Lets pop the stack a few times to get back to the application layer.  When applying this method with an accuracy requirement of 0.1%, and attenuation values with granularity in the thousandths, I found that the largest number of values in these scaling lists was only 5, which is great news for the application of this multiplication scheme for single pole IIR filters.</p>
]]></content:encoded>
			<wfw:commentRss>http://stuartowen.com/home/algorithm-for-determining-optimal-multiplication-via-shifts-adds-and-subtracts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
