07-31-2019 05:50 AM
Hi
I am in need of some assistance writing a script that will reduce manual work load, as I want the same script to run on different measurement files.
Background:
- I have access to both Diadem 2012 and 2018.
- I start with 1x .tdms file with 1x group containing 20x channels.
- Each channel is 15 s long with a resolution of 10 kHz (150 000 measurement values).
- I will first run an FFT analysis manually on one of the channels, with a step size of 1000 and no overlap. This results in 150 new channels in the frequency domain, with a step size of 100 ms. They are automatically named AmplitudePeak1, AmplitudePeak2, AmplitudePeak3, etc.
My understanding is that the calculations result in an FFT analysis every 100 ms, and that the AmplitudePeak channels are created in a chronological order.
What i want to do:
I am not interested in all the frequencies in the AmplitudePeak channels, only the highest value within two intervals. Lets call them interval a-b and interval c-d. I am interested in the maximum value in either one of them (not both, just the one value that is the highest). The highest value will then correspond to the time step 0.1 s. Then i want to repeat the process for the 2nd AmplitudePeak channel and add the highest value for the time step 0.2 s, and so on for all the 150 channels, resulting in one new channel with 150 measurements back in the time domain.
My thoughts on doing it (may it be the most efficient way or not (probably not)):
N=150 (Number of AmplitudePeak channels)
For (i=1 to i=N)
Get the maximum value in AmplitudePeak(i) found in the rows a-b or c-d in the frequency column (x).
Add the highest value to ResultChannel
End
When later plotting the ResultChannel it will then show amplitude on the y-axis and the time on the x-axis.
I would very much appreciate any help in writing this script. Thank you!
Regards Erik
Solved! Go to Solution.
07-31-2019 10:11 AM - edited 07-31-2019 10:13 AM
'------------------------------------------------------------------------------- '-- VBS script file '-- Created on 07/31/2019 09:50:24 '-- Author: g '-- Comment: --- '------------------------------------------------------------------------------- Option Explicit 'Forces the explicit declaration of all the variables in a script. Dim chnl, resultChnl, i, j, maxAB, maxCD, A, B, C, D A = 3 B = 5 C = 7 D = 12 Set resultChnl = Data.Root.ChannelGroups.Add("Results").Channels.Add("Result", DataTypeChnFloat64) i = 1 Do While True ' Loop Forever If Data.Root.ChannelGroups(1).Channels.Exists("AmplitudePeak" & i) Then ' If Another AmplitudePeak exists Set chnl = Data.Root.ChannelGroups(1).Channels("AmplitudePeak" & i) i = i + 1 ' Update for next AmplitudePeak maxAB = chnl.Values(A) ' Find maxAB For j = A To B Step 1 If chnl.Values(j) > maxAB Then maxAB = chnl.Values(j) End If Next maxCD = chnl.Values(C) ' Find maxCD For j = C To D Step 1 If chnl.Values(j) > maxCD Then maxCD = chnl.Values(j) End If Next ' Add to result channel If maxAB > maxCD Then resultChnl.Values(resultChnl.Size + 1) = maxAB Else resultChnl.Values(resultChnl.Size + 1) = maxCD End If Else Exit Do ' EXIT the while loop if no more AmplitudePeak[i] exist End If Loop
Just modify your input-output group names and the A, B, C, D ranges you want to search. Also use recording mode to automate the FFT parameters so you can save time there as well.
08-01-2019 09:46 AM
Thank you very much for the help! It worked on the first try.
One thing I don't quite understand is how the resolution is affected by the interval length. I suppose it makes sense, but I can't really figure it out.
Lets say i have the 15 s signal with 10 kHz resolution:
It is easy to see the trend:
Values/Frequency integer = Interval length/Signal resolution
= 150 000 / 10 000 = 15
= 10 000 / 10 000 = 1
= 1000 / 10 000 = 0,1
I really feel this is something I should understand, but since I dont I would very much appreciate any explanation. Thanks!
08-01-2019 10:08 AM
Hi, tagetes! The frequency resolution is defined as Fs/N in FFT. Where Fs is sample frequency, N is number of data points used in the FFT. For example, if the sample frequency is 1000 Hz and the number of data points used by you in FFT is 1000. Then the frequency resolution is equal to 1000 Hz/1000 = 1 Hz