<?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>moving average &#8211; ASN Home</title>
	<atom:link href="https://www.advsolned.com/tag/moving-average/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.advsolned.com</link>
	<description>ASN home site</description>
	<lastBuildDate>Sat, 15 Jun 2024 12:45:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>How to add an extra MA or Median filter to the ASN DSP filtering ANSI C code framework</title>
		<link>https://www.advsolned.com/how-to-add-an-extra-ma-or-median-filter-to-the-asn-dsp-filtering-ansi-c-code-framework/</link>
		
		<dc:creator><![CDATA[Marty de Vries]]></dc:creator>
		<pubDate>Thu, 06 Apr 2023 13:25:21 +0000</pubDate>
				<category><![CDATA[ASN Filter Designer]]></category>
		<category><![CDATA[ANSI C]]></category>
		<category><![CDATA[Arm Cortex-M]]></category>
		<category><![CDATA[digital filter]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[MA filter]]></category>
		<category><![CDATA[moving average]]></category>
		<guid isPermaLink="false">https://www.advsolned.com/?p=19328</guid>

					<description><![CDATA[<p>ASN Filter Designer’s ANSI C SDK framework, provides developers with a comprehensive C code framework for developing an AIoT filtering application on microcontrollers and embedded platforms.</p>
<p>The post <a rel="nofollow" href="https://www.advsolned.com/how-to-add-an-extra-ma-or-median-filter-to-the-asn-dsp-filtering-ansi-c-code-framework/">How to add an extra MA or Median filter to the ASN DSP filtering ANSI C code framework</a> appeared first on <a rel="nofollow" href="https://www.advsolned.com">ASN Home</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><section class="av_textblock_section "  itemscope="itemscope" itemtype="https://schema.org/BlogPosting" itemprop="blogPost" ><div class='avia_textblock  '   itemprop="text" ><p>ASN Filter Designer’s ANSI C SDK framework, provides developers with a comprehensive C code framework for developing  AIoT filtering application on microcontrollers and embedded platforms. Although the framework has been primarily designed to support the just ASN filter Designer’s filter cascade, it is possible to create extra filter objects to augment the cascade.</p>
<p>Two common filtering methods used by AIoT developers are the Median and moving average (MA) filters. Although these fully integrated within the Framework’s filter cascade, it is often useful to have the flexibility of an additional filtering block to act as a post filter smoothing filter.</p>
<p>An extra median or MA filter may be easily added to <code>main.c</code> as shown below. Notice that data is filtered in blocks of 4 as required by the framework.</p>
<h2>Median filter</h2>
<p>The Median filter is non-linear filtering method that uses the concept of majority voting (i.e. calculating the median) to remove glitches and smooth data.  It is edge preserving, making it a good choice for enhancing square waves or pulse like data.<br />
[code language=&#8221;cpp&#8221;]<br />
#include &quot;ASN_DSP/DSPFilters/MedianFilter.h&quot;<br />
float InputTemp[4];<br />
float OutputTemp[4];</p>
<p>MedianFilter_t MyMedianfilter;</p>
<p>InitMedianFilter(&amp;MyMedianfilter,7);  // median of length 7</p>
<p>   for (n=0; n&lt;TEST_LENGTH_SAMPLES; n+=4)<br />
   {<br />
        InputTemp[0]=InputValues[n];<br />
        InputTemp[1]=InputValues[n+1];<br />
        InputTemp[2]=InputValues[n+2];<br />
        InputTemp[3]=InputValues[n+3];</p>
<p>        MedianFilterData(&amp;MyMedianfilter,InputTemp, OutputTemp);</p>
<p>        OutputValues[n]=OutputTemp[0];<br />
        OutputValues[n+1]=OutputTemp[1];<br />
        OutputValues[n+2]=OutputTemp[2];<br />
        OutputValues[n+3]=OutputTemp[3];<br />
   }</p>
<p>[/code]<br />
<span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span></p>
<h2>Moving Average filter</h2>
<p>The moving average (MA) filter is optimal for reducing random noise while retaining a sharp step response, making it a versatile building block for smart sensor signal processing applications. It is perhaps one of the most widely used digital filters due to its conceptual simplicity and ease of implementation.<br />
[code language=&#8221;cpp&#8221;]<br />
#include &quot;ASN_DSP/DSPFilters/MAFilter.h&quot;<br />
float InputTemp[4];<br />
float OutputTemp[4];</p>
<p>MAFilter_t MyMAfilter;</p>
<p>InitMAFilter(&amp;MyMAfilter,9);  // MA of length 9</p>
<p>   for (n=0; n&lt;TEST_LENGTH_SAMPLES; n+=4)<br />
   {<br />
       InputTemp[0]=InputValues[n];<br />
       InputTemp[1]=InputValues[n+1];<br />
       InputTemp[2]=InputValues[n+2];<br />
       InputTemp[3]=InputValues[n+3];</p>
<p>       MAFilterData(&amp;MyMAfilter,InputTemp, OutputTemp);</p>
<p>       OutputValues[n]=OutputTemp[0];<br />
       OutputValues[n+1]=OutputTemp[1];<br />
       OutputValues[n+2]=OutputTemp[2];<br />
       OutputValues[n+3]=OutputTemp[3];<br />
   }</p>
<p>[/code]<br />
<span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span></p>
<p><a href="https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox.png"><img decoding="async" class="alignleft wp-image-3310" style="margin: 10px 80px 10px 20px;" src="https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox.png" alt="" width="183" height="253" srcset="https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox.png 800w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-217x300.png 217w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-768x1062.png 768w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-745x1030.png 745w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-510x705.png 510w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-450x622.png 450w" sizes="(max-width: 183px) 100vw, 183px" /></a></p>
<p style="text-align: left;"><a class="button" href="https://www.advsolned.com/request-form-asn-filter-designer-demo/">Download demo now</a></p>
<p><a class="button" href="https://www.advsolned.com/pricing-and-licencing/#Best_licence_forme">Licencing information</a></p>
</div></section><br />
<span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span>
                
                    <!--begin code -->

                    
                    <div class="pp-multiple-authors-boxes-wrapper pp-multiple-authors-wrapper pp-multiple-authors-layout-boxed multiple-authors-target-shortcode box-post-id-19551 box-instance-id-1 ppma_boxes_19551"
                    data-post_id="19551"
                    data-instance_id="1"
                    data-additional_class="pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode"
                    data-original_class="pp-multiple-authors-boxes-wrapper pp-multiple-authors-wrapper box-post-id-19551 box-instance-id-1">
                                                                                    <h2 class="widget-title box-header-title">Author</h2>
                                                                            <span class="ppma-layout-prefix"></span>
                        <div class="ppma-author-category-wrap">
                                                                                                                                    <span class="ppma-category-group ppma-category-group-1 category-index-0">
                                                                                                                        <ul class="pp-multiple-authors-boxes-ul author-ul-0">
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                                                                                                    <li class="pp-multiple-authors-boxes-li author_index_0 author_mdevries has-avatar">
                                                                                                                                                                                    <div class="pp-author-boxes-avatar">
                                                                    <div class="avatar-image">
                                                                                                                                                                                                                <img alt='' src='https://www.advsolned.com/wp-content/uploads/2023/05/martydvries.png' srcset='https://www.advsolned.com/wp-content/uploads/2023/05/martydvries.png' class='multiple_authors_guest_author_avatar avatar' height='80' width='80'/>                                                                                                                                                                                                            </div>
                                                                                                                                    </div>
                                                            
                                                            <div class="pp-author-boxes-avatar-details">
                                                                <div class="pp-author-boxes-name multiple-authors-name"><a href="https://www.advsolned.com/author/mdevries/" rel="author" title="Marty de Vries" class="author url fn">Marty de Vries</a></div>                                                                                                                                                                                                        <p class="pp-author-boxes-description multiple-authors-description author-description-0">
                                                                                                                                                    Marty is an applications engineer and embedded software expert at ASN. He has over 10 years experience in developing high performance embedded libraries and applications for Arm processors.                                                                                                                                                </p>
                                                                                                                                
                                                                                                                                    <span class="pp-author-boxes-meta multiple-authors-links">
                                                                        <a href="https://www.advsolned.com/author/mdevries/" title="View all posts">
                                                                            <span>View all posts</span>
                                                                        </a>
                                                                    </span>
                                                                                                                                <a class="ppma-author-user_email-profile-data ppma-author-field-meta ppma-author-field-type-email" aria-label="Email" href="mailto:info@advsolned.com"  target="_self"><span class="dashicons dashicons-email-alt"></span> </a>
                                                                                                                            </div>
                                                                                                                                                                                                                        </li>
                                                                                                                                                                                                                                    </ul>
                                                                            </span>
                                                                                                                        </div>
                        <span class="ppma-layout-suffix"></span>
                                            </div>
                    <!--end code -->
                    
                
                                <style>
                .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .pp-author-boxes-avatar img { 
        width: 80px !important; 
        height: 80px !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .pp-author-boxes-avatar img {
        border-radius: 50% !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .pp-author-boxes-meta a {
        background-color: #655997 !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .pp-author-boxes-meta a {
        color: #ffffff !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .pp-author-boxes-meta a:hover {
        color: #ffffff !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .ppma-author-user_url-profile-data {
        background-color: #655997 !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .ppma-author-user_url-profile-data {
        border-radius: 100% !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .ppma-author-user_url-profile-data {
        color: #ffffff !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .ppma-author-user_url-profile-data:hover {
        color: #ffffff !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .ppma-author-user_email-profile-data {
        background-color: #655997 !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .ppma-author-user_email-profile-data {
        border-radius: 100% !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .ppma-author-user_email-profile-data {
        color: #ffffff !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .ppma-author-user_email-profile-data:hover {
        color: #ffffff !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .pp-author-boxes-recent-posts-title {
        border-bottom-style: dotted !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .pp-multiple-authors-boxes-li {
        border-style: solid !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .pp-multiple-authors-boxes-li {
        color: #3c434a !important; 
    }

    .pp-multiple-authors-boxes-wrapper.pp-multiple-authors-layout-boxed.multiple-authors-target-shortcode .pp-multiple-authors-boxes-li {
        border-radius: px !important; 
    }

            </style>
        
        </p>
		<div class="wpulike wpulike-default " ><div class="wp_ulike_general_class wp_ulike_is_not_liked"><button type="button"
					aria-label="Like Button"
					data-ulike-id="19328"
					data-ulike-nonce="bae10a7124"
					data-ulike-type="post"
					data-ulike-template="wpulike-default"
					data-ulike-display-likers=""
					data-ulike-likers-style="popover"
					class="wp_ulike_btn wp_ulike_put_image wp_post_btn_19328"></button><span class="count-box wp_ulike_counter_up" data-ulike-counter-value="+2"></span>			</div></div>
	<p>The post <a rel="nofollow" href="https://www.advsolned.com/how-to-add-an-extra-ma-or-median-filter-to-the-asn-dsp-filtering-ansi-c-code-framework/">How to add an extra MA or Median filter to the ASN DSP filtering ANSI C code framework</a> appeared first on <a rel="nofollow" href="https://www.advsolned.com">ASN Home</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>A computationally efficient moving average filter: Definition and implementation</title>
		<link>https://www.advsolned.com/computationally-efficient-moving-average-filter-definition-and-implementation/</link>
		
		<dc:creator><![CDATA[ASN consultancy team]]></dc:creator>
		<pubDate>Sun, 24 May 2020 13:18:12 +0000</pubDate>
				<category><![CDATA[ASN FilterScript]]></category>
		<category><![CDATA[Arm Cortex-M]]></category>
		<category><![CDATA[digital filter]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[FIR]]></category>
		<category><![CDATA[IIR]]></category>
		<category><![CDATA[MA filter]]></category>
		<category><![CDATA[moving average]]></category>
		<guid isPermaLink="false">https://www.advsolned.com/?p=12573</guid>

					<description><![CDATA[<p>As discussed in a previous article, the moving average (MA) filter is perhaps one of the most widely used digital filters due to its conceptual simplicity and ease of implementation. The realisation diagram shown below, illustrates that an MA filter can be implemented as a simple FIR filter, just requiring additions and a delay line. [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.advsolned.com/computationally-efficient-moving-average-filter-definition-and-implementation/">A computationally efficient moving average filter: Definition and implementation</a> appeared first on <a rel="nofollow" href="https://www.advsolned.com">ASN Home</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>As discussed in a <a style="color: #0000ff;" href="https://www.advsolned.com/the-moving-average-filter/">previous article</a>, the moving average (MA) filter is perhaps one of the most widely used digital filters due to its conceptual simplicity and ease of implementation. The realisation diagram shown below, illustrates that an MA filter can be implemented as a simple FIR filter, just requiring additions and a delay line.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img fetchpriority="high" decoding="async" width="670" height="217" src="https://www.advsolned.com/wp-content/uploads/2018/07/firdirectformPNG.png" alt="moving average filter, an MA filter can be implemented as a simple FIR filter, just requiring additions and a delay line. moving average FIR filter" class="wp-image-5927" srcset="https://www.advsolned.com/wp-content/uploads/2018/07/firdirectformPNG.png 670w, https://www.advsolned.com/wp-content/uploads/2018/07/firdirectformPNG-300x97.png 300w, https://www.advsolned.com/wp-content/uploads/2018/07/firdirectformPNG-450x146.png 450w" sizes="(max-width: 670px) 100vw, 670px" /></figure></div>



<p>Modelling the above, we see that a moving average filter of length \(\small\textstyle L\) for an input signal \(\small\textstyle x(n)\) may be defined as follows:</p>



<p class="has-text-align-center">\( y(n)=\large{\frac{1}{L}}\normalsize{\sum\limits_{k=0}^{L-1}x(n-k)}\quad \text{for} \quad\normalsize{n=0,1,2,3&#8230;.}\label{FIRdef}\tag{1}\)</p>



<p>This computation requires \(\small\textstyle L-1\) additions, which may become computationally demanding for very low power processors when \(\small\textstyle L\) is large. Therefore, applying some lateral thinking to the computational challenge, we see that a much more computationally efficient filter can be used in order to achieve the same result, namely:</p>



<p class="has-text-align-center"><span class="" style="display:block;clear:both;height: 0px;padding-top: 10px;border-top-width:0px;border-bottom-width:0px;"></span>\(H(z)=\displaystyle\frac{1}{L}\frac{1-z^{-L}}{1-z^{-1}}\tag{2}\label{TF}\)</p>



<p><span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span>with the difference equation,</p>



<p class="has-text-align-center">\(y(n) =y(n-1)+\displaystyle\frac{x(n)-x(n-L)}{L}\tag{3}\)</p>



<p><span class="" style="display:block;clear:both;height: 0px;padding-top: 10px;border-top-width:0px;border-bottom-width:0px;"></span>Notice that this implementation only requires <strong>one addition and one subtraction</strong> for any value of \(\small\textstyle L\). A further simplification (valid for both implementations) can be achieved in a pre-processing step prior to implementing the difference equation, i.e. scaling all input values by \(\small\textstyle L\). If \(\small\textstyle L\) is a power of two (e.g. 4,8,16,32..), this can be achieved by a simple binary shift right operation.</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<h3 class="wp-block-heading"><span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span><strong>Is it an IIR or actually an FIR?</strong></h3>



<p>Upon initial inspection of the transfer function of Eqn. \(\small\textstyle\eqref{TF}\), it appears that the efficient Moving average filter is an IIR filter. However, analysing the pole-zero plot of the filter (shown on the right for \(\small\textstyle L=8\)), we see that the <strong>pole at DC has been cancelled by a zero</strong>, and that the resulting filter is actually an FIR filter, with the same result as Eqn. \(\small\textstyle\eqref{FIRdef}\).</p>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<div class="wp-block-image"><figure class="alignright size-large"><img loading="lazy" decoding="async" width="357" height="357" src="https://www.advsolned.com/wp-content/uploads/2020/05/iir_ma_zp.png" alt="Moving average filter (MA filter). It appears that the efficient MA filter is an IIR filter. However, analysing the pole-zero plot of the filter, , we see that the pole at DC has been cancelled by a zero, and that the resulting filter is actually an FIR filter, with the same result as Eqn. " class="wp-image-12589" srcset="https://www.advsolned.com/wp-content/uploads/2020/05/iir_ma_zp.png 357w, https://www.advsolned.com/wp-content/uploads/2020/05/iir_ma_zp-300x300.png 300w, https://www.advsolned.com/wp-content/uploads/2020/05/iir_ma_zp-80x80.png 80w, https://www.advsolned.com/wp-content/uploads/2020/05/iir_ma_zp-36x36.png 36w, https://www.advsolned.com/wp-content/uploads/2020/05/iir_ma_zp-180x180.png 180w, https://www.advsolned.com/wp-content/uploads/2020/05/iir_ma_zp-120x120.png 120w" sizes="auto, (max-width: 357px) 100vw, 357px" /></figure></div>
</div>
</div>



<p>Notice also that the frequency spacing of the zeros (corresponding to the nulls in the frequency response) are at spaced at \(\small\textstyle\pm\frac{Fs}{L}\). This can be readily seen for this example, where an MA of length 8, sampled at \(\small\textstyle 500Hz\), results in a \(\small\textstyle\pm62.5Hz\) resolution.</p>



<p>As a final point, notice that the our efficient filter requires a delay line of length \(\small\textstyle L+1\), compared with the FIR delay line of length, \(\small\textstyle L\). However, this is a small price to pay for the computation advantage of a filter just requiring one addition and one subtraction. As such, the MA filter of Eqn. \(\small\textstyle\eqref{TF}\) presented herein is very attractive for very low power processors, such as the Arm Cortex-M0 that have been traditionally overlooked for DSP operations.</p>



<h2 class="wp-block-heading">Implementation </h2>



<p>The MA filter of Eqn. \(\small\textstyle\eqref{TF}\) may be implemented in <a style="color: #0000ff;" href="http://www.advsolned.com/asn_filter_designer/#live-math-scripting">ASN FilterScript</a> as follows:</p>



<p><pre class="brush: java; title: ; notranslate"> 
ClearH1;  // clear primary filter from cascade 
interface L = {2,32,2,4}; // interface variable definition 

Main() 
Num = {1,zeros(L-1),-1}; // define numerator coefficients 
Den = {1,-1}; // define denominator coefficients 
Gain = 1/L; // define gain 
</pre></p>



<span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span>
<p><a href="https://www.advsolned.com/asn_filter_designer/"><img loading="lazy" decoding="async" class="alignleft wp-image-3310" style="margin: 10px 80px 10px 20px;" src="http://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox.png" alt="" width="183" height="253" srcset="https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox.png 800w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-217x300.png 217w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-768x1062.png 768w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-745x1030.png 745w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-510x705.png 510w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-450x622.png 450w" sizes="auto, (max-width: 183px) 100vw, 183px" /></a></p>
<br><br>
<p style="text-align: left;"><a class="button" href="http://www.advsolned.com/request-form-asn-filter-designer-demo/">Download demo now</a></p>
<p><a class="button" href="http://www.advsolned.com/pricing-and-licencing/#Best_licence_forme">Licencing information</a></p>
		<div class="wpulike wpulike-default " ><div class="wp_ulike_general_class wp_ulike_is_not_liked"><button type="button"
					aria-label="Like Button"
					data-ulike-id="12573"
					data-ulike-nonce="2ed5a28322"
					data-ulike-type="post"
					data-ulike-template="wpulike-default"
					data-ulike-display-likers=""
					data-ulike-likers-style="popover"
					class="wp_ulike_btn wp_ulike_put_image wp_post_btn_12573"></button><span class="count-box wp_ulike_counter_up" data-ulike-counter-value="+7"></span>			</div></div>
	<p>The post <a rel="nofollow" href="https://www.advsolned.com/computationally-efficient-moving-average-filter-definition-and-implementation/">A computationally efficient moving average filter: Definition and implementation</a> appeared first on <a rel="nofollow" href="https://www.advsolned.com">ASN Home</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>The moving average filter</title>
		<link>https://www.advsolned.com/the-moving-average-filter/</link>
					<comments>https://www.advsolned.com/the-moving-average-filter/#respond</comments>
		
		<dc:creator><![CDATA[ASN consultancy team]]></dc:creator>
		<pubDate>Tue, 03 Jul 2018 15:16:36 +0000</pubDate>
				<category><![CDATA[ASN FilterScript]]></category>
		<category><![CDATA[digital filter]]></category>
		<category><![CDATA[FIR]]></category>
		<category><![CDATA[moving average]]></category>
		<category><![CDATA[moving average filter]]></category>
		<guid isPermaLink="false">http://www.advsolned.com/?p=5896</guid>

					<description><![CDATA[<p>A more computationally efficient implementation of the MA filter is discussed here. Further reading</p>
<p>The post <a rel="nofollow" href="https://www.advsolned.com/the-moving-average-filter/">The moving average filter</a> appeared first on <a rel="nofollow" href="https://www.advsolned.com">ASN Home</a>.</p>
]]></description>
										<content:encoded><![CDATA[<section class="av_textblock_section "  itemscope="itemscope" itemtype="https://schema.org/BlogPosting" itemprop="blogPost" ><div class='avia_textblock  '   itemprop="text" ><p>The moving average (MA) filter is perhaps one of the most widely used FIR filters due to its conceptual simplicity and ease of implementation. As seen in the diagram below, notice that the filter doesn&#8217;t require any multiplications, just additions and a delay line, making it very suitable for many extreme low-power embedded devices with basic computational capabilities.</p>
<p><a href="http://www.advsolned.com/wp-content/uploads/2018/07/firdirectformPNG.png"><img loading="lazy" decoding="async" class="aligncenter wp-image-5927 size-full" src="https://www.advsolned.com/wp-content/uploads/2018/07/firdirectformPNG.png" alt="fir direct form" width="670" height="217" srcset="https://www.advsolned.com/wp-content/uploads/2018/07/firdirectformPNG.png 670w, https://www.advsolned.com/wp-content/uploads/2018/07/firdirectformPNG-300x97.png 300w, https://www.advsolned.com/wp-content/uploads/2018/07/firdirectformPNG-450x146.png 450w" sizes="auto, (max-width: 670px) 100vw, 670px" /></a></p>
<p>However, despite its simplicity, the moving average filter is <strong>optimal for reducing random noise while retaining a sharp step response</strong>, making it a versatile building block for smart sensor signal processing applications.</p>
<p>A moving average filter of length \(L\) for an input signal \(x(n)\) may be defined as follows:</p>
<p style="text-align: center;">\(y(n)=\large{\frac{1}{L}}\normalsize{\sum\limits_{k=0}^{L-1}x(n-k)}\) for \(\normalsize{n=0,1,2,3&#8230;.}\)</p>
<p>Where, a simple rule of thumb states that<strong> the</strong> <strong>amount of</strong> <strong>noise reduction is equal to the square-root of the number of points in the average</strong>. For example, an MA of length 9 will result in a factor 3 noise reduction.</p>
<p style="text-align: center;"><a href="http://www.advsolned.com/wp-content/uploads/2018/07/mafilter.png"><img loading="lazy" decoding="async" class="aligncenter wp-image-5906 size-full" style="margin-top: 10px; margin-bottom: 30px;" src="https://www.advsolned.com/wp-content/uploads/2018/07/mafilter.png" alt="moving average filter" width="438" height="433" srcset="https://www.advsolned.com/wp-content/uploads/2018/07/mafilter.png 438w, https://www.advsolned.com/wp-content/uploads/2018/07/mafilter-80x80.png 80w, https://www.advsolned.com/wp-content/uploads/2018/07/mafilter-300x297.png 300w, https://www.advsolned.com/wp-content/uploads/2018/07/mafilter-36x36.png 36w, https://www.advsolned.com/wp-content/uploads/2018/07/mafilter-120x120.png 120w" sizes="auto, (max-width: 438px) 100vw, 438px" /></a><em>Frequency response of an MA filter of length 9. Notice the poor stopband attentuation at around -20dB.</em></p>
<h2>Advantages</h2>
<ul>
<li>Most commonly used digital lowpass filter.</li>
<li>Optimal for reducing random noise while retaining a sharp step response.</li>
<li>Good smoother (time domain).</li>
<li>Unity valued filter coefficients, no MAC (multiply and accumulate) operations required.</li>
<li>Conceptually simple to implement.</li>
</ul>
<h2><span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span></h2>
<h2>Disadvantages</h2>
<ul>
<li>Inflexible frequency response: nudging a conjugate zero pair results in non-unity coefficients.</li>
<li>Poor lowpass filter (frequency domain): slow roll-off and terrible stopband attenuation characteristics.</li>
</ul>
<h2><span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span></h2>
<h2>Implementation</h2>
<p>The MA filter may be implemented in <span style="color: #0000ff;"><a style="color: #0000ff;" href="http://www.advsolned.com/asn_filter_designer/#live-math-scripting">ASN FilterScript</a></span> as follows:</p>
</div></section>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
ClearH1;  // clear primary filter from cascade
Main();
Hd=movaver(8,"symbolic");  // design an 8th order MA
Num = getnum(Hd);   // define numerator coefficients
Den = {1};          // define denominator coefficients
Gain = getgain(Hd); // define gain
</pre></div>


<p>A more computationally efficient implementation of the MA filter is discussed <a style="color: #0000ff;" href="https://www.advsolned.com/computationally-efficient-moving-average-filters-definitions-and-implementations/">here.</a></p>


<span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span>



<h2 class="wp-block-heading">Further reading</h2>



<ul class="wp-block-list">
<li>Understanding Digital Signal Processing, Chapter 5, R. G. Lyons</li>



<li>The Scientist and Engineer&#8217;s Guide to Digital Signal Processing, Chapter 15, Steven W. Smith</li>
</ul>


<p><span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span><a href="http://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox.png"><img loading="lazy" decoding="async" class="alignleft wp-image-3310" style="margin: 10px 80px 10px 20px;" src="http://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox.png" alt="" width="183" height="253" srcset="https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox.png 800w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-217x300.png 217w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-768x1062.png 768w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-745x1030.png 745w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-510x705.png 510w, https://www.advsolned.com/wp-content/uploads/2018/02/ASNFDbox-450x622.png 450w" sizes="auto, (max-width: 183px) 100vw, 183px" /></a></p>
<p style="text-align: left;"><a class="button" href="http://www.advsolned.com/request-form-asn-filter-designer-demo/">Download demo now</a></p>
<p><a class="button" href="http://www.advsolned.com/pricing-and-licencing/#Best_licence_forme">Licencing information</a><span class="" style="display:block;clear:both;height: 0px;padding-top: 20px;border-top-width:0px;border-bottom-width:0px;"></span></p>
		<div class="wpulike wpulike-default " ><div class="wp_ulike_general_class wp_ulike_is_not_liked"><button type="button"
					aria-label="Like Button"
					data-ulike-id="5896"
					data-ulike-nonce="1faab5e881"
					data-ulike-type="post"
					data-ulike-template="wpulike-default"
					data-ulike-display-likers=""
					data-ulike-likers-style="popover"
					class="wp_ulike_btn wp_ulike_put_image wp_post_btn_5896"></button><span class="count-box wp_ulike_counter_up" data-ulike-counter-value="+4"></span>			</div></div>
	<p>The post <a rel="nofollow" href="https://www.advsolned.com/the-moving-average-filter/">The moving average filter</a> appeared first on <a rel="nofollow" href="https://www.advsolned.com">ASN Home</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.advsolned.com/the-moving-average-filter/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
