DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Weighted Reduction of Datapoints

Hey Community,

 

im looking for a solution to my Problem:

 

In a experiment i record a pressure trace within 200 ms, recording 50000 points.

 

But, for further processing i need to reduce the Data to 250 Points

 

I've reduced the noise allready and now have a rather smooth measurement.

 

But in the Experiment i have one very important peak, which MAX value is very important.

If i now simply reduce by averaging over all, i change the actual peak.

 

So what i need is somethin like a weighted reduciton in respect of the MAX Peak

 

So something like this:

If Point within +- 10% of MAX peak: Average only 2 points

If Point between +-10% and +- 20 % average 5 points

If Not Average 50 points

 

Ideally as a VB script.

 

Thanks

 

rene

 

0 Kudos
Message 1 of 2
(3,385 Views)

Hi Rene,

 

I set up a little demo on how to do this. This example generates a sinus and resamples the sinus. For values greater than 0.9 the resampling resamples with factor 2 and in all other areas the resampling is done with 1:5.

 

 

Option Explicit

Dim strChnTime, strChnTimeHighRes, strChnTimeLowRes
Dim oChnTime, oChnSig, oChnSigHighRes, oChnSigLowRes, oChnTimeHighRes, oChnTimeLowRes
Dim oChnSigResampled, oChnTimeResampled
Dim sFormula, aSymbol(3), aValues(3)

Const HighResFactor = 2
Const LowResFactor = 5

Call Data.Root.Clear()
strChnTime = ChnLinGenImp("Time",1000,0,1,"")
strChnTimeHighRes = ChnLinGenImp("timeHighRes", 1000/HighResFactor, 0, 1*HighResFactor,"")
strChnTimeLowRes = ChnLinGenImp("timeLowRes",  1000/LowResFactor,  0, 1*LowResFactor,"")
Set oChnTime = Data.GetChannel(strChnTime)
Set oChnTimeHighRes = Data.GetChannel(strChnTimeHighRes)
Set oChnTimeLowRes = Data.GetChannel(strChnTimeLowRes)

Set oChnSig = Data.Root.ActiveChannelGroup.Channels.Add("Signal",DataTypeChnFloat64)
Set oChnSigHighRes = Data.Root.ActiveChannelGroup.Channels.Add("SignalHighRes",DataTypeChnFloat64)
Set oChnSigLowRes = Data.Root.ActiveChannelGroup.Channels.Add("SignalLowRes",DataTypeChnFloat64)

sFormula = "A = sin( T/100 )"
aSymbol(1) = "T"
aSymbol(2) = "A"
Set aValues(1) = oChnTime
Set aValues(2) = oChnSig
Call Calculate (sFormula, aSymbol, aValues)
Call ChnCharacterAll()

sFormula = "H = A + CTNV( A < 0.9 * PEAK)"
aSymbol(1) = "A"
aSymbol(2) = "H"
aSymbol(3) = "PEAK"
Set aValues(1) = oChnSig
Set aValues(2) = oChnSigHighRes
aValues(3) = oChnSig.Properties("maximum").Value
Call Calculate (sFormula, aSymbol, aValues)

sFormula = "L = A + CTNV( A >= 0.9 * PEAK)"
aSymbol(1) = "A"
aSymbol(2) = "L"
aSymbol(3) = "PEAK"
Set aValues(1) = oChnSig
Set aValues(2) = oChnSigLowRes
aValues(3) = oChnSig.Properties("maximum").Value
Call Calculate (sFormula, aSymbol, aValues)


Call ChnResampleChnBased(Ref(oChnTime),Ref(oChnSigHighRes),Ref(oChnTimeHighRes),Ref(oChnSigHighRes),"Automatic",0,0)
Call ChnResampleChnBased(Ref(oChnTime),Ref(oChnSigLowRes),Ref(oChnTimeLowRes),Ref(oChnSigLowRes),"Automatic",0,0)

Call ChnValExpand(Ref(oChnTimeLowRes))
Call ChnValExpand(Ref(oChnTimeHighRes))

Call ChnNovHandle(Ref(oChnSigHighRes),Ref(oChnTimeHighRes),"Delete","X",True,False)
Call ChnNovHandle(Ref(oChnSigLowRes),Ref(oChnTimeLowRes),"Delete","X",True,False)

Call ChnConcat(Ref(oChnSigHighRes),Ref(oChnSigLowRes))
Call ChnConcat(Ref(oChnTimeHighRes),Ref(oChnTimeLowRes))

Call ChnMultipleSort(Ref(oChnTimeLowRes),Ref(oChnSigLowRes),False,False)

Set oChnTimeResampled = Data.GetChannel("SortedX")
Set oChnSigResampled = Data.GetChannel("SortedY1")


oChnTimeResampled.Name = "Time (resampled)"
oChnSigResampled.Name = "Signal (resampled)"

Call ChnDel(Ref(oChnTimeHighRes))
Call ChnDel(Ref(oChnTimeLowRes))
Call ChnDel(Ref(oChnSigHighRes))
Call ChnDel(Ref(oChnSigLowRes))



Function Ref(oChn)
  Ref = oChn.GetReference(eRefTypeIndexName)
End Function

 

Best regards,

Christoph

 

Staff Applications Engineer
National Instruments
Certified LabVIEW Developer (CLD), Certified LabVIEW Embedded Systems Developer (CLED)


Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved
0 Kudos
Message 2 of 2
(3,354 Views)