ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Smoothing or Antialiasing
Posted by Norm on Mar-07-2018 03:49
Attachments:
Hi,

I know that exist many methods to antialiasing or smoothing a line !

Sometime we can use a first, a second or both !

Because data collected with a temperature sensor never really precise it hard to draw a smooth line !


Question 1 about smoothing:
- Does exist a smooth function on VB6 to reduce a large step on array to create a second array as photoshop use after applying antialias function ?

I tried to get a temperatre each 20 secondes, add this result to 7 previous results, and divide this by 8 and after, add to array , but this is not really satisfying !
Code similar as this code:
////////////////////////////////////////////////////////////////////////
Dim t_now as integer
Dim t_total as integer
Dim t(1to7) as integer
Dim t_result as integer

t_total = t_now
for x = 1 to 7
  t_total = t_total  +  t(x)
next x
t_result = t_total / 8
////////////////////////////////////////////////////////////////////////



Question 2 about antialiasing:
- Is it possible with :
Call c.setAntiAlias(True, 1))
to adjust intensity or grade ?


Thanks
Smoothing.jpg

  Re: Smoothing or Antialiasing
Posted by Peter Kwan on Mar-07-2018 13:53
Hi Norm,

There are two types of "smoothing":

(a) ChartDirector will connect the data points with straight lines or spline curves. Antialias is a method to draw the connecting lines or curves so that it looks smooth. Note that with this method, ChartDirector will not change or move the data points. It only affects the lines that connects the data points. So if the original data points fluctuate up and down (have "noise"), the line will also fluctuation up and down because it must join the data points.

It is suggested you always enable antialias. (This is the default.) The antialias can either be enabled or disabled. There is no "intensity" to configure.

(b) "Filtering" the data points. This is to change the data points. There are many methods to change the data points. The best method depends on the nature of your data.

The method in your message (add a value with the 7 previous results and then divide by 8) is called the "simple moving average" method, which is widely use in financial charts. Another simple method is the exponential moving average, which is:

' Compute t_result using the previous t_result (not previous data) and the current value
t_result = 0.5 * t_now + 0.5 * previous_t_result

ChartDirector has a number of built-in filtering functions, including the above simple moving average, exponential moving average, weighted moving average, moving median, and some more complicated ones like LOWESS. May be you can try them to see if it works in your case. See:

http://www.advsofteng.com/doc/cdcom.htm#ArrayMath.htm

http://www.advsofteng.com/doc/cdcom.htm#curvefitting.htm

For example, to compute the exponential moving average, you can use:

Dim myData(sampleSize - 1) As Double
Dim filteredData() As Double

' You can try to change the filter 0.5 to 0.2 or some other values. The smaller the
' value, the smoother is the curve.
filteredData = cd.ArrayMath(myData).expAvg(0.5).result()

Hope this can help.

Regards
Peter Kwan

  Re: Smoothing or Antialiasing
Posted by Norm on Mar-07-2018 15:19
Attachments:
Hi Peter,

I just tried fastly this:


Call layer.addDataSet(dataSeries1, 64278)
or
Call layer.addDataSet(cd.ArrayMath(dataSeries1).expAvg(0.1).result(), 64278)
or
Call layer.addDataSet(cd.ArrayMath(dataSeries1).expAvg(0.5).result(), 64278)

and here a result :

Each .PNG is not at the good position !

Tomorrow I will try slowly your method exponential !

Thanks
ArrayMath.jpg

  Re: Smoothing or Antialiasing
Posted by Peter Kwan on Mar-07-2018 17:23
Hi Norm,

Note that all moving average method will have the effect of "delaying" the line (that is, the line will appear to move to the right). For example, in your original message, you mentioned you "add the value to 7 previous results and then divide by 8". This means the value is the average of the previous 8 values. This has the effect of delaying the line by 3.5 samples, as the average of the previous 8 samples will be approximately the one in the middle (that is, between the 4th and 5th samples).

For exponential average, the shifting is approximate  1/multiplier - 1. So if you use 0.1 as the multiplier, the shifting will be 1 / 0.1 - 1 = 9 samples.

Most smoothing method using current and previous data will have the same effect of "delaying" the line, as the current value is modified somewhat with older values.

To avoid the delay, some people will shift the line to the left to compensate. For example, the developer may shift the line to the left by 9 samples to compensate. However, it means the line will not display the last 9 points as they are shifted to the left. It is like:

Dim smoothedData() As Double
smoothedData = cd.ArrayMath(dataSeries1).expAvg(0.1).shift(-9).result()

Regards
Peter Kwan

  Re: Smoothing or Antialiasing
Posted by Norm on Mar-07-2018 19:41
Peter Kwan wrote:

Hi Norm,

Note that all moving average method will have the effect of "delaying" the line (that is, the line will appear to move to the right). For example, in your original message, you mentioned you "add the value to 7 previous results and then divide by 8". This means the value is the average of the previous 8 values. This has the effect of delaying the line by 3.5 samples, as the average of the previous 8 samples will be approximately the one in the middle (that is, between the 4th and 5th samples).

Peter,

Sorry,  I did'nt to be precise !!!

I add theses 8 values of temperature and then divide by 8, later'  I add this value to my array in same time than all others array !

In others words, I receiver thes 8 data samples from sensor each 2.4 secondes, when i receive these 8 samples I divide them by 8. After (One time by 19 secondes) I add this result value to Array in same time of each others array with once timestamps array  !

Note as your suggestion I modified my method and now use once timestamps array, and all have a same sampleSize value.


`/////////////////////////////////////////////////////////////////////////
Private Const sampleSize = 4460 '*********For 86400/19.7************

Private dataSeries1(sampleSize - 1)
Private timeStamps(sampleSize - 1)

Private dataSeriesDefrostToléré(sampleSize - 1)
Private dataSeriesSouhait(sampleSize - 1)
Private dataSeriesRouge(sampleSize - 1)
Private dataSeriesVert(sampleSize - 1)
Private dataSeriesBleu(sampleSize - 1)
Private dataSeriesExtérieur(sampleSize - 1)
Private dataSeriesExtérieurText(sampleSize - 1)
`/////////////////////////////////////////////////////////////////////////


Today I will try your last solution !

  Re: Smoothing or Antialiasing
Posted by Norm on Mar-09-2018 04:47
Peter Kwan wrote:

However, it means the line will not display the last 9 points as they are shifted to the left. It is like:

Dim smoothedData() As Double
smoothedData = cd.ArrayMath(dataSeries1).expAvg(0.1).shift(-9).result()


Hi Peter

Just to tell you that I tried and I obtained this error each time:
-2147417848(80010108) Error Automation !

If I use a value between 0 to 9 it work fine, but on bad side:
smoothedData = cd.ArrayMath(dataSeries1).expAvg(0.1).shift(-9).result()

If I use a negative value (as -1 or -9) I obtain this error code !

Thanks !

  Re: Smoothing or Antialiasing
Posted by Peter Kwan on Mar-09-2018 15:35
Hi Norm,

Sorry for this problem. I found out the correct method should be to "trim" with a positive number. It is like:

smoothedData = cd.ArrayMath(dataSeries1).expAvg(0.1).trim(9).result()

Hope this can help.

Regards
Peter Kwan