blob: 7df1dad7bb1cd432475642b5c1c49219bdc3af8f [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>CMSIS DSP Software Library: arm_variance_example_f32.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javaScript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Generated by Doxygen 1.7.2 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
<div class="navigation" id="top">
<div class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
<li id="searchli">
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
</div>
<div class="header">
<div class="headertitle">
<h1>arm_variance_example_f32.c</h1> </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="comment">/* ---------------------------------------------------------------------- </span>
<span class="comment">* Copyright (C) 2010 ARM Limited. All rights reserved. </span>
<span class="comment">* </span>
<span class="comment">* $Date: 29. November 2010 </span>
<span class="comment">* $Revision: V1.0.3</span>
<span class="comment">* </span>
<span class="comment">* Project: CMSIS DSP Library </span>
<span class="comment">* Title: arm_variance_example_f32.c </span>
<span class="comment">* </span>
<span class="comment">* Description: Example code demonstrating variance calculation of input sequence.</span>
<span class="comment">* </span>
<span class="comment">* Target Processor: Cortex-M4/Cortex-M3 </span>
<span class="comment">*</span>
<span class="comment">*</span>
<span class="comment">* Version 1.0.3 2010/11/29 </span>
<span class="comment">* Re-organized the CMSIS folders and updated documentation. </span>
<span class="comment">* </span>
<span class="comment">* Version 1.0.1 2010/10/05 KK </span>
<span class="comment">* Production release and review comments incorporated. </span>
<span class="comment">*</span>
<span class="comment">* Version 1.0.0 2010/09/20 KK</span>
<span class="comment">* Production release and review comments incorporated.</span>
<span class="comment">* ------------------------------------------------------------------- */</span>
<span class="preprocessor">#include &lt;math.h&gt;</span>
<span class="preprocessor">#include &quot;<a class="code" href="arm__math_8h.html">arm_math.h</a>&quot;</span>
<span class="comment">/* ----------------------------------------------------------------------</span>
<span class="comment">* Defines each of the tests performed</span>
<span class="comment">* ------------------------------------------------------------------- */</span>
<span class="preprocessor">#define MAX_BLOCKSIZE 32</span>
<span class="preprocessor"></span><span class="preprocessor">#define DELTA (0.000001f)</span>
<span class="preprocessor"></span>
<span class="comment">/* ----------------------------------------------------------------------</span>
<span class="comment">* Declare I/O buffers </span>
<span class="comment">* ------------------------------------------------------------------- */</span>
<a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715" title="32-bit floating-point type definition.">float32_t</a> <a name="a0"></a><a class="code" href="arm__signal__converge__example__f32_8c.html#a16e759789fbc05f878863f009066c8ea">wire1</a>[<a name="a1"></a><a class="code" href="arm__convolution__example__f32_8c.html#af8a1d2ed31f7c9a00fec46a798edb61b">MAX_BLOCKSIZE</a>];
<a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715" title="32-bit floating-point type definition.">float32_t</a> <a name="a2"></a><a class="code" href="arm__signal__converge__example__f32_8c.html#a4e370163c81ae2b72cc655a6b79e4c6a">wire2</a>[<a class="code" href="arm__convolution__example__f32_8c.html#af8a1d2ed31f7c9a00fec46a798edb61b">MAX_BLOCKSIZE</a>];
<a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715" title="32-bit floating-point type definition.">float32_t</a> <a name="a3"></a><a class="code" href="arm__signal__converge__example__f32_8c.html#a7e2cceadf6ec7f0aa0f698a680fa3a4b">wire3</a>[<a class="code" href="arm__convolution__example__f32_8c.html#af8a1d2ed31f7c9a00fec46a798edb61b">MAX_BLOCKSIZE</a>];
<span class="comment">/* ----------------------------------------------------------------------</span>
<span class="comment">* Test input data for Floating point Variance example for 32-blockSize</span>
<span class="comment">* Generated by the MATLAB randn() function</span>
<span class="comment">* ------------------------------------------------------------------- */</span>
<a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715" title="32-bit floating-point type definition.">float32_t</a> <a name="a4"></a><a class="code" href="arm__graphic__equalizer__example__q31_8c.html#aa4699dc6ee05353c83e0be4e69f6ad05">testInput_f32</a>[32] =
{
-0.432564811528221, -1.665584378238097, 0.125332306474831, 0.287676420358549,
-1.146471350681464, 1.190915465642999, 1.189164201652103, -0.037633276593318,
0.327292361408654, 0.174639142820925, -0.186708577681439, 0.725790548293303,
-0.588316543014189, 2.183185818197101, -0.136395883086596, 0.113931313520810,
1.066768211359189, 0.059281460523605, -0.095648405483669, -0.832349463650022,
0.294410816392640, -1.336181857937804, 0.714324551818952, 1.623562064446271,
-0.691775701702287, 0.857996672828263, 1.254001421602532, -1.593729576447477,
-1.440964431901020, 0.571147623658178, -0.399885577715363, 0.689997375464345
};
<span class="comment">/* ----------------------------------------------------------------------</span>
<span class="comment">* Declare Global variables </span>
<span class="comment">* ------------------------------------------------------------------- */</span>
uint32_t <a name="a5"></a><a class="code" href="arm__fir__example__f32_8c.html#ab6558f40a619c2502fbc24c880fd4fb0">blockSize</a> = 32;
<a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715" title="32-bit floating-point type definition.">float32_t</a> <a name="a6"></a><a class="code" href="arm__variance__example__f32_8c.html#a26cbbfe2a7905669e8440159465050df">refVarianceOut</a> = 0.903941793931839;
<span class="comment">/* ----------------------------------------------------------------------</span>
<span class="comment">* Variance calculation test</span>
<span class="comment">* ------------------------------------------------------------------- */</span>
int32_t <a name="a7"></a><a class="code" href="arm__class__marks__example__f32_8c.html#a196718f834091385d38586a0ce4009dc">main</a>(<span class="keywordtype">void</span>)
{
<a class="code" href="arm__math_8h.html#a5e459c6409dfcd2927bb8a57491d7cf6" title="Error status returned by some functions in the library.">arm_status</a> <a name="a8"></a><a class="code" href="arm__dotproduct__example__f32_8c.html#a88ccb294236ab22b00310c47164c53c3">status</a>;
<a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715" title="32-bit floating-point type definition.">float32_t</a> <a name="a9"></a><a class="code" href="arm__class__marks__example__f32_8c.html#acc9290716b3c97381ce52d14b4b01681">mean</a>, oneByBlockSize;
<a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715" title="32-bit floating-point type definition.">float32_t</a> variance;
<a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715" title="32-bit floating-point type definition.">float32_t</a> diff;
status = <a name="a10"></a><a class="code" href="arm__math_8h.html#a5e459c6409dfcd2927bb8a57491d7cf6a9f8b2a10bd827fb4600e77d455902eb0">ARM_MATH_SUCCESS</a>;
<span class="comment">/* Calculation of mean value of input */</span>
<span class="comment">/* x&#39; = 1/blockSize * (x(0)* 1 + x(1) * 1 + ... + x(n-1) * 1) */</span>
<span class="comment">/* Fill wire1 buffer with 1.0 value */</span>
<a name="a11"></a><a class="code" href="group___fill.html#ga2248e8d3901b4afb7827163132baad94" title="Fills a constant value into a floating-point vector.">arm_fill_f32</a>(1.0, <a class="code" href="arm__signal__converge__example__f32_8c.html#a16e759789fbc05f878863f009066c8ea">wire1</a>, <a class="code" href="arm__fir__example__f32_8c.html#ab6558f40a619c2502fbc24c880fd4fb0">blockSize</a>);
<span class="comment">/* Calculate the dot product of wire1 and wire2 */</span>
<span class="comment">/* (x(0)* 1 + x(1) * 1 + ...+ x(n-1) * 1) */</span>
<a name="a12"></a><a class="code" href="group__dot__prod.html#ga55418d4362f6ba84c327f9b4f089a8c3" title="Dot product of floating-point vectors.">arm_dot_prod_f32</a>(<a class="code" href="arm__graphic__equalizer__example__q31_8c.html#aa4699dc6ee05353c83e0be4e69f6ad05">testInput_f32</a>, <a class="code" href="arm__signal__converge__example__f32_8c.html#a16e759789fbc05f878863f009066c8ea">wire1</a>, <a class="code" href="arm__fir__example__f32_8c.html#ab6558f40a619c2502fbc24c880fd4fb0">blockSize</a>, &amp;mean);
<span class="comment">/* Calculation of 1/blockSize */</span>
oneByBlockSize = 1.0 / (<a class="code" href="arm__fir__example__f32_8c.html#ab6558f40a619c2502fbc24c880fd4fb0">blockSize</a>);
<span class="comment">/* 1/blockSize * (x(0)* 1 + x(1) * 1 + ... + x(n-1) * 1) */</span>
<a name="a13"></a><a class="code" href="group___basic_mult.html#gaca3f0b8227da431ab29225b88888aa32" title="Floating-point vector multiplication.">arm_mult_f32</a>(&amp;mean, &amp;oneByBlockSize, &amp;mean, 1);
<span class="comment">/* Calculation of variance value of input */</span>
<span class="comment">/* (1/blockSize) * (x(0) - x&#39;) * (x(0) - x&#39;) + (x(1) - x&#39;) * (x(1) - x&#39;) + ... + (x(n-1) - x&#39;) * (x(n-1) - x&#39;) */</span>
<span class="comment">/* Fill wire2 with mean value x&#39; */</span>
<a class="code" href="group___fill.html#ga2248e8d3901b4afb7827163132baad94" title="Fills a constant value into a floating-point vector.">arm_fill_f32</a>(mean, <a class="code" href="arm__signal__converge__example__f32_8c.html#a4e370163c81ae2b72cc655a6b79e4c6a">wire2</a>, <a class="code" href="arm__fir__example__f32_8c.html#ab6558f40a619c2502fbc24c880fd4fb0">blockSize</a>);
<span class="comment">/* wire3 contains (x-x&#39;) */</span>
<a name="a14"></a><a class="code" href="group___basic_sub.html#ga7f975a472de286331134227c08aad826" title="Floating-point vector subtraction.">arm_sub_f32</a>(<a class="code" href="arm__graphic__equalizer__example__q31_8c.html#aa4699dc6ee05353c83e0be4e69f6ad05">testInput_f32</a>, <a class="code" href="arm__signal__converge__example__f32_8c.html#a4e370163c81ae2b72cc655a6b79e4c6a">wire2</a>, <a class="code" href="arm__signal__converge__example__f32_8c.html#a7e2cceadf6ec7f0aa0f698a680fa3a4b">wire3</a>, <a class="code" href="arm__fir__example__f32_8c.html#ab6558f40a619c2502fbc24c880fd4fb0">blockSize</a>);
<span class="comment">/* wire2 contains (x-x&#39;) */</span>
<a name="a15"></a><a class="code" href="group__copy.html#gadd1f737e677e0e6ca31767c7001417b3" title="Copies the elements of a floating-point vector.">arm_copy_f32</a>(<a class="code" href="arm__signal__converge__example__f32_8c.html#a7e2cceadf6ec7f0aa0f698a680fa3a4b">wire3</a>, <a class="code" href="arm__signal__converge__example__f32_8c.html#a4e370163c81ae2b72cc655a6b79e4c6a">wire2</a>, <a class="code" href="arm__fir__example__f32_8c.html#ab6558f40a619c2502fbc24c880fd4fb0">blockSize</a>);
<span class="comment">/* (x(0) - x&#39;) * (x(0) - x&#39;) + (x(1) - x&#39;) * (x(1) - x&#39;) + ... + (x(n-1) - x&#39;) * (x(n-1) - x&#39;) */</span>
<a class="code" href="group__dot__prod.html#ga55418d4362f6ba84c327f9b4f089a8c3" title="Dot product of floating-point vectors.">arm_dot_prod_f32</a>(<a class="code" href="arm__signal__converge__example__f32_8c.html#a4e370163c81ae2b72cc655a6b79e4c6a">wire2</a>, <a class="code" href="arm__signal__converge__example__f32_8c.html#a7e2cceadf6ec7f0aa0f698a680fa3a4b">wire3</a>, <a class="code" href="arm__fir__example__f32_8c.html#ab6558f40a619c2502fbc24c880fd4fb0">blockSize</a>, &amp;variance);
<span class="comment">/* Calculation of 1/blockSize */</span>
oneByBlockSize = 1.0 / (<a class="code" href="arm__fir__example__f32_8c.html#ab6558f40a619c2502fbc24c880fd4fb0">blockSize</a> - 1);
<span class="comment">/* Calculation of variance */</span>
<a class="code" href="group___basic_mult.html#gaca3f0b8227da431ab29225b88888aa32" title="Floating-point vector multiplication.">arm_mult_f32</a>(&amp;variance, &amp;oneByBlockSize, &amp;variance, 1);
<span class="comment">/* absolute value of difference between ref and test */</span>
diff = fabsf(<a class="code" href="arm__variance__example__f32_8c.html#a26cbbfe2a7905669e8440159465050df">refVarianceOut</a> - variance);
<span class="comment">/* Comparison of variance value with reference */</span>
<span class="keywordflow">if</span>(diff &gt; <a name="a16"></a><a class="code" href="arm__convolution__example__f32_8c.html#a3fd2b1bcd7ddcf506237987ad780f495">DELTA</a>)
{
status = <a name="a17"></a><a class="code" href="arm__math_8h.html#a5e459c6409dfcd2927bb8a57491d7cf6a09457f2be656b35015fd6d36202fa376">ARM_MATH_TEST_FAILURE</a>;
}
<span class="keywordflow">if</span>( status != <a class="code" href="arm__math_8h.html#a5e459c6409dfcd2927bb8a57491d7cf6a9f8b2a10bd827fb4600e77d455902eb0">ARM_MATH_SUCCESS</a>)
{
<span class="keywordflow">while</span>(1);
}
}
</pre></div> </div>
</div>
<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Fri Jul 15 2011 13:16:15 for CMSIS DSP Software Library by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>