Moving average filter

I have a problem that I will describe:
I am receiving a continous stream of data,  in the form of an array.
however I want to do some processing on a smaller subset of the array, and obtain similar results to as if i was using the whole array.
the processing is:
1) recevie data: 10 points
2) take mean of these 10 points
3) divide array/mean
and more processing which is not important.
the original array can have up to thousands of points. I know I can use a moving average, which i have done. so the average of the points 1:10 and 11:20 is the same as points 1:20.
however the problem is the third step, dividing each data by the mean.
in the end i want to plot the subset outputs, and i want it to be similar to processing the enitre data set.
Im not an expert in filters and all, but is there a good way to do this?
because the result i am getting now is quite choppy and unsmooth.
thanks!

If you are averaging data, and it is choppy, there are likely multiple things wrong.  The data is only going to be as good as the the sensor can measure.  And if you are getting crappy data at the sensor, then software should not be the one to fix it.  Fix the environment so the sensor gets the best data it can before software has to be involved.
That being said some times software filtering is needed and that's okay.  Try to post what an example of your code.  It is hard to understand what you are trying to do.  Do you want a moving window of data to average?  Or are you trying to understample where 10 values are now 1?
Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

Similar Messages

  • 8 point moving average filter

    How to implement an 8 point moving averge filter for a sample size of 1000?

    There are many ways to do this.  One of my favorite is to just use an FIR Filter.  But the most straight forward way is to use the Mean Pt By Pt VI inside of a FOR loop.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Filter slope of multipass moving average

    Hey guys,
    here is a picture of the frequency response of a multipass moving average filter. The number of stages tells you how often the data is passed through the filter.
    As I am interested in the different slope behaviours of the different stages I wanted to ask you how to determine the slope.
    Do I take the envelope to calculate the roll off (=slope) of the filter?
    Actually it should be 1 pass (= 1 stage) is 20dB/Dekade, 2 passes = 40dB/dekade and so on...
    I hope you can help me.
    Kind regards
    Slev1n
     

    The equation for the envelope of the frequency response can be obtained by noting that the absolute value of the numerator sin(wM/2) varies between 0 and 1.  So its upper edge is 1, and you can replace sin(wM/2) with unity, to find the upper envelope of H(w). (This envelope only applies for wM/2>Pi, which is the first zero of the numerator.)  Thus you get
    envelope of H(w)= 1/[M*sin(w/2)]^Mp. 
    Note also that when w/2<<1, you can use the approximation sinx ~= x:
    envelope of H(w) ~= 1/[M*w/2]^Mp
    Therefore the envelope of H(w) is proportional to 1/w, 1/w^2, 1/w^3 when Mp=1,2,3.  Now you see why the envelope's slope is 20, 40, 60 dB/decade when Mp=1,2,3.  (Apply the equation for gain in dB, when w changes by 10X.)  The approximation above is decent only when 2Pi/M < w << 1.  If the number of moving average points, M, is small, for example a 5 point moving average, then there will be no frequencies which satisfy the preceding inequality for w.  But you chose M=500, so there is a range of frequencies where the 20 dB/decade rolloff is apparent.  If you look carefully at your plot, you will see that the frequency response starts to deviate from 20 dB/decade as frequency f (=w/2Pi) approaches 0.5 (the Nyquist frequency).  This is because you are getting into the range where sin(x)~=x is not accurate.
    Final comment: Since you apparently care about the frequency response properties of your lowpass filter, you might want to use a different filter.  Other FIR and IIR filters have flatter passbands, sharper rolloff around the cutoff frequency, and lower sidebands.

  • Exponential Moving Average - EMA - in PowerPivot

    Hello All
    We´re having a challenge trying to put the [20] (trading days) Exponential Moving Average (EMA) in our data model in PowerPivot.
    Here is the EMA formula and sample spreadsheet:
    http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_averages
    Pasted the formula here for convenience:
    SMA (simple moving average): [10] period sum / [10]
    Multiplier: 2 / ([Time period] + 1) )
    EMA: {Close - EMA(previous day)} x multiplier + EMA(previous day).
    Sample spreadsheet
    http://stockcharts.com/school/data/media/chart_school/technical_indicators_and_overlays/moving_averages/cs-movavg.xls
    In our model the fact table have these columns:
    Symbol Date Open High Low Close Volume
    And in the Calendar table we´ve identified the trading days (Calendar[TradingDayNumber]) as 1 so we can count them back.
    We want the EMA calculated field in a pivot table like this
    Filter context: a date selected on Calendar[FullDate]
    Row context: FactTable[Symbol]
    Values: FactTable[Close]
        FactTable[EMA 20D] >> Missing
    So far we got these calculated fields:
    Period
    =20
    Ema Multiplier
    =2 / ([Period] + 1)
    Average 20D CLOSE
    =IF([Sum of CLOSE]=BLANK(),BLANK(),(CALCULATE(AVERAGE(FactTable[CLOSE]),FILTER(ALL(Calendar),Calendar[TradingDayNumber]<=MAX(Calendar[TradingDayNumber]) && Calendar[TradingDayNumber]>MAX(Calendar[TradingDayNumber])-[Period]))))
    But it looks like the EMA formula contains a self reference from previous values, and it also starts from a SMA (Average 20D CLOSE) value.
    How can we do it?
    Thanks in advance. I highly appreciate your support.

    Nico,
    Is this still an issue?
    Thanks!
    Ed Price, Azure & Power BI Customer Program Manager (Blog,
    Small Basic,
    Wiki Ninjas,
    Wiki)
    Answer an interesting question?
    Create a wiki article about it!

  • Problem with moving average

    I have to create a report which displays rolling average of revenue.
    The report contains two columns week and avg revenue. I have to display only ten weeks from the current week.
    For each week the revenue should be calculated as follows;
    weeks     actual revenue     Avg revenue
    1     10          10     
    2     20          (10+20)/2
    3     30          (10+20+30)/3     
    4     40          (10+20+30+40)/4
    5     50          (20+30+40+50)/4
    6     60          (30+40+50+60)/4
    (current week-10 weeks)
    current week
    I have used Mavg(actual revenue, 4) to calculate avg revenue.
    I am getting the correct values. However if I apply a filter say weeks between current week and (current week-10 weeks), I am facing a problem.
    My (current week-10 weeks) is now showing avg revenue as 10 which is my actual revenue amount.
    But i would like to show the revnue amount as an avgerage of (current week-10 weeks) and previous three weeks.
    The filter to limit the number of weeks is applied before calculating the moving average. Is there anyway to calculate the moving average first and then apply the week filter to report.
    Pls help me solving this.
    Thanks

    Do this:
    Have the measure as :
    case when Periods."Weekdate" > TIMESTAMPADD(SQL_TSI_WEEK, -10 , CURRENT_DATE) then MAVG ("Sales Measures".Units, 4) else 999999999 end
    And then apply filter on the above measure column as :
    Case when Periods.Weekdate > TIMESTAM... ' is not equal to / is not in 999999999
    Let us know how it goes.
    PS : To prevent runaway query, you may want filter it further by Periods."Weekdate" > TIMESTAMPADD(SQL_TSI_WEEK, -15 , CURRENT_DATE)

  • Moving Averages and drilling

    Hey everyone,
    I've got the following scenario going on:
    A pivot table that has a product hierarchy and quantity sold along with a 5,10 and 20 day moving average. At the base level of the hierarchy (i.e. you haven't drilled into anything yet), the moving averages work correctly.
    But once you drill into the different product levels, the moving averages immediately stop making any sense. It's almost as if they are precomputed in some other order and then reorganized into a order that no longer makes mathematical sense.
    Does anyone know why this happens?
    Can anyone recommend how to get it to function as I would expect it to?
    thanks everyone!
    -Joe

    Serhan,
    If you are just aiming to smooth out your signal and reduce noise, than an FIR filter would work fine, but it sounds like you are trying to achieve an exact moving average.  Unfortunately, there are entire textbooks on filter design and getting the filter to accomplish that with great accuracy would be a feat.  It is true that the moving average is a form of the FIR filter.
    I had some old code that took the running average of 100 samples in SE, but I'll have to look for it when I get to work tomorrow.  I'll post again when Ifind it.
    I don't have any moving average VI's handy, but that would probably be the easiest way to accomplish this. Maybe someone can distribute their VI to Serhan?
    Rob K
    Measurements Mechanical Engineer (C-Series, USB X-Series)
    National Instruments
    CompactRIO Developers Guide
    CompactRIO Out of the Box Video

  • Moving Average in a Report Section

    Hi there,
    I am displaying a measure in a chart that has three data points. The measure is 4 day moving average of a metric. Let's say my query brings back the last 6 days, which enables me to calculate the 4 day moving average for days 4, 5, and 6.
    I use the Previous() function to calculate the moving average:
    =(metric + Previous(metric) + Previous(Previous(metric)) + Previous(Previous(Previous(metric)))) / 4
    I don't want to show days 1, 2, and 3, so I filter these out of the chart and wrap a NoFilter() around the moving average. Everything is good so far.
    The problem arises when I section on a dimension. I can't seem to get the correct values unless I display all 6 data points in each section. NoFilter() doesn't seem to work.
    Has anyone run into this before? Does there exist a solution for this?
    Any help would be greatly appreciated.
    Thanks,
    Allan

    I figured it out:
    NoFilter([[4wkMvAvgMeasure]]) ForEach ([[day]]) In Section
    Thanks,
    Allan

  • An averaging filter that tightens depending on slope??

    Hello all,
    I have an application where a variable (DBL scalar) is shown in a graph to be bouncing above and below the target setpoint @ approx 1-5sec intervals.  In other words, if the setpoint is 1500lbs, the variable bounces between 1250 and 1750lbs, which is +/-250lbs and it does this bouncing @ approx 0.2 to 1 Hz.  The customer wants me to show the average instead of the real-time.... so the graph would show a horizontal line @ 1500lbs in the above example.  They dont want to see the ripple.  So, I pulled out the "Mean PtbyPt.vi" function and as long as I increase the sample length adequately it does exactly what my customer wants.  Heres my problem...  When the process starts or ends and the weight returns to zero lbs, the mean is very, very slow to respond.
    Is there a way to make it "come into" and "out of" the target zone quickly, but filter the heck out of it when it is in the zone?  I am thinking of making my own function that would look @ the slope.  If the slope is less than a certain threshold, then the "Mean PtbyPt" sample length is long, but if the slope is greater than a certain threshold, then the "Mean PtbyPt" sample length is short.  Since I am just learning labview now and I have never used any of the filters or signal processing functions before, I feel like I might be recreating something that already exists?  Would any of these help me?  FIR, IIR, Chebyshev, Butterworth?  I am glad to learn all of these things, but to accomplish my task efficiently without chasing my tail, can anyone point me in a helpful direction?
    Thank you very much for any input.
    respectfully,
    frenchy

    Hai,
    For the task like reducing jitter moving average serves good.  It's takes "number of points" to average.  A simple example is if you had a data set with 100 data points, the first value of the moving average might be the arithmetic mean (one simple type of average) of data points 1 through 25. The next value would be this simple average of data points 2 through 26, and so forth, until the final value, which would be the same simple average of data points 76 through 100.
    The VI can be found in the following link: http://zone.ni.com/devzone/cda/epd/p/id/82
    Hope this helps.
    With regards,
    JK
    (Certified LabVIEW Developer)
    Give Kudos for Good Answers, and Mark it a solution if your problem is solved.

  • Moving Averages in Labview SignalExpress

    Hi everyone,
    I am measuring power consumption values from a PC system at 25k samples/sec and looking for a way to calculate the 1-sec and 5-sec moving averages via Labview SignalExpress (Unfortunately I don't have Labview to custom-implement this). One person suggested using FIR low pass filter instead, but I am not quite sure what values I need to set for "number of taps" and "cutoff frequency" values to have it act like a 1-second and 5-second moving average. Any suggestions here?
    Also, does anyone have a .VI from Labview for a moving average functionality, which I can use in my Labview SignalExpress setup?
    Thanks,
    --Serhan 

    Serhan,
    If you are just aiming to smooth out your signal and reduce noise, than an FIR filter would work fine, but it sounds like you are trying to achieve an exact moving average.  Unfortunately, there are entire textbooks on filter design and getting the filter to accomplish that with great accuracy would be a feat.  It is true that the moving average is a form of the FIR filter.
    I had some old code that took the running average of 100 samples in SE, but I'll have to look for it when I get to work tomorrow.  I'll post again when Ifind it.
    I don't have any moving average VI's handy, but that would probably be the easiest way to accomplish this. Maybe someone can distribute their VI to Serhan?
    Rob K
    Measurements Mechanical Engineer (C-Series, USB X-Series)
    National Instruments
    CompactRIO Developers Guide
    CompactRIO Out of the Box Video

  • SSRS 2008 Column Chart with Calculated Series (moving average) "formula error - there are not enough data points for the period" error

    I have a simple column chart grouping on 1 value on the category axis.  For simplicity's sake, we are plotting $ amounts grouping by Month on the category axis.  I right click on the data series and choose "Add calculated series...".  I choose moving average.  I want to move the average over at least 2 periods.
    When I run the report, I get the error "Formula error - there are not enough data points for the period".  The way the report is, I never have a guaranteed number of categories (there could be one or there could be 5).  When there is 2 or more, the chart renders fine, however, when there is only 1 value, instead of suppressing the moving average line, I get that error and the chart shows nothing.
    I don't think this is entirely acceptable for our end users.  At a minimum, I would think the moving average line would be suppressed instead of hiding the entire chart.  Does anyone know of any workarounds or do I have to enter another ms. connect bug/design consideration.
    Thank you,
    Dan

    I was having the same error while trying to plot a moving average across 7 days. The work around I found was rather simple.
    If you right click your report in the solution explorer and select "View Code" it will give you the underlying XML of the report. Find the entry for the value of your calculated series and enter a formula to dynamically create your periods.
    <ChartFormulaParameter Name="Period">
                      <Value>=IIf(Count(Fields!Calls.Value) >= 7 ,7, (Count(Fields!Calls.Value)))</Value>
    </ChartFormulaParameter>
    What I'm doing here is getting the row count of records returned in the chart. If the returned rows are greater than or equal to 7 (The amount of days I want the average) it will set the points to 7. If not, it will set the number to the amount of returned rows. So far this has worked great. I'm probably going to add more code to handle no records returned although in my case that shouldn't happen but, you never know.
    A side note:
    If you open the calculated series properties in the designer, you will notice the number of periods is set to "0". If you change this it will overwrite your custom formula in the XML.

  • Moving average price in case of goods receipt with free of charge

    Hello everyone,
    Need some inputs......
    Sometimes we receive materials from suppliers free of charge (e.g. warranty replacement) u2013 moving average goes down u2013 worst case 0,01 EUR/piece. This causes problems in government reporting and export documentation EX1 and clearance/pro-forma invoice) for deliveries to field engineers (Order type ZIS1, ZIS3 u2013 item cat. ZICA), because moving average price is used for the values in government reporting and on the invoices. In government reporting and on invoices we need to state a true value of the part.On the other hand, the value warehouse stock is depending on the moving average cost as well.Could you please let me know, how to handle such receipts from the supplier to have a correct stock value and correct values on invoices and government reporting?
    Thanks
    Deepthi...

    Hello Deepthi,
    It depends on your company policy. If you want to valuate the material along with the material purchased handled in moving average price, free consignment will bring down the MAP for the material.
    In that case, you can revaluate the material to the original price in MR21 transaction.
    If you are not going to handle the materials received free of charge along with the purchased material, you can go with another material code, with non valuated material type.
    But i guess, no company will be asking for another material code. So go for revaluation after the receipt of free consignment.
    Regards

  • Average filter but the image is gray and not color RGB

    Hi,
    i use this code for an average filter 3x3, the result is the image whit average but gray and not RGB color.... why??
    thanks in advance
        public void Average()
            int values[]=null;
            int input2d[] = new int [image.getWidth()*image.getHeight()];
            int [][] output2d=new int [image.getWidth()][image.getHeight()];
            image.getRaster().getSamples(0, 0, image.getWidth(), image.getHeight(),0,input2d);
            for(int y=0; y < image.getHeight(); y++)
                for(int x=0; x < image.getWidth(); x++)
                    int count = 0;
                    int average=0;
              values = new int[5*5];
                    for(int s = 0; s < 5; s++)
                        for(int r = 0; r < 5; r++)
                            try
                                values[count] = input2d[(y-2+r)*image.getWidth()+(x-2+s)];
                                count++;
                            catch(ArrayIndexOutOfBoundsException e){ }
                    //trovo il valore medio dell'intorno 5x5
                    for (int temp=0; temp<count; temp++)
                        average+=values[temp];
                    int valpixel=average/count;
                    output2d[x][y]=valpixel;
            image2 = new BufferedImage(image.getWidth(),image.getHeight(), BufferedImage.TYPE_INT_RGB);
            image2.getGraphics().drawImage(image,0,0,null);
            for(int y=0; y < image.getHeight(); y++)
                for(int x=0; x < image.getWidth(); x++)
                    image2.getRaster().setSample(x, y, 0, output2d[x][y] );// componente R
                    image2.getRaster().setSample(x, y, 1, output2d[x][y] );// componente G
                    image2.getRaster().setSample(x, y, 2, output2d[x][y] );// componente B
        }

    Can hel me please!!!

  • Moving Average Price for Sales stock and Project stock of a material

    Hiya Gurus,
                     I am developing a report to display inventory details. My requirement is that I have to display the Moving average price of a material for all Valuation type. I also need to display the Moving average price if a material has got Project stock or Sales stock.
                     In MBEW table I can get the Valuation type and its Moving average price, but how can I find the moving average price for the same material if it has got Sales stock and project stock. Please let me know the table and field where I could get the relevant data.
                    Kindly help me on this, it would be deeply appreciated.
    Cheers,
    ZIa

    Hi
    can you look at tables
    EBEW                             Sales Order Stock Valuation
    QBEW                             Project Stock Valuation
    Nat

  • SSRS 2008 R2 - Add moving average to column group

    I have a column group of dollar amounts.  The row is a year/month.  I would like to add a moving average column to the right of the last 6 months.  My SQL Server data source is already complex enough and I'd really prefer not to add a column
    there.  Is there anything I can do within the report itself?  Some way to reference the previous records in a matrix?
    Thank you!

    Hi mateoc15,
    According to your description, you have a matrix in your report. Now you want to calculate the average value of last 6 month. Right?
    In Reporting Service, we can put custom code into report to deal with complicated logic. Add one more column/row inside of group and call the functions defined in custom code. For your requirement we modified Robert’s code to achieve your goal. We tested
    your case in our local environment with sample data. Here are steps and screenshots for your reference:
    Put the custom code into report:
    Private queueLength As Integer = 6
    Private queueSum As Double = 0
    Private queueFull As Boolean = False
    Private idChange As String=""
    Dim queue As New System.Collections.Generic.Queue(Of Integer)
    Public Function CumulativeQueue(ByVal currentValue As Integer,id As String) As Object
    Dim removedValue As Double = 0
    If idChange <> id then
            ClearQueue()
                    idChange = id
                    queueSum = 0
                    queueFull = False
                    CumulativeQueue(currentValue,id)
    Else
                    If queue.Count >= queueLength Then
                                    removedValue = queue.Dequeue()
                    End If
                    queueSum += currentValue
                    queueSum -= removedValue
                    queue.Enqueue(currentValue)
                    If queue.Count < queueLength Then
                    Return Nothing
                    ElseIf queue.Count = queueLength And queueFull = False Then
                    queueFull = True
                    Return queueSum / queueLength
                    Else
                    Return (queueSum) / queueLength
                    End If
    End If
    End Function
    public function ClearQueue()
    Dim i as Integer
    Dim n as Integer = Queue.Count-1
    for i=n To 0 Step-1
                    queue.Dequeue()
    next i
    End function
    Add one more row inside of group, call the function defined in custom code.
    Save and preview. It looks like below:
    Reference:
    Moving or rolling average, how to?
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou (Pactera)

  • Moving average price

    Hai all MM gurus,
    While invoice posting, system is showing the error message " Moving average price is negative for the material ".
    How to post the invoice .

    Hi,
    In the material master the moving average price is negative.
    Please use MR21 and change price so that the MAP will be
    postitive then you can verify  the invoice
    G.Ganesh Kumar

Maybe you are looking for

  • If i never back up my ipad on itunes or icloud how can i have my files back?

    Pleas help

  • Rman archivelog backup fails with rman-03002,ora-19563

    Hi, D:\ Oracle- -\BIN\RMAN TARGET / NOCATALOG RMAN> backup archivelog all; RMAN-03002: Error with backup command on 06-25-2013 ORA-19563: Header-Validation is not successful.     fails with the given errors. 11.2.0.2 PROD DB on Windows Server 2008  R

  • Can I make Folders in Mail?

    Can I make Folders in Mail so I can store some?  Right now they all scroll off site in no time and I can't read them again.  Help!

  • A keyboard shortcut seems to crash CS5

    Since beginning my trial of CS5 I have been crashing under certain circumstances. I may have isolated the problem, but I wonder if anyone else has had this problem or can reproduce it. FYI. I am using a brand new 17" Macbook Pro w/ 8 GB or ram. I als

  • Power Management Issue

    Hey, I got this issue with my laptop: If I start it up when its unplugged from the power supply, the screen does not start in a "shaded" mode - meaning, the screen keeps spending power as if its connected to the power supply. Only if I connect my AC