<?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>John Roach &#187; code</title>
	<atom:link href="http://johnroach.info/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnroach.info</link>
	<description>Coding for life</description>
	<lastBuildDate>Wed, 18 Jan 2012 19:30:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Getting raw data from a USB mouse in Linux using Python</title>
		<link>http://johnroach.info/2011/02/16/getting-raw-data-from-a-usb-mouse-in-linux-using-python/</link>
		<comments>http://johnroach.info/2011/02/16/getting-raw-data-from-a-usb-mouse-in-linux-using-python/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 07:15:32 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mice]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[multiple]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[raw data]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=534</guid>
		<description><![CDATA[If you are geek your mouth should be watering by now. I will like to thank Oscar Lindberg and his cool Linux friend for this code! I was trying to get multiple-mice movement data. This is the code that got &#8230; <a href="http://johnroach.info/2011/02/16/getting-raw-data-from-a-usb-mouse-in-linux-using-python/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are geek your mouth should be watering by now. I will like to thank Oscar Lindberg and his cool Linux friend for this code! I was trying to get multiple-mice movement data. This is the code that got me started. Once I beautify my multiple-mouse code I will be posting it here as well. Without further ado :</p>
<pre name="code" class="py">
mouse = file('/dev/input/mouse0')
while True:
    status, dx, dy = tuple(ord(c) for c in mouse.read(3))

    def to_signed(n):
        return n - ((0x80 &#038; n) << 1)

    dx = to_signed(dx)
    dy = to_signed(dy)
    print "%#02x %d %d" % (status, dx, dy)
</pre>
<p>I hope this just made your day!</p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2011/02/16/getting-raw-data-from-a-usb-mouse-in-linux-using-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Changing size of array in C programming language</title>
		<link>http://johnroach.info/2010/04/17/changing-size-of-array-in-c-programming-language/</link>
		<comments>http://johnroach.info/2010/04/17/changing-size-of-array-in-c-programming-language/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 09:59:44 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=266</guid>
		<description><![CDATA[It&#8217;s been a long time since I coded in C. I needed to change the size of an array within the program. At first I just simply tried; int ab=10; int array[ab]; And surprisingly it didn&#8217;t work. (I mean it &#8230; <a href="http://johnroach.info/2010/04/17/changing-size-of-array-in-c-programming-language/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long time since I coded in C. I needed to change the size of an array within the program. At first I just simply tried;</p>
<pre name="code" class="c">
int ab=10;
int array[ab];
</pre>
<p>And surprisingly it didn&#8217;t work. (I mean it works in C++ and C#)<br />
Anyway I was thinking of ways on how to do this thought of using malloc() however I really didn&#8217;t know how hence I did some Google&#8217;ing around. And found this neat piece of code.</p>
<pre name="code" class="c">
int *resize_array(int *a, size_t new_size)
{
  int *save;

  save = realloc(a, new_size);
  if (save == NULL) {
    fprintf(stderr, "Memory exhausted\n");
    exit(EXIT_FAILURE);
  }
  return save;
}

int *user_old_array; // the array
int new_array_size=10;
user_old_array = malloc(initial_array_size * sizeof *user_old_array); //resized array
</pre>
<p>Quite neat isn&#8217;t it. I thought I should probably write this somewhere so I won&#8217;t forget. Hence the post.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2010/04/17/changing-size-of-array-in-c-programming-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up a CVS server for the BlackBox project</title>
		<link>http://johnroach.info/2009/12/13/setting-up-a-cvs-server-for-the-blackbox-project/</link>
		<comments>http://johnroach.info/2009/12/13/setting-up-a-cvs-server-for-the-blackbox-project/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 09:05:28 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ip home automation project]]></category>
		<category><![CDATA[cvs]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[fedora 11]]></category>
		<category><![CDATA[fedora 12]]></category>
		<category><![CDATA[john roach]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=172</guid>
		<description><![CDATA[Following the previous posts in this category you will notice that I was using Sourceforge.net as the code hosting. We had to change that because we really didn&#8217;t want to share every bit of code. ( A big sorry to &#8230; <a href="http://johnroach.info/2009/12/13/setting-up-a-cvs-server-for-the-blackbox-project/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Following the previous posts in this category you will notice that I was using Sourceforge.net as the code hosting. We had to change that because we really didn&#8217;t want to share every bit of code. ( A big sorry to open source developers. I am truly a sell out. ) So had to set up CVS server. Never done that before. Should probably add it to my CV. Anyways to business.</p>
<p><strong>How to set up a CVS server using SSH :</strong></p>
<p><span id="more-172"></span><strong>Step 1 : </strong>Install CVS to Fedora. My Fedora distro came with CVS since I chose developer properties during installation. However you may not have it to install simply say;</p>
<p><code>sudo yum install cvs</code></p>
<p><strong>Step 2 : </strong>Create a cvs user and group! Just follow the code below;<br />
<code>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 129px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">useradd cvs</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 129px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">groupadd cvs</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 129px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mkdir /home/cvs</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 129px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">cvs -d /home/cvs init</div>
<p>useradd cvs</p>
<p>groupadd cvs</p>
<p>mkdir /home/cvs<br />
</code><br />
<strong>Step 3 : </strong>Set permissions and add /home/cvs directory to cvs by using the following;</p>
<p><code>cvs -d /home/cvs init</p>
<p>chown -R cvs:cvs /home/cvs</p>
<p>chmod -R 770 /home/cvs</p>
<p>chmod 700   /home/cvs/CVSROOT</code></p>
<p><strong>Step 4 : </strong>Now you have to add your project to the CVS server. I assume you have a ~/project<strong> </strong>directory on the server. Just follow the following commands;</p>
<p><code>cd ~/project</p>
<p>cvs -d /home/cvs import -m "Initial Import" project myname release</p>
<p>cvs -d /home/cvs checkout project</code></p>
<p><strong>Step 5 :</strong> Add an account to the CVS server (preferably with the same username and password of the user acount you have created for the CVS server that will connect through SSH.) Use the following by replacing &lt;username&gt; and &lt;password&gt;</p>
<p><code>echo "&lt;username&gt;:&lt;password&gt;" &gt;&gt; /home/cvs/CVSROOT/passwd</code></p>
<p><strong>Step 6 :</strong> Make sure you have created a user to connect through SSH give him CVS group permission.</p>
<p>And that is that. It should work. Though you may need to do some changes in <strong>Step 3.</strong> To connect you can simply use the following code or just use Eclipse&#8217;s IDE ( that is what we are using. )</p>
<p><code>export CVS_RSH=ssh</p>
<p>cvs -d :ext:username@repository.host.name:/home/cvs login</p>
<p>cvs -d :ext:username@repository.host.name:/home/cvs co moduleName</code></p>
<p>I hope it will be helpful. Peace! </p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2009/12/13/setting-up-a-cvs-server-for-the-blackbox-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Ångström Linux on BeagleBoard</title>
		<link>http://johnroach.info/2009/11/27/installing-angstrom-linux-on-beagleboard/</link>
		<comments>http://johnroach.info/2009/11/27/installing-angstrom-linux-on-beagleboard/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 07:57:21 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[ip home automation project]]></category>
		<category><![CDATA[angstrom]]></category>
		<category><![CDATA[beagleboard]]></category>
		<category><![CDATA[embedded device]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[paramiko]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sd card]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=164</guid>
		<description><![CDATA[We have been able to install Ångström Linux to our beagle board. Ran into couple problems. The first one was we trusted BeagleBoard Beginners wiki just too much!! You see we learned that we should NOT set any environment variables while using &#8230; <a href="http://johnroach.info/2009/11/27/installing-angstrom-linux-on-beagleboard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We have been able to install Ångström Linux to our beagle board. Ran into couple problems. The first one was we trusted <a title="BeagleBoardBeginners Wiki" href="http://elinux.org/BeagleBoardBeginners" target="_blank">BeagleBoard Beginners</a> wiki just too much!!</p>
<p>You see we learned that we should NOT set any environment variables while using demo u-boot image which was downloaded from <a title="Angstrom demo images" href="http://www.angstrom-distribution.org/demo/beagleboard/" target="_blank">here</a>. In fact what we did is we created our own Ångström image (from Ångström site) and simply installed that to our Linux partition of our SDHC card. And it worked beautifully. Though I must say first boot is a drag, very very slow.</p>
<p><span id="more-164"></span></p>
<p>Ran to some problems again. It seems BeagleBoard only works with DVI-D LCD&#8217;s and we had a HDMI to VGA instead of a HDMI to DVI-D cable.We ended up connecting to it from SSH and installing our programs like that. We really don&#8217;t need an LCD any time soon. And to connect to it from SSH we had to learn it&#8217;s IP from terminal. So no problems there. And we were very happy with the outcome.</p>
<div class="flashalbum">
<div class="flagallery_swfobject" id="sid_413276769_div"><style type="text/css">
.flashalbum { clear: both; }
.flag_alternate { display: none; }
.flag_alternate .flagcatlinks { padding: 7px 3px; margin:0 0 3px; background-color: #292929; }
.flag_alternate .flagcatlinks a.flagcat { padding: 4px 10px; margin: 0; border: none; border-left: 1px dotted #ffffff; font: 14px Tahoma; text-decoration: none; background: none; color: #ffffff; background-color: #292929; }
.flag_alternate .flagcatlinks a.flagcat:hover { text-decoration: none; background: none; border: none; border-left: 1px dotted #ffffff; }
.flag_alternate .flagcatlinks a.active, .flag_alternate .flagcatlinks a.flagcat:hover { color: #ffffff; background-color: #737373; outline: none; }
.flag_alternate .flagcatlinks a.flagcat:first-child { border: none; }
.flag_alternate .flagcategory { display: none; font-size: 0; line-height: 0; }
.flag_alternate { background-color: transparent; margin: 7px 0; }
.flag_alternate .flagcategory { width: 100%; height: auto; position: relative; text-align: center; padding-bottom: 4px; }
.flag_alternate .flagcategory a.flag_pic_alt { display: inline-block; margin: 1px 0 0 1px; padding: 0; height: 100px; width: 115px; line-height: 96px; position:relative; z-index: 2; text-align: center; z-index:99; cursor:pointer; background-color: #ffffff; border: 2px solid #ffffff; text-decoration: none; background-image: url(http://johnroach.info/wp-content/plugins/flash-album-gallery/admin/images/loadingAnimation.gif); background-repeat: no-repeat; background-position: 50% 50%; font-size: 8px; color: #ffffff; }
.flag_alternate .flagcategory a.flag_pic_alt > .flag_pic_desc { display: none; padding: 4px; line-height: 140%; font-size: 12px; }
.flag_alternate .flagcategory a.flag_pic_alt > .flag_pic_desc * { display: none; line-height: 140%; font-size: 12px !important; }
.flag_alternate .flagcategory a.flag_pic_alt:hover { background-color: #ffffff; border: 2px solid #4a4a4a; color: #4a4a4a; text-decoration: none; z-index: 3; }
.flag_alternate .flagcategory a.flag_pic_alt.current, .flag_alternate .flagcategory a.flag_pic_alt.last { border-color: #4a4a4a; }
.flag_alternate .flagcategory a.flag_pic_alt > img { vertical-align: middle; display:inline-block; position: static; margin: 0 auto; padding: 0; border: none; height: 100px !important; width: 115px !important; max-width: 115px; min-width: 115px; }

#fancybox-title-over .title { color: #ff9900; }
#fancybox-title-over .descr { color: #cfcfcf; }
.flag_alternate .flagcatlinks { background-color: #292929; }
.flag_alternate .flagcatlinks a.flagcat { border-color: #ffffff; color: #ffffff; background-color: #292929; }
.flag_alternate .flagcatlinks a.flagcat:hover { border-color: #ffffff; }
.flag_alternate .flagcatlinks a.active, .flag_alternate .flagcatlinks a.flagcat:hover { color: #ffffff; background-color: #737373; }
	.flag_alternate .flagcategory a.flag_pic_alt { background-color: #ffffff; border: 2px solid #ffffff; color: #ffffff; }
.flag_alternate .flagcategory a.flag_pic_alt:hover { background-color: #ffffff; border: 2px solid #4a4a4a; color: #4a4a4a; }
.flag_alternate .flagcategory a.flag_pic_alt.current, .flag_alternate .flagcategory a.flag_pic_alt.last { border-color: #4a4a4a; }
</style>
<script type="text/javascript">var ExtendVar='http://johnroach.info/wp-content/plugins/flash-album-gallery/';</script>
<div id="sid_413276769_jq" class="flag_alternate">
		<div class="flagcatlinks"></div>
			<div class="flagCatMeta">
			<h4>angstrombeagleboard</h4>
			<p></p>
		</div>
		<div class="flagcategory" id="gid_4_sid_413276769">
			<a class="i0 flag_pic_alt" href="http://johnroach.info/wp-content/flagallery/angstrombeagleboard/angstrom.png" id="flag_pic_5" rel="gid_4_sid_413276769" title="">[img src=http://johnroach.info/wp-content/flagallery/angstrombeagleboard/thumbs/thumbs_angstrom.png]<span class="flag_pic_desc" id="flag_desc_5"><strong></strong><br /><span></span></span></a><a class="i1 flag_pic_alt" href="http://johnroach.info/wp-content/flagallery/angstrombeagleboard/image000.jpg" id="flag_pic_6" rel="gid_4_sid_413276769" title="">[img src=http://johnroach.info/wp-content/flagallery/angstrombeagleboard/thumbs/thumbs_image000.jpg]<span class="flag_pic_desc" id="flag_desc_6"><strong></strong><br /><span></span></span></a><a class="i2 flag_pic_alt" href="http://johnroach.info/wp-content/flagallery/angstrombeagleboard/image001.jpg" id="flag_pic_8" rel="gid_4_sid_413276769" title="">[img src=http://johnroach.info/wp-content/flagallery/angstrombeagleboard/thumbs/thumbs_image001.jpg]<span class="flag_pic_desc" id="flag_desc_8"><strong></strong><br /><span></span></span></a>		</div>
	</div>

</div></div>
<script type="text/javascript" defer="defer">
flag_alt['sid_413276769'] = jQuery("div#sid_413276769_jq").clone().wrap(document.createElement('div')).parent().html();
var sid_413276769_div = {
	params : {
		wmode : "opaque",
		allowfullscreen : "true",
		allowScriptAccess : "always",
		saling : "lt",
		scale : "noScale",
		menu : "false",
		bgcolor : "##262626"},
	flashvars : {
		path : "http://johnroach.info/wp-content/plugins/flagallery-skins/default/",
		gID : "4",
		galName : "Gallery",
		skinID : "sid_413276769",
		postID : "164",
		postTitle : "Installing+%C3%85ngstr%C3%B6m+Linux+on+BeagleBoard+"},
	attr : {
		styleclass : "flashalbum",
		id : "sid_413276769"},
	start : function() {
		swfobject.embedSWF("http://johnroach.info/wp-content/plugins/flagallery-skins/default/gallery.swf", "sid_413276769_div", "100%", "500", "10.1.52", "http://johnroach.info/wp-content/plugins/flash-album-gallery/skins/expressInstall.swf", this.flashvars, this.params , this.attr );
swfobject.createCSS("#sid_413276769","outline:none");
	}
}
sid_413276769_div.start();
</script>
<p>Installing python libraries; as installing python libraries go this one was a little tricky. You see it seems that Ångström doesn&#8217;t update its python libs that frequently. So calling the package by</p>
<p><code>opkg intall python-pycrypto</code></p>
<p>Didn&#8217;t quite work since installed itself to python2.5 directory. Had to install pycrypto manually. I hated every moment of it. I  than uploaded my own program and I was very happy with the outcome. The program worked perfectly.</p>
<p>Stay tuned for more updates on The Black Box project! Remember you can find it at<a href="http://sourceforge.net/projects/theblackbox/">http://sourceforge.net/projects/theblackbox/</a> .</p>
<p>Live coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2009/11/27/installing-angstrom-linux-on-beagleboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Robots go Open Source!! Thanks to Willow Garage Watch Video</title>
		<link>http://johnroach.info/2009/11/16/robots-go-open-source-thanks-to-willow-garage-watch-video/</link>
		<comments>http://johnroach.info/2009/11/16/robots-go-open-source-thanks-to-willow-garage-watch-video/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 17:13:38 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[tech news]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[robot]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=134</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><center><object width="444" height="390" id="soundslider" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="http://www.ieee.org/netstorage/spectrum/flash/RobotShowFlash-1/11W_AudioSS_Robot_WillowGarage/publish_to_web/soundslider.swf?size=1&#038;format=xml&#038;embed_width=444&#038;embed_height=390&#038;autoload=false" name="movie" /><param value="always" name="allowScriptAccess" /><param value="high" name="quality" /><param value="true" name="allowFullScreen" /><param value="false" name="menu" /><param value="#FFFFFF" name="bgcolor" /><embed width="444" height="390" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="sameDomain" menu="false" bgcolor="#FFFFFF" quality="high" src="http://www.ieee.org/netstorage/spectrum/flash/RobotShowFlash-1/11W_AudioSS_Robot_WillowGarage/publish_to_web/soundslider.swf?size=1&#038;format=xml&#038;embed_width=444&#038;embed_height=390&#038;autoload=false"></embed></object></center></p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2009/11/16/robots-go-open-source-thanks-to-willow-garage-watch-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AM and DSB-SC Modulation and Demodulation of a Periodic Square Wave (Matlab)</title>
		<link>http://johnroach.info/2009/11/15/am-and-dsb-sc-modulation-and-demodulation-of-a-periodic-square-wave-matlab/</link>
		<comments>http://johnroach.info/2009/11/15/am-and-dsb-sc-modulation-and-demodulation-of-a-periodic-square-wave-matlab/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 15:49:00 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[demodulation]]></category>
		<category><![CDATA[john roach]]></category>
		<category><![CDATA[matlab]]></category>
		<category><![CDATA[modulation]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=127</guid>
		<description><![CDATA[We once had a homework way back when decided to share it. I edited this script which is in Matlab. I hope you like it. It simply is an analysis of AM and DSB-SC Modulation and Demodulation of a Periodic &#8230; <a href="http://johnroach.info/2009/11/15/am-and-dsb-sc-modulation-and-demodulation-of-a-periodic-square-wave-matlab/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We once had a homework way back when decided to share it. I edited this script which is in Matlab. I hope you like it. It simply is an analysis of AM and DSB-SC Modulation and Demodulation of a Periodic Square Wave.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%Amplitude Modulation with a periodic sqare wave and its spectrum analysis</span>
<span style="color: #228B22;">%Show the time domain and frquency domain representation of DSB-AM and</span>
<span style="color: #228B22;">%DSB-SC modulations</span>
<span style="color: #228B22;">%By : John Roach – 6 March 2009</span>
<span style="color: #228B22;">%visit my site at http://johnroach.info</span>
N = <span style="color: #33f;">1024</span>; <span style="color: #228B22;">%N point FFT N&gt;fc to avoid freq domain aliasing</span>
fs = <span style="color: #33f;">4096</span>; <span style="color: #228B22;">% Sample frequency</span>
t = <span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>:N-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>/fs;
fc = <span style="color: #33f;">600</span>; <span style="color: #228B22;">%Carrier Frequency</span>
fm2 = <span style="color: #33f;">80</span>; <span style="color: #228B22;">%Message Frequency</span>
Ec = <span style="color: #33f;">20</span>; <span style="color: #228B22;">%Carrier Amplitude</span>
Em2 = <span style="color: #33f;">5</span>; <span style="color: #228B22;">%Messagae Amplitude</span>
<span style="color: #228B22;">% Try changing the message and carrier amplitudes to see the effect in</span>
<span style="color: #228B22;">% DSB-AM modulation</span>
<span style="color: #228B22;">%———Double SideBand Full Carrier Modulation (DSB-FC(AM))</span>
A = Ec + Em2*square<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span>*fm2*t<span style="color: #080;">&#41;</span>;<span style="color: #228B22;">%Envelope/eliminate the carrier amplitude</span>
m = A.*<span style="color: #0000FF;">sin</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span>*fc*t<span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%to convert DSB-AM to DSB-SC</span>
Mf = <span style="color: #33f;">2</span>/N*<span style="color: #0000FF;">abs</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">fft</span><span style="color: #080;">&#40;</span>m,N<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
f = fs * <span style="color: #080;">&#40;</span><span style="color: #33f;">0</span> : N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span> / N;<span style="color: #228B22;">%Since the fft result is symmetrical, only the</span>
<span style="color: #228B22;">%positive half is sufficient for spectral representation</span>
<span style="color: #0000FF;">close</span> <span style="color: #0000FF;">all</span>;
<span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span>’Name’,'Time/Fequency domain representations of DSB-AM signals’<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%Time domain plot</span>
<span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>t<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,m<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,t<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,A<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,’r',t<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,-A<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,’r'<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">title</span><span style="color: #080;">&#40;</span>’Time Domain Representation’<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span>’Time’<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span>’Modulated signal’<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%Frequency Domain Plot</span>
<span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>f<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:<span style="color: #33f;">256</span><span style="color: #080;">&#41;</span>,Mf<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:<span style="color: #33f;">256</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">title</span><span style="color: #080;">&#40;</span>’Frequency Domain Representation’<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span>’Frequency <span style="color: #080;">&#40;</span>Hz<span style="color: #080;">&#41;</span>’<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span>’Spectral Magnitude’<span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">%———-Double SideBand Suppressed Carrier DSB-SC———-</span>
A = Em2*square<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span>*fm2*t<span style="color: #080;">&#41;</span> ; <span style="color: #228B22;">%Envelope/eliminate the carrier amplitude</span>
m = A.*<span style="color: #0000FF;">sin</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span>*fc*t<span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%to convert DSB-AM to DSB-SC</span>
Mf = <span style="color: #33f;">2</span>/N*<span style="color: #0000FF;">abs</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">fft</span><span style="color: #080;">&#40;</span>m,N<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span>’Name’,'Time/Fequency domain representations of DSB-SC signals’<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%Time domain plot</span>
<span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>t<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,m<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,t<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,A<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,’r',t<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,-A<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:N/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,’r'<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">title</span><span style="color: #080;">&#40;</span>’Time Domain Representation’<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span>’Time’<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span>’Modulated signal’<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%Frequency Domain Plot</span>
<span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>f<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:<span style="color: #33f;">256</span><span style="color: #080;">&#41;</span>,Mf<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:<span style="color: #33f;">256</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">title</span><span style="color: #080;">&#40;</span>’Frequency Domain Representation’<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span>’Frequency <span style="color: #080;">&#40;</span>Hz<span style="color: #080;">&#41;</span>’<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span>’Spectral Magnitude’<span style="color: #080;">&#41;</span>;
text<span style="color: #080;">&#40;</span><span style="color: #33f;">15</span>,<span style="color: #33f;">60</span>,’Carrier’<span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">%——————————————————————–</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2009/11/15/am-and-dsb-sc-modulation-and-demodulation-of-a-periodic-square-wave-matlab/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

