<?xml version="1.0" encoding="windows-1252"?>
<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>The Blogging Protagonist &#187; Radio</title>
	<atom:link href="http://www.SWHarden.com/blog/category/radio/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.SWHarden.com/blog</link>
	<description>A collection of thoughts in technological degradation</description>
	<lastBuildDate>Tue, 27 Jul 2010 21:45:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>High Altitude Balloon Transmitter</title>
		<link>http://www.SWHarden.com/blog/2010-07-14-high-altitude-balloon-transmitter/</link>
		<comments>http://www.SWHarden.com/blog/2010-07-14-high-altitude-balloon-transmitter/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 13:05:46 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Circuitry]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Radio]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=2283</guid>
		<description><![CDATA[SUMMARY: A small group of high school students taking an AP class for college credit launched a high-altitude weather balloon with a small payload.  In addition to a video transmitter and GPS transmitter, they decided to include a simple transmitter built from scratch.  This is the story of the project, with emphasis on [...]]]></description>
			<content:encoded><![CDATA[<p><table><tr><td style="text-indent: 25px; background-color: #E5E5E5; padding: 10px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 7px;border-top-style: solid; border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-top-color: #B5B5B5; border-right-color: #B5B5B5;border-bottom-color: #B5B5B5; border-left-color: #B5B5B5;border-right-width: 1px;background-image: url(http://www.swharden.com/graphics/layout_2006_08_12/quotes.jpg); background-position: left top; background-repeat: no-repeat;"><b>SUMMARY:</b> A small group of high school students taking an AP class for college credit launched a high-altitude weather balloon with a small payload.  In addition to a video transmitter and GPS transmitter, they decided to include a simple transmitter built from scratch.  This is the story of the project, with emphasis on the simple transmitter&#8217;s design, construction, implementation, and reception (which surprised me, being detected ~200 miles away and lasting the entire duration of the flight!) [<a href='http://www.SWHarden.com/blog/images/beeps.ogg'>sample.ogg</a>]</td></tr></table></p>
<h1>6/16/2010 &#8211; TRACKING</h1>
<p><b>I&#8217;m completely amazed</b> at how well the transmitter/receiver worked!  For only a few milliwatts, I was able to track that thing all the way from takeoff to landing in Gainesville, FL a few hundred miles away. Here is the data assembled in a special, annotated way!</p>
<p><a href="http://swharden.com/tmp/balloon/view2.html">CLICK HERE to view the signal tracked from Gainesville, FL<br />
<img src="http://www.SWHarden.com/blog/images/balloon_track-525x613.jpg" alt="balloon_track" title="balloon_track" width="525" height="613" class="alignleft size-medium wp-image-2345" /></a></p>
<p><b>ANALYSIS:</b> the text on the image describes most if it, but one of the most interesting features is the &#8220;multipathing&#8221; during the final moments of the descent, where the single carrier signal splits into two.  I believe this is due to two Doppler shifts: (1) as the distance between the falling transmitter and the receiver is decreasing, producing a slight in increase in frequency, and (2) a signal reflected off of a layer of the atmosphere above the craft (the ionosphere?) before it gets to the receiver, the distance of which is increasing as the craft falls, producing a decrease in frequency. I&#8217;ll bet I can mathematically work backwards and determine how high the craft was, how fast it was falling, and/or how high the layer of the reflecting material is &#8211; but that&#8217;s more work than this dental student is prepared to do before his morning coffee!</p>
<p><b>HERE IS SOME AUDIO</b> of some of the strongest signals I received. Pretty good for a few milliwatts a hundred miles away! [<a href='http://www.SWHarden.com/blog/images/beeps.ogg'>beeps.ogg</a>]</p>
<h1>6/16/2010 &#8211; THE FLIGHT</h1>
<p><b>The launch:</b><br />
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/qjLrytsDPjw&amp;hl=en_US&amp;fs=1?color1=0x006699&amp;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/qjLrytsDPjw&amp;hl=en_US&amp;fs=1?color1=0x006699&amp;color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p><b>This is the design team:</b><br /><a href="http://www.SWHarden.com/blog/images/DSC_7127.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7127-525x306.jpg" alt="DSC_7127" title="DSC_7127" width="525" height="306" class="alignleft size-medium wp-image-2334" /></a></p>
<p><b>Walking the balloon</b> to its launch destination at NASA with an awesome rocket (Saturn 1B &#8211; identified by Lee, KU4OS) in the background.<br /><a href="http://www.SWHarden.com/blog/images/DSC_7210.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7210-525x348.jpg" alt="DSC_7210" title="DSC_7210" width="525" height="348" class="alignleft size-medium wp-image-2335" /></a></p>
<p><b>The team</b> again, getting ready for launch.  I&#8217;ve been informed that the reason their hands are up is to prevent the balloon from tilting over too much.  I&#8217;d imagine that a brush with a grass blade could be bad news for the project!<br />
<a href="http://www.SWHarden.com/blog/images/DSC_7232.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7232-525x382.jpg" alt="DSC_7232" title="DSC_7232" width="525" height="382" class="alignleft size-medium wp-image-2336" /></a></p>
<p><b>Last minute checks</b> &#8211; you can see the transmitter and battery holders for it taped to the Styrofoam.<br />
<a href="http://www.SWHarden.com/blog/images/DSC_7248.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7248-525x348.jpg" alt="DSC_7248" title="DSC_7248" width="525" height="348" class="alignleft size-medium wp-image-2337" /></a></p>
<p><b>The transmitter in its final position.</b> Note the coil of yellow wire.  That serves as a rudimentary &#8220;ground&#8221; for the antenna&#8217;s signal to push off of.  I wasn&#8217;t very clear on my instructions on how to make it.  I meant that it should be a huge coil wrapped around the entire payload (as large as it can be), which would have probably produced a better signal, but since I was able to capture the signal during the whole flight it turned out to be a non-issue.<br />
<a href="http://www.SWHarden.com/blog/images/DSC_7250.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7250-525x348.jpg" alt="DSC_7250" title="DSC_7250" width="525" height="348" class="alignleft size-medium wp-image-2338" /></a></p>
<p><b>The antenna</b> can be seen dropping down as a yellow wire beneath the payload. (arrow)<br />
<a href="http://www.SWHarden.com/blog/images/DSC_7253.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7253-525x348.jpg" alt="DSC_7253" title="DSC_7253" width="525" height="348" class="alignleft size-medium wp-image-2339" /></a></p>
<p><b>Awesome photo.</b><br />
<a href="http://www.SWHarden.com/blog/images/DSC_7279.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7279-525x113.jpg" alt="DSC_7279" title="DSC_7279" width="525" height="113" class="alignleft size-medium wp-image-2340" /></a></p>
<p><b>Launch!</b> Look how fast that balloon is rising!<br />
<a href="http://www.SWHarden.com/blog/images/DSC_7294.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7294-525x264.jpg" alt="DSC_7294" title="DSC_7294" width="525" height="264" class="alignleft size-medium wp-image-2341" /></a></p>
<p><b>It&#8217;s out of our hands</b> now.  When I got the text message that it launched, I held my breath.  I was skeptical that the transmitter would even work!<br />
<a href="http://www.SWHa rden.com/blog/images/DSC_7297.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHa rden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7297-525x423.jpg" alt="DSC_7297" title="DSC_7297" width="525" height="423" class="alignleft size-medium wp-image-2342" /></a></p>
<p><b>One of the students</b> listening to my transmitter with QRSS VD software (score!)<br />
<a href="http://www.SWHarden.com/blog/images/DSC_7365.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7365-525x348.jpg" alt="DSC_7365" title="DSC_7365" width="525" height="348" class="alignleft size-medium wp-image-2333" /></a></p>
<p><b>Video capture</b> from an on-board camera was also attempted (900MHz), but from what I hear it didn&#8217;t function well for very long.<br />
<a href="http://www.SWHarden.com/blog/images/DSC_7334.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7334-525x348.jpg" alt="DSC_7334" title="DSC_7334" width="525" height="348" class="alignleft size-medium wp-image-2343" /></a></p>
<h1>6/15/2010 &#8211; IMPROVED BUILD</h1>
<p><b>Here you can see me</b> (center arrow) showing the students how to receive the Morse code signal sent from the small transmitter (left arrow) using a laptop running <a href="http://www.swharden.com/blog/qrss_vd/" >QRSS VD (my software)</a> analyzing audio from and an Icom706 mkII radio receiver attached to a dipole (right arrow).<a href="http://www.SWHarden.com/blog/images/DSC_7082.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSC_7082-525x348.jpg" alt="DSC_7082" title="DSC_7082" width="525" height="348" class="alignleft size-medium wp-image-2332" /></a></p>
<p><b>I amped-up the output of the oscillator</b> using an octal buffer chip (74HC240) with some decent results. I&#8217;m pleased!  It&#8217;s not perfect (it&#8217;s noisy as heck) but it should be functional for a 2 hour flight.<br />
<a href="http://www.SWHarden.com/blog/images/72hc240_qrp_amplifier.jpg" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/72hc240_qrp_amplifier-525x535.jpg" alt="72hc240_qrp_amplifier" title="72hc240_qrp_amplifier" width="525" height="535" class="alignleft size-medium wp-image-2344" /></a></p>
<p>Closeup of the transmitter showing the oscillator at 29.4912 MHz, the Atmel ATTiny44a AVR microcontroller (left chip), octal buffer 74HC240 (right chip), and some status lights which blink as the code is executed.<a href="http://www.SWHarden.com/blog/images/01_closeup.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/01_closeup-525x393.jpg" alt="01_closeup" title="01_closeup" width="525" height="393" class="alignleft size-medium wp-image-2293" /></a></p>
<p><b>This is my desk</b> where I work from home. Note the styrofoam box in the background &#8211; that&#8217;s where my low-power transmitter lives (the one that&#8217;s spotted around the world).  All I needed to build this device was a soldering iron. <a href="http://www.SWHarden.com/blog/images/02_workstation.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/02_workstation-525x393.jpg" alt="02_workstation" title="02_workstation" width="525" height="393" class="alignleft size-medium wp-image-2294" /></a></p>
<p><b>Although I had a radio,</b> it is not capable of receiving 29MHz so I was unable to test the transmitter from home.  I had to take it to the university to assess its transmitting capabilities.<a href="http://www.SWHarden.com/blog/images/03_room.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/03_room-525x393.jpg" alt="03_room" title="03_room" width="525" height="393" class="alignleft size-medium wp-image-2295" /></a></p>
<p><b>At UF I used an oscilloscope to measure the waveform of the transmitter.</b> <a href="http://www.SWHarden.com/blog/images/04_measure.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/04_measure-525x393.jpg" alt="04_measure" title="04_measure" width="525" height="393" class="alignleft size-medium wp-image-2296" /></a></p>
<p><b>I connected the leads to the output of the transmitter, shorted by a 39ohm resistor.</b>  By measuring the peak-to-peak voltage of the signal going into a resistor, we can measure its power.<a href="http://www.SWHarden.com/blog/images/04_measure2.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/04_measure2-525x393.jpg" alt="04_measure2" title="04_measure2" width="525" height="393" class="alignleft size-medium wp-image-2297" /></a></p>
<p><b>Here&#8217;s the test setup.</b> The transmitter is on the blue pad on the right, and the waveform can be seen on the oscilloscope on the upper left.<a href="http://www.SWHarden.com/blog/images/05_lab.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/05_lab-525x393.jpg" alt="05_lab" title="05_lab" width="525" height="393" class="alignleft size-medium wp-image-2298" /></a></p>
<p><b>Here&#8217;s a closer view.</b><br /><a href="http://www.SWHarden.com/blog/images/06_scope.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/06_scope-525x393.jpg" alt="06_scope" title="06_scope" width="525" height="393" class="alignleft size-medium wp-image-2299" /></a></p>
<p><b>With the amplifier off</b>, the output power is just that of the oscillator.  Although the wave should look like a sine wave, it&#8217;s noisy, and simply does not.  While this is unacceptable if our goal is a clean radio signal with maximum efficiency, this is good enough to be heard at our target frequency.  The PPV (peak-to-peak voltage) as seen on the screen is about 100mV.  Since I&#8217;m using a x10 probe, this value should be multiplied by 10 = 1V.  1V PPV into 39 ohms is about <b>3 milliwatts!</b> ((1/(2*2^.5))^2/39*1000=3.2). For the math, see <a href="http://www.swharden.com/blog/2010-05-28-measuring-qrp-radio-output-power-with-an-oscilliscope/" >this post</a><a href="http://www.SWHarden.com/blog/images/07_no_amp.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/07_no_amp-525x393.jpg" alt="07_no_amp" title="07_no_amp" width="525" height="393" class="alignleft size-medium wp-image-2300" /></a></p>
<p><b>With the amplifier,</b> the output is much more powerful.  At 600mV peak-to-peak with a 10x probe (actually 6V peak-to-peak, expected because that&#8217;s the voltage of the 4xAAA battery supply we&#8217;re using) into 39 ohms we get <b>115 millivolts!</b> (6/(2*2^.5))^2/39*1000=115.38. <a href="http://www.SWHarden.com/blog/images/08_amp1.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/08_amp1-525x393.jpg" alt="08_amp" title="08_amp" width="525" height="393" class="alignleft size-medium wp-image-2302" /></a></p>
<p><b>Notes about power:</b> First of all, the actual power output isn&#8217;t 115mW.  The reason is that the math equations I used work only for pure sine waves.  Since our transmitter has multiple waves in it, less than that power is going to produce our primary signal.  It&#8217;s possible that only 50mW are going to our 29MHz signal, so the power output assessment is somewhat qualitative.  Something significant however is the difference between the measured power with and without the amplifier.  The 6x increase in peak-to-peak voltage results in a 36x (6^2) increase in power, which is very beneficial.  I&#8217;m glad I added this amplifier!  A 36 times increase in power will certainly help.</p>
<p><b>The final schematic</b> is here:<br />
<a href="http://www.SWHarden.com/blog/images/balloon_transmitter_final.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/balloon_transmitter_final.png" alt="balloon_transmitter_final" title="balloon_transmitter_final" width="290" height="281" class="alignleft size-full wp-image-2304" /></a></p>
<h1>6/14/2010 &#8211; THE BUILD</h1>
<p><b>Last week I spoke with a student in the UF aerospace engineering department who told me he was working with a group of high school students to add a payload to a high-altitude balloon being launched at (and tracked by) NASA.</b>  We tossed around a few ideas about what to put on it, and we decided it was worth a try to add a transmitter.  I&#8217;ll slowly add to this post as the project unfolds, but with only 2 days to prepare (wow!) I picked a simplistic design which should be extremely easy to understand by everyone.  Here&#8217;s the schematic:</p>
<p><a href="http://www.SWHarden.com/blog/images/balloon_transmitter.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/balloon_transmitter.png" alt="balloon_transmitter" title="balloon_transmitter" width="484" height="340" class="alignleft size-full wp-image-2285" /></a></p>
<p><b>The code is as simple as it gets.</b>  It sends some Morse code (&#8221;go gators&#8221;), then a long tone (about 15 seconds) which I hope can be measured QRSS style.  I commented virtually every line so it should be easy to understand how the program works.</p>
<pre class="prettyprint c">
#include &lt;avr /io.h>
#include &lt;util /delay.h>

char call[]={2,2,1,0,2,2,2,0,0,2,2,1,0,1,2,0,2,0,2,2,2,0,1,2,1,0,1,1,1,0,0};
// 0 for space, 1 for dit, 2 for dah

void sleep(){
  _delay_ms(100); // sleep for a while
  PORTA^=(1&lt;&lt;PA1); // "flip" the state of the TICK light
}

void ON(){
 PORTB=255; // turn on transmitter
 PORTA|=(1&lt;&lt;PA3); // turn on the ON light
 PORTA&#038;=~(1&lt;&lt;PA2); // turn off the ON light
}

void OFF(){
 PORTB=0; // turn off transmitter
 PORTA|=(1&lt;&lt;PA2); // turn on the OFF light
 PORTA&#038;=~(1&lt;&lt;PA3); // turn off the OFF light
}

void ID(){
        for (char i=0;i&lt;sizeof(call);i++){
                if (call[i]==0){OFF();} // space
                if (call[i]==1){ON();} // dot
                if (call[i]==2){ON();sleep();sleep();} // dash
    sleep();OFF();sleep();sleep(); // between letters
        }
}

void tone(){
 ON(); // turn on the transmitter
 for (char i=0;i&lt;200;i++){ // do this a lot of times
  sleep();
 }
 OFF();sleep();sleep();sleep(); // a little pause
}

int main(void) // PROGRAM STARTS HERE
{
    DDRB = 255; // set all of port B to output
 DDRA = 255; // set all of port A to output
 PORTA = 1; // turn on POWER light

 while (1){ // loop forever
  ID(); // send morse code ID
  tone(); // send a long beep
 }
}
</pre>
<p><b>I&#8217;m now wondering if I should further amplify this signal&#8217;s output power.</b>  Perhaps a 74HC240 can handle 9V? &#8230; or maybe it would be better to use 4 AAA batteries in series to give me about 6V. [ponders]  <a href="http://www.SWHarden.com/blog/images/balloon_transmitter_amplified.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');">this</a> is the schematic I&#8217;m thinking of building.</p>
<h2>UPDATE</h2>
<p>This story was featured on <a href="http://hackaday.com/2010/07/27/200-mile-rf-transmitter-and-high-altitude-balloon/" onclick="javascript:urchinTracker ('/outbound/article/hackaday.com');">Hack-A-Day</a>! Way to go everyone!<br /><a href="http://www.SWHarden.com/blog/images/hackaday_swharden.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/hackaday_swharden.png" alt="hackaday_swharden" title="hackaday_swharden" width="488" height="759" class="alignleft size-full wp-image-2365" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2010-07-14-high-altitude-balloon-transmitter/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Coder&#8217;s Block</title>
		<link>http://www.SWHarden.com/blog/2010-07-12-coders-block/</link>
		<comments>http://www.SWHarden.com/blog/2010-07-12-coders-block/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 03:36:03 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Radio]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=2279</guid>
		<description><![CDATA[It&#8217;s inexplicable, yet undeniable.  I simply can&#8217;t code anything useful right now.  I&#8217;m currently memorized by the idea of writing a truly powerful set of tools for scientific frequency analysis (more than just turning audio into images), and I keep starting over re-coding things from scratch.   I develop too much, too [...]]]></description>
			<content:encoded><![CDATA[<p><b>It&#8217;s inexplicable, yet undeniable.</b>  I simply can&#8217;t code anything useful right now.  I&#8217;m currently memorized by the idea of writing a truly powerful set of tools for scientific frequency analysis (more than just turning audio into images), and I keep starting over re-coding things from scratch.   I develop too much, too quickly, and half way in I get overwhelmed and mentally blocked. I do it to myself. <b>I&#8217;ve taken about a week off and will continue to take a few more days off to reset my mind.</b>  I&#8217;m trying to improve my coding by reading books (e-books) about advanced Python programming.  Perhaps when it&#8217;s time to return, I&#8217;ll write gorgeous and functional code.  I always seem to have one or the other, but never both [sigh]<a href="http://www.SWHarden.com/blog/images/qrss_aj4vd_belgium.jpg" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/qrss_aj4vd_belgium-525x284.jpg" alt="qrss_aj4vd_belgium" title="qrss_aj4vd_belgium" width="525" height="284" class="alignleft size-medium wp-image-2280" /></a></p>
<p><b>The photo above is</b> the signal of my (AJ4VD) little homemade transmitter in Gainesville, Florida, USA (using a 20-ft piece of wire inside my apartment as an antenna) detected by ON5EX in Belgium. It makes me happy.  It reminds me that some of the projects I work on succeed, which gives me motivation to continue pursuing the ones which currently challenge me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2010-07-12-coders-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detrending Data in Python with Numpy</title>
		<link>http://www.SWHarden.com/blog/2010-06-24-detrending-data-in-python-with-numpy/</link>
		<comments>http://www.SWHarden.com/blog/2010-06-24-detrending-data-in-python-with-numpy/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 13:38:52 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Radio]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=2253</guid>
		<description><![CDATA[While continuing my quest into the world of linear data analysis and signal processing, I came to a point where I wanted to emphasize variations in FFT traces.  While I am keeping my original data for scientific reference, visually I want to represent it emphasizing variations rather than concentrating on trends.  I wrote [...]]]></description>
			<content:encoded><![CDATA[<p><b>While continuing my quest</b> into the world of linear data analysis and signal processing, I came to a point where I wanted to emphasize variations in FFT traces.  While I am keeping my original data for scientific reference, visually I want to represent it emphasizing variations rather than concentrating on trends.  I wrote a detrending function which I&#8217;m sure will be useful for many applications:<a href="http://www.SWHarden.com/blog/images/detrend_fft.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/detrend_fft-525x392.png" alt="detrend_fft" title="detrend_fft" width="525" height="392" class="alignleft size-medium wp-image-2254" /></a></p>
<pre class="prettyprint python">
def detrend(data,degree=10):
	detrended=[None]*degree
	for i in range(degree,len(data)-degree):
		chunk=data[i-degree:i+degree]
		chunk=sum(chunk)/len(chunk)
		detrended.append(data[i]-chunk)
	return detrended+[None]*degree
</pre>
<p><b>However,</b> this method is extremely slow.  I need to think of a way to accomplish this same thing much faster.  [ponders]</p>
<p><b>UPDATE:</b> It looks like I&#8217;ve once again re-invented the wheel.  All of this has been done already, and FAR more efficiently I might add.  Simply:</p>
<pre class="prettyprint python">
import scipy.signal
ffty=scipy.signal.detrend(ffty)
</pre>
<p><b>Now I&#8217;m looking into</b> <code>scipy.signal.triang()</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2010-06-24-detrending-data-in-python-with-numpy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Insights Into FFTs, Imaginary Numbers, and Accurate Spectrographs</title>
		<link>http://www.SWHarden.com/blog/2010-06-23-insights-into-ffts-imaginary-numbers-and-accurate-spectrographs/</link>
		<comments>http://www.SWHarden.com/blog/2010-06-23-insights-into-ffts-imaginary-numbers-and-accurate-spectrographs/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 03:21:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Radio]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=2237</guid>
		<description><![CDATA[I&#8217;m attempting to thoroughly re-write the data assessment portions of my QRSS VD software, and rather than rushing to code it (like I did last time) I&#8217;m working hard on every step trying to optimize the code.  I came across some notes I made about Fast Fourier Transformations from the first time I coded [...]]]></description>
			<content:encoded><![CDATA[<p><b>I&#8217;m attempting to thoroughly re-write the data assessment</b> portions of my QRSS VD software, and rather than rushing to code it (like I did last time) I&#8217;m working hard on every step trying to optimize the code.  I came across some notes I made about Fast Fourier Transformations from the first time I coded the software, and though I&#8217;d post some code I found helpful.  Of particular satisfaction is an email I received from Alberto, I2PHD, the creator of Argo (the &#8220;gold standard&#8221; QRSS spectrograph software for Windows).  In it he notes: <table><tr><td style="text-indent: 25px; background-color: #E5E5E5; padding: 10px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 7px;border-top-style: solid; border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-top-color: #B5B5B5; border-right-color: #B5B5B5;border-bottom-color: #B5B5B5; border-left-color: #B5B5B5;border-right-width: 1px;background-image: url(http://www.swharden.com/graphics/layout_2006_08_12/quotes.jpg); background-position: left top; background-repeat: no-repeat;">I think that [it is a mistake to] throw away the imaginary part of the FFT. What I do in Argo, in Spectran, in Winrad, in SDRadio and in all of my other programs is compute the magnitude of the [FFT] signal, then compute the logarithm of it, and only then I do a mapping of the colors on the screen with the result of this last computation.</td></tr></table></p>
<p><b>These concepts are simple</b> to visualize when graphed.  Here I&#8217;ve written a short Python script to listen to the microphone (which is being fed a 2kHz sine wave), perform the FFT, and graph the real FFT component, imaginary FFT component, and their sum.  The output is:<a href="http://www.SWHarden.com/blog/images/real_imaginary_fft_pcm.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/real_imaginary_fft_pcm-525x317.png" alt="real_imaginary_fft_pcm" title="real_imaginary_fft_pcm" width="525" height="317" class="alignleft size-medium wp-image-2241" /></a></p>
<p><b>Of particular interest</b> to me is the beautiful complementarity of the two curves.  It makes me wonder what types of data can be extracted by the individual curves (or perhaps their difference?) down the road.  I wonder if phase measurements would be useful in extracting weak carries from beneath the noise floor?</p>
<p><b>Here&#8217;s the code I used to generate the image above.</b> Note that my microphone device was set to listen to my stereo output, and I generated a 2kHz sine wave using the command <code>speaker-test -t sine -f 2000</code> on a PC running Linux.  I hope you find it useful!</p>
<pre class="prettyprint python">
import numpy
import pyaudio
import pylab
import numpy

### RECORD AUDIO FROM MICROPHONE ###
rate=44100
soundcard=1 #CUSTOMIZE THIS!!!
p=pyaudio.PyAudio()
strm=p.open(format=pyaudio.paInt16,channels=1,rate=rate,\
			input_device_index=soundcard,input=True)
strm.read(1024) #prime the sound card this way
pcm=numpy.fromstring(strm.read(1024), dtype=numpy.int16)

### DO THE FFT ANALYSIS ###
fft=numpy.fft.fft(pcm)
fftr=10*numpy.log10(abs(fft.real))[:len(pcm)/2]
ffti=10*numpy.log10(abs(fft.imag))[:len(pcm)/2]
fftb=10*numpy.log10(numpy.sqrt(fft.imag**2+fft.real**2))[:len(pcm)/2]
freq=numpy.fft.fftfreq(numpy.arange(len(pcm)).shape[-1])[:len(pcm)/2]
freq=freq*rate/1000 #make the frequency scale

### GRAPH THIS STUFF ###
pylab.subplot(411)
pylab.title("Original Data")
pylab.grid()
pylab.plot(numpy.arange(len(pcm))/float(rate)*1000,pcm,'r-',alpha=1)
pylab.xlabel("Time (milliseconds)")
pylab.ylabel("Amplitude")
pylab.subplot(412)
pylab.title("Real FFT")
pylab.xlabel("Frequency (kHz)")
pylab.ylabel("Power")
pylab.grid()
pylab.plot(freq,fftr,'b-',alpha=1)
pylab.subplot(413)
pylab.title("Imaginary FFT")
pylab.xlabel("Frequency (kHz)")
pylab.ylabel("Power")
pylab.grid()
pylab.plot(freq,ffti,'g-',alpha=1)
pylab.subplot(414)
pylab.title("Real+Imaginary FFT")
pylab.xlabel("Frequency (kHz)")
pylab.ylabel("Power")
pylab.grid()
pylab.plot(freq,fftb,'k-',alpha=1)
pylab.show()
</pre>
<p><b>After fighting for a while long with</b> a &#8220;shifty baseline&#8221; of the FFT, I came to another understanding.  Let me first address the problem.  Taking the FFT of different regions of the 2kHz wave I got traces with the peak in the identical location, but the &#8220;baselines&#8221; completely different.  <a href="http://www.SWHarden.com/blog/images/fft_base2.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/fft_base2-525x395.png" alt="fft_base2" title="fft_base2" width="525" height="395" class="alignleft size-medium wp-image-2248" /></a></p>
<p><b>Like many things, I re-invented the wheel.</b> Since I knew the PCM values weren&#8217;t changing, the only variable was the starting/stopping point of the linear sample.  &#8220;Hard edges&#8221;, I imagined, must be the problem.  I then wrote the following function to shape the PCM audio like a triangle, silencing the edges and sweeping the volume up toward the middle of the sample:</p>
<pre class="prettyprint python">
def shapeTriangle(data):
	triangle=numpy.array(range(len(data)/2)+range(len(data)/2)[::-1])+1
	return data*triangle
</pre>
<p><b>After shaping the data BEFORE I applied the FFT,</b> I made the subsequent traces MUCH more acceptable.  Observe:<a href="http://www.SWHarden.com/blog/images/fft_base3.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/fft_base3-525x395.png" alt="fft_base3" title="fft_base3" width="525" height="395" class="alignleft size-medium wp-image-2250" /></a></p>
<p><b>Now that I&#8217;ve done all this experimentation/thinking,</b> I remembered that this is nothing new!  Everyone talks about shaping the wave to minimize hard edges before taking the FFT.  BAH!  Another case of me re-inventing the wheel because I&#8217;m too lazy to read others&#8217; work.  However, in my defense, I learned a lot by trying all this stuff &#8212; far more than I would have learned simply by copying someone else&#8217;s code into my script.  Experimentation is the key to discovery!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2010-06-23-insights-into-ffts-imaginary-numbers-and-accurate-spectrographs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Insulated MEPT = Stable Signal</title>
		<link>http://www.SWHarden.com/blog/2010-06-12-insulated-mept-stable-signal/</link>
		<comments>http://www.SWHarden.com/blog/2010-06-12-insulated-mept-stable-signal/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 14:18:14 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Radio]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=2212</guid>
		<description><![CDATA[While it may not be perfect, it&#8217;s a whole lot better.  Below is a capture from this morning of my signal (the waves near the bottom). Compare that to how it was before and you should notice a dramatic improvement!  The MEPT is inside a metal box inside a 1-inch-thick Styrofoam box.  [...]]]></description>
			<content:encoded><![CDATA[<p><b>While it may not be perfect</b>, it&#8217;s a whole lot better.  Below is a capture from this morning of my signal (the waves near the bottom). Compare that to <a href="http://www.swharden.com/blog/images/assembled-squished.jpg" >how it was before</a> and you should notice a dramatic improvement!  The MEPT is inside a metal box inside a 1-inch-thick Styrofoam box.  Very cool!<br />
<a href="http://www.SWHarden.com/blog/images/stable.jpg" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/stable.jpg" alt="stable" title="stable" width="504" height="300" class="alignleft size-full wp-image-2213" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2010-06-12-insulated-mept-stable-signal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
