<?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>dspLog &#187; DSP</title>
	<atom:link href="http://www.dsplog.com/category/dsp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dsplog.com</link>
	<description>Signal Processing for Communication</description>
	<lastBuildDate>Tue, 20 Jul 2010 16:36:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Approximate Vector Magnitude Computation</title>
		<link>http://www.dsplog.com/2009/02/08/approximate-vector-magnitude-computation/</link>
		<comments>http://www.dsplog.com/2009/02/08/approximate-vector-magnitude-computation/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 01:43:35 +0000</pubDate>
		<dc:creator>Krishna Sankar</dc:creator>
				<category><![CDATA[DSP]]></category>
		<category><![CDATA[magnitude]]></category>

		<guid isPermaLink="false">http://www.dsplog.com/?p=468</guid>
		<description><![CDATA[In this post, let us discuss a simple implementation friendly scheme for computing the absolute value of a complex number . The technique called (alpha Max + beta Min) algorithm is discussed in Chapter 13.2 of Understanding Digital Signal Processing, Richard Lyons and is also available online at Digital Signal Processing Tricks &#8211; High-speed vector [...]


Related posts:<ol><li><a href='http://www.dsplog.com/2007/12/16/using-cordic-for-phase-and-magnitude-computation/' rel='bookmark' title='Permanent Link: Using CORDIC for phase and magnitude computation'>Using CORDIC for phase and magnitude computation</a></li><li><a href='http://www.dsplog.com/2008/08/10/ber-bpsk-rayleigh-channel/' rel='bookmark' title='Permanent Link: BER for BPSK in Rayleigh channel'>BER for BPSK in Rayleigh channel</a></li><li><a href='http://www.dsplog.com/2008/02/24/peak-to-average-power-ratio-for-ofdm/' rel='bookmark' title='Permanent Link: Peak to Average Power Ratio for OFDM'>Peak to Average Power Ratio for OFDM</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>In this post, let us discuss a simple implementation friendly scheme for computing the absolute value of a complex number <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?Z = X+jY" border="0" alt="" align="absmiddle" />. The technique called <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha Max + \beta Min" border="0" alt="" align="absmiddle" />(alpha Max + beta Min) algorithm is discussed in Chapter 13.2 of <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FUnderstanding-Digital-Signal-Processing-Richard%2Fdp%2F0201634678&amp;tag=dl04-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325">Understanding Digital Signal Processing, Richard Lyons</a><img style="border: medium none  ! important; margin: 0px ! important;" src="https://www.assoc-amazon.com/e/ir?t=dl04-20&amp;l=ur2&amp;o=1" border="0" alt="" width="1" height="1" /> and is also available online at <a href="http://www.embedded.com/design/embeddeddsp/202600924?_requestid=7638">Digital Signal Processing Tricks &#8211; High-speed vector magnitude approximation </a></p>
<p>The magnitude of a complex number <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?Z = X+jY" border="0" alt="" align="absmiddle" />is</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?|Z| = \sqrt{X^2 + Y^2}" border="0" alt="" align="absmiddle" />.</p>
<p>The simplified computation of the absolute value is</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?|Z| \approx \alpha Max + \beta Min" border="0" alt="" align="absmiddle" /> where</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?Max = \max \left( |X|, |Y| \right)" border="0" alt="" align="absmiddle" /></p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?Min = \min \left( |X|, |Y| \right)" border="0" alt="" align="absmiddle" />.</p>
<p><span id="more-468"></span>The values of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha" border="0" alt="" align="absmiddle" /> and <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\beta" border="0" alt="" align="absmiddle" /> can be tried out to understand the performance. For analysis we can use a complex number with magnitude 1 and phase from 0 to 180 degrees.</p>
<p><strong>Option#1 </strong></p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha" border="0" alt="" align="absmiddle" /> = 1, <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\beta" border="0" alt="" align="absmiddle" /> = 1/2,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?|Z| \approx  Max + \frac{Min}{2}" border="0" alt="" align="absmiddle" /></p>
<p><strong>Option#2 </strong></p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha" border="0" alt="" align="absmiddle" /> = 1, <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\beta" border="0" alt="" align="absmiddle" /> = 1/4,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?|Z| \approx  Max + \frac{Min}{4}" border="0" alt="" align="absmiddle" /></p>
<p><strong>Option#3 </strong></p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha" border="0" alt="" align="absmiddle" /> = 1, <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\beta" border="0" alt="" align="absmiddle" /> = 3/8</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?|Z| \approx  Max + \frac{3Min}{8}" border="0" alt="" align="absmiddle" /></p>
<p><strong>Option#4 </strong></p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha" border="0" alt="" align="absmiddle" /> = 7/8, <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\beta" border="0" alt="" align="absmiddle" /> = 7/16</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?|Z| \approx  \frac{7Max}{8} + \frac{7Min}{16}" border="0" alt="" align="absmiddle" /></p>
<p><strong>Option#5 </strong></p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha" border="0" alt="" align="absmiddle" /> = 15/16, <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\beta" border="0" alt="" align="absmiddle" /> = 15/32</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?|Z| \approx  \frac{15Max}{16} + \frac{15Min}{32}" border="0" alt="" align="absmiddle" /></p>
<h2>Simulation Model</h2>
<p>The script performs the following.</p>
<p>(a) Generate a complex number with phase varying from 0 to 180 degrees.</p>
<p>(b) Find the absolute value using the above 5 options</p>
<p>(c) For each option, find the maximum error, average error and root mean square error</p>
<p>Click here to download <a href="http://www.dsplog.com/db-install/wp-content/uploads/2009/02/script_approximate_vector_magnitude_computation.m">Matlab/Octave script for computing the approximate value of magnitude of a complex number</a></p>
<p><img class="alignnone" title="Plot of approximate value of magnitude of a complex number" src="http://www.dsplog.com/db-install/wp-content/uploads/2009/02/plot_approximate_vector_magnitude_computation.png" alt="" width="632" height="399" /></p>
<p><strong>Figure: Plot of approximate value of magnitude of a complex number</strong></p>
<p><strong></strong></p>
<table style="text-align: center;" border="0" cellspacing="0" cellpadding="0" width="497">
<col width="64"></col>
<col width="73"></col>
<col width="76"></col>
<col width="90"></col>
<col width="93"></col>
<col width="101"></col>
<tbody>
<tr height="63">
<td width="64" height="63">Option</td>
<td width="73">alpha</td>
<td width="76">beta</td>
<td width="90">Maximum Error %</td>
<td width="93">Average Error %</td>
<td width="101">RMS<br />
error %</td>
</tr>
<tr height="20">
<td height="20">1</td>
<td width="73">1</td>
<td width="76">1/2</td>
<td width="90">11.80340</td>
<td width="93">8.67667</td>
<td width="101">9.21159</td>
</tr>
<tr height="20">
<td height="20">2</td>
<td width="73">1</td>
<td width="76">1/4</td>
<td width="90">-11.60134</td>
<td width="93">-0.64520</td>
<td width="101">4.15450</td>
</tr>
<tr height="20">
<td height="20">3</td>
<td width="73">1</td>
<td width="76">3/8</td>
<td width="90">6.80005</td>
<td width="93">4.01573</td>
<td width="101">4.76143</td>
</tr>
<tr height="20">
<td height="20">4</td>
<td width="73">7/8</td>
<td width="76">7/16</td>
<td width="90">-12.50000</td>
<td width="93">-4.90792</td>
<td width="101">5.60480</td>
</tr>
<tr height="20">
<td height="20">5</td>
<td width="73">15/16</td>
<td width="76">15/32</td>
<td width="90">-6.25000</td>
<td width="93">1.88438</td>
<td width="101">3.45847</td>
</tr>
</tbody>
</table>
<p><strong></strong></p>
<p><strong>Table: Error in the approximate value computation with various values of </strong><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha" border="0" alt="" align="absmiddle" />, <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\beta" border="0" alt="" align="absmiddle" /></p>
<h2>Observations</h2>
<p>1. The chosen values of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha" border="0" alt="" align="absmiddle" />, <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\beta" border="0" alt="" align="absmiddle" />facilitates simple multiplier-less implementation of approximate computation (can be implemented using only bit shift and addition).</p>
<p>2. For Options (1),  (3) the maximum error is more than the expected value. Hence we need to allocate extra bits for the output to prevent overflow.</p>
<p>3. The error in the approximate magnitude computation repeats every 90 degrees.</p>
<h2>Reference</h2>
<p>Chapter 13.2 of <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FUnderstanding-Digital-Signal-Processing-Richard%2Fdp%2F0201634678&amp;tag=dl04-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325">Understanding Digital Signal Processing, Richard Lyons</a><img style="border: medium none  ! important; margin: 0px ! important;" src="https://www.assoc-amazon.com/e/ir?t=dl04-20&amp;l=ur2&amp;o=1" border="0" alt="" width="1" height="1" /></p>


<p>Related posts:<ol><li><a href='http://www.dsplog.com/2007/12/16/using-cordic-for-phase-and-magnitude-computation/' rel='bookmark' title='Permanent Link: Using CORDIC for phase and magnitude computation'>Using CORDIC for phase and magnitude computation</a></li><li><a href='http://www.dsplog.com/2008/08/10/ber-bpsk-rayleigh-channel/' rel='bookmark' title='Permanent Link: BER for BPSK in Rayleigh channel'>BER for BPSK in Rayleigh channel</a></li><li><a href='http://www.dsplog.com/2008/02/24/peak-to-average-power-ratio-for-ofdm/' rel='bookmark' title='Permanent Link: Peak to Average Power Ratio for OFDM'>Peak to Average Power Ratio for OFDM</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.dsplog.com/2009/02/08/approximate-vector-magnitude-computation/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using CORDIC for phase and magnitude computation</title>
		<link>http://www.dsplog.com/2007/12/16/using-cordic-for-phase-and-magnitude-computation/</link>
		<comments>http://www.dsplog.com/2007/12/16/using-cordic-for-phase-and-magnitude-computation/#comments</comments>
		<pubDate>Sun, 16 Dec 2007 09:22:17 +0000</pubDate>
		<dc:creator>Krishna Sankar</dc:creator>
				<category><![CDATA[DSP]]></category>
		<category><![CDATA[CORDIC]]></category>
		<category><![CDATA[magnitude]]></category>
		<category><![CDATA[phase]]></category>

		<guid isPermaLink="false">http://www.dsplog.com/2007/12/16/using-cordic-for-phase-and-magnitude-computation/</guid>
		<description><![CDATA[In a previous post (here), we looked at using CORDIC (Co-ordinate Rotation by DIgital Computer) for understanding how a complex number  can be rotated by an angle  without using actual multipliers. Let us know try to understand how we can use CORDIC for finding the phase and magnitude of a complex number.
Basics
The CORDIC [...]


Related posts:<ol><li><a href='http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/' rel='bookmark' title='Permanent Link: CORDIC for phase rotation'>CORDIC for phase rotation</a></li><li><a href='http://www.dsplog.com/2009/02/08/approximate-vector-magnitude-computation/' rel='bookmark' title='Permanent Link: Approximate Vector Magnitude Computation'>Approximate Vector Magnitude Computation</a></li><li><a href='http://www.dsplog.com/2008/08/08/negative-frequency/' rel='bookmark' title='Permanent Link: Negative Frequency'>Negative Frequency</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>In a previous post (<a href="http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/">here</a>), we looked at using CORDIC (Co-ordinate Rotation by DIgital Computer) for understanding how a complex number <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" /> can be rotated by an angle <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\theta" border="0" alt="" align="absmiddle" /> without using actual multipliers. Let us know try to understand how we can use CORDIC for finding the phase and magnitude of a complex number.</p>
<p><strong><span style="text-decoration: underline;">Basics</span></strong></p>
<p>The CORDIC algorithm is built on successively multiplying the complex number <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" />, by <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?%5Cmathbf%7BY%7D%20=1%20+%20j2%5E%7B-k%7D" border="0" alt="" align="absmiddle" />. As can be noticed, as the elements of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Y}" border="0" alt="" align="absmiddle" /> can be represented in powers of 2, the multiplication can be achieved by using the appropriate &#8216;bit shift&#8217;.  For further details, please refer to the previous post (<a href="http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/">CORDIC for phase rotation</a>).</p>
<p><span id="more-29"></span></p>
<p><strong><span style="text-decoration: underline;">Finding the magnitude and phase</span></strong></p>
<p>It is reasonably obvious that the multiplying a complex number <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" /> by <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?e^{j\theta}" border="0" alt="" align="absmiddle" /> does not change the magnitude of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" />.</p>
<p>Given so, if phase rotation of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" /> results in <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Z}" border="0" alt="" align="absmiddle" />, and the imaginary component of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Z}" border="0" alt="" align="absmiddle" /> is 0, then the real part of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Z}" border="0" alt="" align="absmiddle" /> stores the magnitude of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" />.</p>
<p>To put in equations, if</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Z}=\mathbf{X}e^{j\theta}" border="0" alt="" align="absmiddle" />, where <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?%5CIm%20%5Cleft%5B%7B%5Cmathbf%7BZ%7D%7D%5Cright%5D=0" border="0" alt="" align="absmiddle" />,</p>
<p>then,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?%5CRe%20%5Cleft%5B%7B%5Cmathbf%7BZ%7D%7D%5Cright%5D=%7C%5Cmathbf%7BX%7D%7C" border="0" alt="" align="absmiddle" /> (real part of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Z}" border="0" alt="" align="absmiddle" /> is the magnitude of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" />)</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?%5Ctheta%20=%20-%5Cangle%5Cleft%5B%7BX%7D%5Cright%5D" border="0" alt="" align="absmiddle" /> (the rotation angle <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\theta" border="0" alt="" align="absmiddle" /> is the negative of the phase of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" />)</p>
<p>This is the fundamental idea behind finding the magnitude and phase of a complex number using CORDIC.</p>
<p>The sequence of events is as shown below:</p>
<p>(a) The input complex number is subject to a series of phase rotations.</p>
<p>(b) The sign of the phase rotation is the negative of the sign of imaginary component of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Z}" border="0" alt="" align="absmiddle" />.</p>
<p>(c) After multiple iterations, imaginary component of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Z}" border="0" alt="" align="absmiddle" /> tends to zero.</p>
<p>(d) <span style="text-decoration: underline;">Then, the real part of the new complex vector represents the magnitude and the cumulative phase value represents the negative of the phase of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" />.</span></p>
<p><img src="http://www.dsplog.com/db-install/wp-content/uploads/2008/04/cordic_for_phase_magnitude.jpg" alt="Flowchart of the operations when CORDIC is used for phase and magnitude computation" width="375" height="500" /></p>
<p><strong>Figure: Flow chart for the operations involved in using CORDIC for computing phase and magnitude</strong></p>
<p>The reference phase <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha_k=\angle\left[1+j2^{-k}\right]" border="0" alt="" align="absmiddle" /> (phase of  <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?1+j2^{-k}" border="0" alt="" align="absmiddle" />).</p>
<p>The scaling factor of 1.64676025786545 is to remove the &#8216;gain&#8217;  following successive rotations by <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?1%20+%20sj2%5E%7B-k%7D" border="0" alt="" align="absmiddle" />. Please look at the previous post on CORDIC (<a href="http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/">here</a>) for details.</p>
<p><span style="text-decoration: underline;">Note:</span></p>
<p>If the input complex number lies in the second or third quadrant, it needs to be first shifted to the first/fourth quadrant before we start the sequence of events shown in the figure above (as the CORDIC range is limited to around +/-90 degrees). This can be achieved by multiplication by <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?j" border="0" alt="" align="absmiddle" /> or <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?-j" border="0" alt="" align="absmiddle" />, as appropriate.</p>
<h2>Simulation model</h2>
<p>Simple Matlab/Octave script for computing the phase and magnitude of a complex number using the CORDIC approach. Quick comparison indicate that the computed and acutal values are closely matching.</p>
<p>Click <a title="Script for computing the phase and magnitude of a complex number using the CORDIC" href="http://www.dsplog.com/db-install/wp-content/uploads/2008/04/script_cordic_phase_magnitude.m">here</a> to dowload<br />
<strong><span style="text-decoration: underline;">Reference</span></strong></p>
<p>[DSPGURU-CORDIC] <a href="http://www.dspguru.com/info/faqs/cordic.htm">CORDIC FAQ in dspGuru(TM)</a></p>
<p>Hope this helps.</p>
<p>Krishna</p>


<p>Related posts:<ol><li><a href='http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/' rel='bookmark' title='Permanent Link: CORDIC for phase rotation'>CORDIC for phase rotation</a></li><li><a href='http://www.dsplog.com/2009/02/08/approximate-vector-magnitude-computation/' rel='bookmark' title='Permanent Link: Approximate Vector Magnitude Computation'>Approximate Vector Magnitude Computation</a></li><li><a href='http://www.dsplog.com/2008/08/08/negative-frequency/' rel='bookmark' title='Permanent Link: Negative Frequency'>Negative Frequency</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.dsplog.com/2007/12/16/using-cordic-for-phase-and-magnitude-computation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CORDIC for phase rotation</title>
		<link>http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/</link>
		<comments>http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/#comments</comments>
		<pubDate>Sun, 19 Aug 2007 10:04:00 +0000</pubDate>
		<dc:creator>Krishna Sankar</dc:creator>
				<category><![CDATA[DSP]]></category>
		<category><![CDATA[CORDIC]]></category>
		<category><![CDATA[phase]]></category>

		<guid isPermaLink="false">http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/</guid>
		<description><![CDATA[My understanding of the CORDIC (Co-ordinate Rotation by DIgital Computer) thanks to the nice article in [DSPGURU-CORDIC].

The idea is that rotation of a complex number  by an angle  can be achieved without using multipliers. The phase angle  is approximately equal to successive addition or subtraction of angles from a set of reference [...]


Related posts:<ol><li><a href='http://www.dsplog.com/2007/12/16/using-cordic-for-phase-and-magnitude-computation/' rel='bookmark' title='Permanent Link: Using CORDIC for phase and magnitude computation'>Using CORDIC for phase and magnitude computation</a></li><li><a href='http://www.dsplog.com/2007/06/10/first-order-digital-pll-for-tracking-constant-phase-offset/' rel='bookmark' title='Permanent Link: First order digital PLL for tracking constant phase offset'>First order digital PLL for tracking constant phase offset</a></li><li><a href='http://www.dsplog.com/2008/05/12/gray-code-to-binary-conversion-for-psk-pam/' rel='bookmark' title='Permanent Link: Gray code to Binary conversion for PSK and PAM'>Gray code to Binary conversion for PSK and PAM</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>My understanding of the CORDIC (Co-ordinate Rotation by DIgital Computer) thanks to the nice article in <a href="http://www.dspguru.com/info/faqs/cordic.htm">[DSPGURU-CORDIC]</a>.</p>
<p><span id="more-20"></span></p>
<p>The idea is that rotation of a complex number <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" /> by an angle <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\theta" border="0" alt="" align="absmiddle" /> can be achieved without using multipliers. The phase angle <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\theta" border="0" alt="" align="absmiddle" /> is approximately equal to successive addition or subtraction of angles from a set of reference angles i.e. <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\theta \simeq \hat{\theta}" border="0" alt="" align="absmiddle" />, where</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\hat{\theta} = \sum_{k=0}^{K-1}s_k\alpha_k" border="0" alt="" align="absmiddle" />,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha_k" border="0" alt="" align="absmiddle" /> is the set of reference angles,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?s_k" border="0" alt="" align="absmiddle" /> is the sign (takes +1 or -1) and</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?K" border="0" alt="" align="absmiddle" /> is the number of iteration.</p>
<p>Let the complex number corresponding to reference phase <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha_k" border="0" alt="" align="absmiddle" /> is <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Y} =1 + j2^{-k}" border="0" alt="" align="absmiddle" />. The reference angles for different values of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?k" border="0" alt="" align="absmiddle" />is listed in the table below</p>
<table style="width: 325pt; border-collapse: collapse;" border="1" cellspacing="1" cellpadding="1" width="433">
<colgroup>
<col style="width: 45pt;" width="60"></col>
<col style="width: 48pt;" width="64"></col>
<col style="width: 73pt;" width="97"></col>
<col style="width: 80pt;" width="106"></col>
<col style="width: 79pt;" width="105"></col>
</colgroup>
<tbody>
<tr style="height: 12.75pt;" height="17">
<td class="xl24" style="width: 45pt; height: 12.75pt;" width="56" height="17"><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?k" border="0" alt="" align="absmiddle" /></td>
<td class="xl24" style="border-left: medium none; width: 48pt" width="61"><strong>Re{Y}</strong></td>
<td class="xl24" style="border-left: medium none; width: 73pt" width="97"><strong>Im{Y} = <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?2^{-k}" border="0" alt="" align="absmiddle" /></strong></td>
<td class="xl24" style="border-left: medium none; width: 80pt" width="107"><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha_k" border="0" alt="" align="absmiddle" /><br />
(in degrees)</td>
<td class="xl24" style="border-left: medium none; width: 79pt" width="104"><strong>abs()</strong></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">0</td>
<td class="xl25" style="border-top: medium none; border-left: medium none">1</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.000000000</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">45.000000000</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.414213562</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">1</td>
<td class="xl25" style="border-top: medium none; border-left: medium none">1</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.500000000</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">26.565051177</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.118033989</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">2</td>
<td class="xl25" style="border-top: medium none; border-left: medium none">1</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.250000000</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">14.036243468</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.030776406</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">3</td>
<td class="xl25" style="border-top: medium none; border-left: medium none">1</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.125000000</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">7.125016349</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.007782219</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">4</td>
<td class="xl25" style="border-top: medium none; border-left: medium none">1</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.062500000</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">3.576334375</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.001951221</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">5</td>
<td class="xl25" style="border-top: medium none; border-left: medium none">1</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.031250000</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.789910608</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.000488162</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">6</td>
<td class="xl25" style="border-top: medium none; border-left: medium none">1</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.015625000</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.895173710</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.000122063</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">7</td>
<td class="xl25" style="border-top: medium none; border-left: medium none">1</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.007812500</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.447614171</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.000030517</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">8</td>
<td class="xl25" style="border-top: medium none; border-left: medium none">1</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.003906250</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.223810500</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.000007629</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">9</td>
<td class="xl25" style="border-top: medium none; border-left: medium none">1</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.001953125</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">0.111905677</td>
<td class="xl26" style="border-top: medium none; border-left: medium none">1.000001907</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="border-top: medium none; height: 12.75pt" height="17">&#8230;.</td>
<td class="xl25" style="border-top: medium none; border-left: medium none"></td>
<td class="xl26" style="border-top: medium none; border-left: medium none"></td>
<td class="xl26" style="border-top: medium none; border-left: medium none"></td>
<td class="xl26" style="border-top: medium none; border-left: medium none"></td>
</tr>
</tbody>
</table>
<p><strong>Table: List of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\alpha_k" border="0" alt="" align="absmiddle" />for <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?k" border="0" alt="" align="absmiddle" />= 1 to 10</strong></p>
<p>The set of operations for rotating a complex number <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" /> by an angle <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\theta" border="0" alt="" align="absmiddle" /> to generate <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Z} = \mathbf{X}e^{j\theta}" border="0" alt="" align="absmiddle" /> in the CORDIC way can be as shown below:</p>
<p><a title="Photo Sharing" href="http://www.flickr.com/photos/8649381@N03/1161323284/"><img src="http://farm2.static.flickr.com/1092/1161323284_98e37a93a5.jpg" alt="cordic_for_phase_rotation" width="423" height="500" /></a></p>
<p><strong>Figure: CORDIC for phase rotation</strong></p>
<p>As the multiplication by <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?1 + sj2^{-k}" border="0" alt="" align="absmiddle" /> involves only power of two, the operation can be implemented with out using &#8216;real&#8217; multipliers. Nice advantage when we need to save hardware. The flip side is the number of iterations required for obtaining accurate estimate.</p>
<p>Additionally, the multiplication by <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?1 + sj2^{-k}" border="0" alt="" align="absmiddle" /> introduces gain (as shown in the Table above) and after 16 iterations (<img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?K=16" border="0" alt="" align="absmiddle" />) the cumulative gain come to 1.64676025786545. Hence the block for compensating the gain.</p>
<p><span style="color: #0000ff;">% Simple Matlab example of phase rotation using CORDIC<br />
clear<br />
% creating the reference angles<br />
Y_k = ones(32,1) + j*2.^(-1*[0:1:31])&#8217;; % values of Y<br />
alpha_k = angle(Y_k)*180/pi; % reference angles </span></p>
<p><span style="color: #0000ff;">X = 2+3*j; % complex number to be phase rotated<br />
thetaDeg = 25; % the phase to be rotated<br />
K = 16; % number of iterations </span></p>
<p><span style="color: #0000ff;">thetaHat = 0; % initial phase angle<br />
Z = X; % assigning the output as the input </span></p>
<p><span style="color: #0000ff;">% for different values of k<br />
for k = 0: K-1<br />
s = sign(thetaDeg &#8211; thetaHat); % difference<br />
if s == 0  s = 1;  end     % to handle when thetaDeg = 0<br />
Z = Z*[1 + s*j*2^(-1*k)];<br />
thetaHat = thetaHat + s*alpha_k(k+1);<br />
% dumping the variables for plot<br />
sign_v(k+1) = s;<br />
thetaHat_v(k+1) = thetaHat;<br />
end </span></p>
<p><span style="color: #0000ff;">Z_ideal = X*exp(j*thetaDeg*pi/180);<br />
Z_cordic  = Z/1.64676025786545;<br />
err = Z_ideal &#8211; Z_cordic;<br />
errdB = 10*log10(err*err&#8217;) </span></p>
<p><span style="color: #0000ff;">close all<br />
figure<br />
plot(thetaHat_v,&#8217;m.-&#8217;)<br />
grid on<br />
xlabel(&#8216;k&#8217;)<br />
ylabel(&#8216;thetaHat, degree&#8217;)<br />
title(&#8216;thetaHat converging to theta over K iterations&#8217;)</span></p>
<p><a title="Photo Sharing" href="http://www.flickr.com/photos/8649381@N03/1168469081/"><img src="http://farm2.static.flickr.com/1033/1168469081_9691947103.jpg" alt="cordic_thetaHat_convergence" width="500" height="375" /></a></p>
<p><strong>Reference</strong></p>
<p>[DSPGURU-CORDIC] <a href="http://www.dspguru.com/info/faqs/cordic.htm">CORDIC FAQ in dspGuru(TM)</a></p>


<p>Related posts:<ol><li><a href='http://www.dsplog.com/2007/12/16/using-cordic-for-phase-and-magnitude-computation/' rel='bookmark' title='Permanent Link: Using CORDIC for phase and magnitude computation'>Using CORDIC for phase and magnitude computation</a></li><li><a href='http://www.dsplog.com/2007/06/10/first-order-digital-pll-for-tracking-constant-phase-offset/' rel='bookmark' title='Permanent Link: First order digital PLL for tracking constant phase offset'>First order digital PLL for tracking constant phase offset</a></li><li><a href='http://www.dsplog.com/2008/05/12/gray-code-to-binary-conversion-for-psk-pam/' rel='bookmark' title='Permanent Link: Gray code to Binary conversion for PSK and PAM'>Gray code to Binary conversion for PSK and PAM</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.dsplog.com/2007/08/19/cordic-for-phase-rotation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Straight line fit using least squares estimate</title>
		<link>http://www.dsplog.com/2007/07/15/straight-line-fit-using-least-squares-estimate/</link>
		<comments>http://www.dsplog.com/2007/07/15/straight-line-fit-using-least-squares-estimate/#comments</comments>
		<pubDate>Sun, 15 Jul 2007 07:22:00 +0000</pubDate>
		<dc:creator>Krishna Sankar</dc:creator>
				<category><![CDATA[DSP]]></category>
		<category><![CDATA[least squares]]></category>
		<category><![CDATA[straight line]]></category>

		<guid isPermaLink="false">http://www.dsplog.com/2007/07/15/straight-line-fit-using-least-squares-estimate/</guid>
		<description><![CDATA[Two points suffice for drawing a straight line. However we may be presented with a set of data points (more than two?) presumably forming a straight line. How can one use the available set of data points to draw a straight line?
A probable approach is to draw a straight line which hopefully minimizes the error [...]


Related posts:<ol><li><a href='http://www.dsplog.com/2007/06/10/first-order-digital-pll-for-tracking-constant-phase-offset/' rel='bookmark' title='Permanent Link: First order digital PLL for tracking constant phase offset'>First order digital PLL for tracking constant phase offset</a></li><li><a href='http://www.dsplog.com/2009/02/08/approximate-vector-magnitude-computation/' rel='bookmark' title='Permanent Link: Approximate Vector Magnitude Computation'>Approximate Vector Magnitude Computation</a></li><li><a href='http://www.dsplog.com/2009/03/08/iq-imbalance-in-transmitter/' rel='bookmark' title='Permanent Link: IQ imbalance in transmitter'>IQ imbalance in transmitter</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>Two points suffice for drawing a straight line. However we may be presented with a set of data points (more than two?) presumably forming a straight line. How can one use the available set of data points to draw a straight line?</p>
<p>A probable approach is to draw a straight line which hopefully minimizes the error between the observed data points and estimated straight line.</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?err = \Sigma_{i=1}^N\left(y_i - \hat{y}_i\right)^2" border="0" alt="" align="absmiddle" /> where <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?y_i" border="0" alt="" align="absmiddle" /> is the observed data points and <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\hat{y}_i" border="0" alt="" align="absmiddle" /> is the points from estimated straight line.</p>
<p><span id="more-18"></span></p>
<p>To draw the estimated straight line <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\hat{y}=mx+c" border="0" alt="" align="absmiddle" />, we need to estimate the slope, <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?m" border="0" alt="" align="absmiddle" /> and the constant, <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?c" border="0" alt="" align="absmiddle" />.</p>
<p>Formulating as a matrix,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\left[\begin{eqnarray} y_1 \\ y_2 \\ y_3 \\  \vdots \\ y_n \end{eqnarray}\right]=\left[\begin{eqnarray} x_1\  1\\ x_2\ 1 \\ x_3\ 1 \\  \vdots \\ x_n\ 1 \end{eqnarray}\right]\left[\begin{eqnarray} m \\ c \end{eqnarray}\right]+\left[\begin{eqnarray} \eta_1\\ \eta_2 \\ \eta_3 \\  \vdots \\ \eta_n\end{eqnarray}\right]" border="0" alt="" align="absmiddle" /></p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Y} = \mathbf{X}\left[\begin{eqnarray} m \\ c \end{eqnarray}\right]+ \mathbf{N}" border="0" alt="" align="absmiddle" />,</p>
<p>where,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?{y}_i" border="0" alt="" align="absmiddle" /> = <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{Y}" border="0" alt="" align="absmiddle" /> is the set of observations is a matrix of dimension <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?[N \times 1]" border="0" alt="" align="absmiddle" /> ,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?{x}_i" border="0" alt="" align="absmiddle" /> = <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{X}" border="0" alt="" align="absmiddle" /> is the set of coefficients is a matrix of dimension <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?[N \times 2]" border="0" alt="" align="absmiddle" />,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\left[\begin{eqnarray} m \\ c \end{eqnarray}\right]" border="0" alt="" align="absmiddle" /> is the slope and constant estimate of dimension <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?[2\times 1]" border="0" alt="" align="absmiddle" />,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\eta_i" border="0" alt="" align="absmiddle" /> = <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\mathbf{N}" border="0" alt="" align="absmiddle" />is the noise is a matrix of dimension <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?[N\times1]" border="0" alt="" align="absmiddle" /> .</p>
<p>The <strong>least square estimate of the straight line</strong> is,</p>
<p><img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\left[\begin{eqnarray} m \\ c \end{eqnarray}\right]=(\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{Y}" border="0" alt="" align="absmiddle" />.</p>
<p>A simple MATLAB code for least squares straight line fit is given below:</p>
<p><span style="color: #0000ff;">% Least Squares Estimate<br />
rand(&#8217;state&#8217;,100); % initializing the random number generation<br />
y = [5:3:50]; % observations, y_i<br />
y = y + 5*rand(size(y)); % y_i with noise added<br />
x = 1:length(y); % the x co-ordinates </span></p>
<p><span style="color: #0000ff;">% Formulating in matrix for solving for least squares estimate<br />
Y = y.&#8217;;<br />
X = [x.' ones(1,length(x)).'];<br />
alpha = inv(X&#8217;*X)*X&#8217;*Y; % solving for m and c </span></p>
<p><span style="color: #0000ff;">% constructing the straight line using the estimated slope and constant<br />
yEst = alpha(1)*x + alpha(2); </span></p>
<p><span style="color: #0000ff;">close all<br />
figure<br />
plot(x,y,&#8217;r.&#8217;)<br />
hold on<br />
plot(x,yEst,&#8217;b')<br />
legend(&#8216;observations&#8217;, &#8216;estimated straight line&#8217;)<br />
grid on<br />
ylabel(&#8216;observations&#8217;)<br />
xlabel(&#8216;x axis&#8217;)<br />
title(&#8216;least squares straight line fit&#8217;)</span></p>
<p><a title="Photo Sharing" href="http://www.flickr.com/photos/8649381@N03/809038180/"><img src="http://farm2.static.flickr.com/1085/809038180_7959b6bea5.jpg" alt="least_squares_fit" width="500" height="375" /></a></p>
<p><strong></strong></p>
<p><strong>References:</strong></p>
<p>[1] <a href="http://www.mathworks.com/access/helpdesk_r13/help/toolbox/curvefit/ch_fitt5.html">Details on Curve fitting toolbox from  MathWorks(TM) website</a></p>


<p>Related posts:<ol><li><a href='http://www.dsplog.com/2007/06/10/first-order-digital-pll-for-tracking-constant-phase-offset/' rel='bookmark' title='Permanent Link: First order digital PLL for tracking constant phase offset'>First order digital PLL for tracking constant phase offset</a></li><li><a href='http://www.dsplog.com/2009/02/08/approximate-vector-magnitude-computation/' rel='bookmark' title='Permanent Link: Approximate Vector Magnitude Computation'>Approximate Vector Magnitude Computation</a></li><li><a href='http://www.dsplog.com/2009/03/08/iq-imbalance-in-transmitter/' rel='bookmark' title='Permanent Link: IQ imbalance in transmitter'>IQ imbalance in transmitter</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.dsplog.com/2007/07/15/straight-line-fit-using-least-squares-estimate/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Interpreting the output of fft() operation in Matlab</title>
		<link>http://www.dsplog.com/2007/06/17/interpreting-the-output-of-fft-operation-in-matlab/</link>
		<comments>http://www.dsplog.com/2007/06/17/interpreting-the-output-of-fft-operation-in-matlab/#comments</comments>
		<pubDate>Sun, 17 Jun 2007 16:32:00 +0000</pubDate>
		<dc:creator>Krishna Sankar</dc:creator>
				<category><![CDATA[DSP]]></category>
		<category><![CDATA[FFT]]></category>

		<guid isPermaLink="false">http://www.dsplog.com/2007/06/17/interpreting-the-output-of-fft-operation-in-matlab/</guid>
		<description><![CDATA[It might be interesting to interpret the output of the fft() function in Matlab. Consider the following simple examples.
fsMHz = 20; % sampling frequency
fcMHz = 1.5625; % signal frequency
N = 128; % fft size
% generating the time domain signal
x1T = exp(j*2*pi*fcMHz*[0:N-1]/fsMHz);
x1F = fft(x1T,N); % 128 pt FFT
figure;
plot([-N/2:N/2-1]*fsMHz/N,fftshift(abs(x1F))) ; % sub-carriers from [-128:127]
xlabel('frequency, MHz')
ylabel('amplitude')
title('frequency response of [...]


Related posts:<ol><li><a href='http://www.dsplog.com/2007/05/12/polyphase-filters-for-interpolation/' rel='bookmark' title='Permanent Link: Polyphase filters for interpolation'>Polyphase filters for interpolation</a></li><li><a href='http://www.dsplog.com/2007/03/25/zero-order-hold-and-first-order-hold-based-interpolation/' rel='bookmark' title='Permanent Link: Zero-order hold and first-order hold based interpolation'>Zero-order hold and first-order hold based interpolation</a></li><li><a href='http://www.dsplog.com/2008/04/14/transmit-pulse-shape-nyquist-sinc-rectangular/' rel='bookmark' title='Permanent Link: Transmit pulse shaping filter &#8211; rectangular and sinc (Nyquist)'>Transmit pulse shaping filter &#8211; rectangular and sinc (Nyquist)</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>It might be interesting to interpret the output of the fft() function in Matlab. Consider the following simple examples.</p>
<pre class="html">fsMHz = 20; % sampling frequency
fcMHz = 1.5625; % signal frequency
N = 128; % fft size
% generating the time domain signal
x1T = exp(j*2*pi*fcMHz*[0:N-1]/fsMHz);
x1F = fft(x1T,N); % 128 pt FFT
figure;
plot([-N/2:N/2-1]*fsMHz/N,fftshift(abs(x1F))) ; % sub-carriers from [-128:127]
xlabel('frequency, MHz')
ylabel('amplitude')
title('frequency response of complex sinusoidal signal');</pre>
<p><span id="more-16"></span></p>
<p><a title="Photo Sharing" href="http://www.flickr.com/photos/8649381@N03/560585801/"><img src="http://farm2.static.flickr.com/1125/560585801_f4624990d4.jpg" alt="fft_complex_cosine" width="500" height="375" /></a></p>
<p>With an<img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?N" border="0" alt="" align="absmiddle" />point fft() and sampling frequency of <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?f_s" border="0" alt="" align="absmiddle" />, the observable spectrum from <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\left[-\frac{f_s}{2},\ \ +\frac{f_s}{2}\right) \leftrightarrow [-64,\ 63]" border="0" alt="" align="absmiddle" /> is split to <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\frac{f_s}{N}" border="0" alt="" align="absmiddle" /> sub-carriers.</p>
<p>Additionally, the signal at the output of fft() is from <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\left[0,\ \ +f_s\right) \leftrightarrow [0,\ 127]" border="0" alt="" align="absmiddle" />.  As the frequencies from  <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\left[+\frac{f_s}{2},\ \ +f_s\right) \leftrightarrow [64,\ 127]" border="0" alt="" align="absmiddle" /> get aliased to <img src="http://www.dsplog.com/cgi-bin/mimetex.cgi?\left[-\frac{f_s}{2},\ \ 0\right) \leftrightarrow [-64,\ -1]" border="0" alt="" align="absmiddle" />, the operator fftshift() is used when plotting the spectrum.</p>
<p>In the example above, with a sampling frequency of 20MHz, the spectrum from [-10MHz, +10MHz) is divided into 128 sub-carriers with spaced apart by 20MHz/128 =  156.25kHz. The generated signal <span style="color: #0000ff;">x1T</span> of frequency 1.5625MHz corresponds to the information on the 10th sub-carrier, which can also be generated in the frequency domain.</p>
<pre class="html">% generating the frequency domain signal with subcarrier indices [-N/2:-1 dc 1:N/2-1]
x2F = [zeros(1,N/2) 0 zeros(1,9) 1 zeros(1,N/2-10-1)]; % valid frequency on 10th subcarrier, rest all zeros
x2T = N*ifft(fftshift(x2F)); % time domain signal using ifft()
% comparing the signals
diff = x2T &#8211; x1T;
err = diff*diff&#8217;/length(diff)</pre>
<h4><span style="text-decoration: underline;">Plotting the frequency response of a filter</span></h4>
<p>Consider a filter with the a sinc() shaped impulse response. The Matlab code for plotting the frequency response is as follows:</p>
<pre class="html">% impulse response of a sinc() filter
hT = sinc([-20:20]/3); % consider sample at 30MHz sampling;
hF = fft(hT,1024); % 128 pt FFT
figure;
plot([-512:511]*30/1024,fftshift(abs(hF))) ;
xlabel('frequency, MHz')
ylabel('amplitude')
title('frequency response of sinc filter');</pre>
<p><a title="Photo Sharing" href="http://www.flickr.com/photos/8649381@N03/565359839/"><img src="http://farm2.static.flickr.com/1102/565359839_8eda2df72b.jpg" alt="fft_sinc" width="500" height="375" /></a></p>
<p>Hopefully, the post provides some insights on the query raised in the <a href="http://groups.google.com/group/comp.dsp/browse_thread/thread/9314be1f0ca8ed62/24ffc77dabef23ef?lnk=gst&amp;q=interpreting+fft()&amp;rnum=1#24ffc77dabef23ef">comp.dsp thread</a>.</p>


<p>Related posts:<ol><li><a href='http://www.dsplog.com/2007/05/12/polyphase-filters-for-interpolation/' rel='bookmark' title='Permanent Link: Polyphase filters for interpolation'>Polyphase filters for interpolation</a></li><li><a href='http://www.dsplog.com/2007/03/25/zero-order-hold-and-first-order-hold-based-interpolation/' rel='bookmark' title='Permanent Link: Zero-order hold and first-order hold based interpolation'>Zero-order hold and first-order hold based interpolation</a></li><li><a href='http://www.dsplog.com/2008/04/14/transmit-pulse-shape-nyquist-sinc-rectangular/' rel='bookmark' title='Permanent Link: Transmit pulse shaping filter &#8211; rectangular and sinc (Nyquist)'>Transmit pulse shaping filter &#8211; rectangular and sinc (Nyquist)</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.dsplog.com/2007/06/17/interpreting-the-output-of-fft-operation-in-matlab/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
