NI Home > Community > NI Discussion Forums

DIAdem

Reply
Member
Mr. Spark Plug
Posts: 52
0 Kudos
Accepted Solution

Time channel with offset in the middle

[ Edited ]

I have a time channel that has an unexplicable "step" in it.  I'm going to blame it on sunspots...  Anyway, for some reason, my measurement system has a big jump in the time channel, which is ruining some analysis.  I have about 40 different explicit time channels, and only some of the exhibit this problem.  Please take a look at the attached screen print to see the problem.

 

I can't go back an collect the data, so I need to fix the time channel as it is now.  Any ideas how I can fix this?  The data is explicit, so I can't create an implicit time channel.  Basically, I need to offset this particular time channel starting at row 1861119 and later.  Since I have so many time channels to check, I would like to create a script.  I will also use the script in the future to automatically fix this, if it should happen again.

 

Any help is appreciated. 

Untitled.png

Trusted Enthusiast
Brad_Turpin
Posts: 2,719
0 Kudos

Re: Time channel with offset in the middle

Hi Mr. Spark Plug,

 

We can help you achieve your goals, but you need to provide more information.  You can run a script to check the elapsed time between adjacent values in the Time channel and look for any delta time values greater than a certain allowable threshold to detect these unwanted sunspot events.  What would be that threshold delta time value?  Is it a static value or something dependent on the average delta time in the data file, or what?

 

Once detected, the script can shift the values in the time channel after the sunspot event to make the large delta time sunspot incident into a reasonable delta time value.  So, what would that reasonable delta time value be?  The same as the previous or subsequent delta time?  The same as the average delta time in the time channel, with or without the sunspot jump?

 

Would you ever expect more than one sunspot event per time channel?  Or would you be willing to run the processing script multiple times if there are multiple sunspot events?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Member
Mr. Spark Plug
Posts: 52
0 Kudos

Re: Time channel with offset in the middle

Hello Brad, we are collecting the data at 100hz, but it is an explicit time channel with data collected from a CAN network.  So, the time stamp deltas can be as much as .2s.  I would think that anything over 1s would be a good delta to use.  So far, I have only seen ONE sunspot event per time channel.  I hope it doesn't happen again, as that would mean I have bigger problems. (Have you ever seen anything like this before?  I can't imagine what would cause this to happen)

 

The shift in time after the sunspot event should have a value of 0.01s + the time stamp just prior to the event. So the reasonable time would be 0.01s.  This should get the channel back to a reasonable state. So if the values are 1.2258, 1.2347, 5.6743, 5.6878, they should become 1.2258, 1.2347, 1.2447, 1.2582.  Notice that the delta between value 3 and 4 is maintained. 

 

This is IMPORTANT, the delta between all the values needs to be maintained, with the exception of the delta between the first pre-sunspot value, and the first post-sunspot value.  Does that make sense?

 

Thanks for the help. 

 

 

Trusted Enthusiast
Brad_Turpin
Posts: 2,719
0 Kudos

Re: Time channel with offset in the middle

Hi Mr. Spark Plug,

 

OK, I think I have all the info I need.  Would you be able to post of email (brad.turpin@ni.com) me a data set to practice with?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Member
Mr. Spark Plug
Posts: 52
0 Kudos

Re: Time channel with offset in the middle

Hello Brad, thanks for the help, I appreciate it very much.  I sent an email, but it was 63MB, so if you do not recieve it, I might have to get the data to you another way. 

Trusted Enthusiast
Brad_Turpin
Posts: 2,719

Re: Time channel with offset in the middle

Hi Mr. Spark Plug,

 

Here's the script I just created to filter out those spikes.  The last two lines are commented out but in production would be commented back in.  The 3rd to last line would be removed in production, but I left it there for you to compare the new original channel with the new time channel.

Const MaxDelta = 1.00 ' seconds
Const NewDelta = 0.01 ' seconds
Set Group = Data.Root.ActiveChannelGroup
Set TimeChannel = Group.Channels("Time")
Set DeltChannel = Group.Channels.Add("Delta", DataTypeFloat64)
Call ChnDeltaCalc(TimeChannel, DeltChannel)
Call ChnAreaInsert0(DeltChannel, 1, 1)
L1 = TimeChannel.Properties("Number").Value
L2 = DeltChannel.Properties("Number").Value
R1 = MaxDelta
R2 = NewDelta
Call FormulaCalc("Ch(L2):= Ch(L2)*(Ch(L2)<R1) + R2*(Ch(L2)>=R1)")
DeltChannel.Values(1) = TimeChannel.Values(1)
Call ChnSum(DeltChannel, DeltChannel)
'Call ChnSum(DeltChannel, TimeChannel)
'Call Group.Channels.Remove(DeltChannel.Name)

  

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Member
Mr. Spark Plug
Posts: 52
0 Kudos

Re: Time channel with offset in the middle

You sir, are a genious.  I'm glad you used conditional statements in the formula calc function, I didn't know you could do that.  Brilliant.  I can now drastically improve the speed of a lot of my scripts.  It's like going from a musket to a mini-gun, haha. 

 

Thanks again!

Member
Mr. Spark Plug
Posts: 52
0 Kudos

Re: Time channel with offset in the middle

One more question: How can you use formulacalc when you know the channel index, rather than the value?  For example, lets say I want to add 25 to value from index 1000 to index 1500. How could I do that with formulacalc? 

 

Maybe an easier answer is where could I go for more information on formula's and thier tricks? 

 

Thanks.

Trusted Enthusiast
Brad_Turpin
Posts: 2,719
0 Kudos

Re: Time channel with offset in the middle

Hi Mr. Spark Plug,

 

You would need to create a NewChannel with the correct length (below I assume 2000) which has 0s in the index range you want to leave unchanged and the increment value (below I assume 25) in the index range you do want to increment.  Then it's just a matter of adding the 2 channels, which you can do easier with the ChnAdd() function.  Typically you would delete or reuse the NewChannel afterwards.

 

Set NewChannel = Data.Root.ActiveChannelGroup.Channels.Add("Temp Increment", DataTypeFloat64)
Call ChnLinGen(NewChannel, 15, 15, 500)
Call ChnAreaInsert0(NewChannel, 1, 999)
ChnLength(NewChannel) = 2000
Call ChnAdd(OldChannel, NewChannel, OldChannel)

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments