I have an interesting question that I need some assistance on.
We have a signal that generally has no dominant frequency. However, it sometimes does get a dominant frequency and when it does, we are really interested in two things:
What is the dominant frequency?
How dominant is it? ( Let's call this "magnitude." )
Tracking both the dominant frequency and the intensity over time using a rolling 2 to 3 hour window every 5 minutes.
This value has predictive capability when it does show up, and it intensifies as it gets closer to a particular event we are trying to predict.
I've been able get the peak frequency because the formulas are clear enough to figure this out. The problem is the magnitude.
The "Frequency Analysis" panel results show something like this:
How do I get that peak value? I don't want to have to specify a hard-coded frequency band for this.
The problem is that I don't see a function for that.
I can call the
fft()
function in a way in which it returns a "Table" type.
signal.fft ( bounds , period , units ) : Table
Create a table of frequency magnitudes by analyzing the signal in the bounds. The table will have 2 columns, frequency and magnitude.
Then I can use the top() function to return the top 1 row ordered by the greatest "magnitude" column:
table.top ( limit , columnName , direction ) : Table
However, I cannot for the life of me figure out how to get the "mangitude" value out of the first row returned in "Table" the above function and convert it into a sample at the ending point of the rolling 3 hour/5min period.
Is this even possible. Is there a better way?
// Getting a rolling 3 hour window every 5 minutes.
$periods = periods(3h, 5min)
// for condition, get a signal with samples ending at each capsule representing:
// key: end of 3hr window
// value: peak magnitude of the fft of the $waveSignal
$periods.transformToSamples(
$cap -> { // excute the expression for each capsule in condition.
$tbl = $waveSignal.fft($cap, 1s, 's') // want the results in period lengths, not frequencies.
// get the largest magnitude, filtering for the frequency/period length range of interest
// get the first row of that table.
$r = $tbl.filter('frequency'. isBetween(30s, 150s))
.top(1, 'magnitude', 'desc')
.getFirstRow() // *******HOW DO I DO THIS???******
// convert that magnitude calculated to sample located at the end of this capsule.
sample($cap.getEnd(), $r.get('magnitude'))
}
)
Thanks in advance!
Even better would be: getting the sum of the values in the peakFrequency +-/ 2s window.