<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to perform spectrum analysis? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/562629#M100264</link>
    <description>&lt;P&gt;A little bit dirty and of course not too fast, but ,&amp;nbsp; easy to implement as a macro without any library using builtin trigonometry from splunk:&lt;BR /&gt;&lt;BR /&gt;| makeresults&lt;BR /&gt;| eval x="35 21 39 88"&lt;BR /&gt;| makemv x&lt;BR /&gt;| mvexpand x&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;| eventstats count as N&lt;BR /&gt;| streamstats count as n&lt;BR /&gt;| eval n=n-1&lt;BR /&gt;| fields - _time&lt;BR /&gt;| eventstats values(n) as k&lt;BR /&gt;| mvexpand k&lt;BR /&gt;| stats sum(eval(x*cos(2*pi()/N * k * n))) as Fr sum(eval(x*sin(2*pi()/N * k * n) * -1)) as Fi by k&lt;/P&gt;</description>
    <pubDate>Mon, 09 Aug 2021 16:37:56 GMT</pubDate>
    <dc:creator>eduardoduarte</dc:creator>
    <dc:date>2021-08-09T16:37:56Z</dc:date>
    <item>
      <title>How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160865#M98021</link>
      <description>&lt;P&gt;I do not see FFT or other Fourier transform functions.  If I must use an external script, I need the output to be searchable, as a summary index or something.   How do I do that?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2014 00:49:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160865#M98021</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2014-07-29T00:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160866#M98022</link>
      <description>&lt;P&gt;I believe R is capable of FFT, take a look at &lt;A href="http://apps.splunk.com/app/1735/"&gt;http://apps.splunk.com/app/1735/&lt;/A&gt; for using R within Splunk.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2014 07:14:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160866#M98022</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-29T07:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160867#M98023</link>
      <description>&lt;P&gt;Thank you!  With 3,397 pages of reference manual and a 155-page intro, I still have a lot of trees to kill. But yes, FFT is expressed in one function!  And the R app makes it all integral within Splunk.  Brilliant.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2014 17:50:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160867#M98023</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2014-07-29T17:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160868#M98024</link>
      <description>&lt;P&gt;You could probably buy a dedicated R-manual-Kindle for the price of printing that &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2014 17:56:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160868#M98024</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-29T17:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160869#M98025</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  Or I can just use PDF; in fact, R provides (thoughtfully) EPUB version, too.  I'm just extremely uncomfortable reading serious documents on screen. (But of course, I'm not to convert 3K pages into dead trees, either.)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2014 18:03:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160869#M98025</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2014-07-29T18:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160870#M98026</link>
      <description>&lt;P&gt;Another note: FFT operates only on equally paced samples, i.e., data of constant sampling rate.  The majority of Splunk data are not constant-rate.  I have yet to find an easy way for interpolation.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2014 20:25:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160870#M98026</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2014-07-29T20:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160871#M98027</link>
      <description>&lt;P&gt;If you have more data points than you need you can make them equally paced using &lt;CODE&gt;timechart&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;If you have too few data points you can do the same and throw some &lt;CODE&gt;streamstats&lt;/CODE&gt; shenanigans in the mix... won't be fast for a large data set though.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jul 2014 00:22:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160871#M98027</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-30T00:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160872#M98028</link>
      <description>&lt;P&gt;Here's a run-anywhere example using &lt;CODE&gt;_internal&lt;/CODE&gt; data coming in every 30s, interpolated to 10s:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal eps="*" group=per_host_thruput | head 10 | timechart fixedrange=f span=10s avg(ev) as ev
| eval value_time = case(isnotnull(ev), _time) | streamstats last(ev) as last_ev last(value_time) as last_time | reverse | streamstats last(ev) as next_ev last(value_time) as next_time | reverse
| eval interpolated_ev = last_ev + ((_time - last_time) / (next_time - last_time)) * (next_ev - last_ev)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Jul 2014 00:24:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160872#M98028</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-30T00:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160873#M98029</link>
      <description>&lt;P&gt;First line grabs data and builds a &lt;CODE&gt;timechart&lt;/CODE&gt; with data gaps in it.&lt;BR /&gt;
Second line prepares lots of data to fill in the gaps: previous value, next value, time of previous value, time of next value&lt;BR /&gt;
Last line calculates the naïve linearly interpolated value.&lt;/P&gt;

&lt;P&gt;Some results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time                ev  interpolated_ev
2014-07-30 00:55:00  99
2014-07-30 00:55:10      98.000000
2014-07-30 00:55:20      97.000000
2014-07-30 00:55:30  96
2014-07-30 00:55:40      101.000000
2014-07-30 00:55:50      106.000000
2014-07-30 00:56:00 111
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Jul 2014 00:28:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160873#M98029</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-30T00:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160874#M98030</link>
      <description>&lt;P&gt;Not familiar with cost of streamstats, but excellent work on a straight-Splunk interpolation.  You may want to give an answer in &lt;A href="http://answers.splunk.com/answers/79513/"&gt;http://answers.splunk.com/answers/79513/&lt;/A&gt;.  I made a nuanced analysis there.&lt;/P&gt;

&lt;P&gt;For my use case, I need to make sure missing data are treated as 0.  @somesoni2 offered an inexpensive way to do this in &lt;A href="http://answers.splunk.com/answer_link/149598/"&gt;http://answers.splunk.com/answer_link/149598/&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Aug 2014 18:19:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160874#M98030</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2014-08-06T18:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160875#M98031</link>
      <description>&lt;P&gt;Streamstats isn't expensive in and of itself, it runs over the data once... however, there's two streamstatses and two reverses in there, so for large data sets it's going to add up.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Aug 2014 18:33:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160875#M98031</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-06T18:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160876#M98032</link>
      <description>&lt;P&gt;Following &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/172708"&gt;@martin_mueller&lt;/a&gt;'s R-rated suggestion and help from R-rated app author &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/193463"&gt;@rfujara_splunk&lt;/a&gt;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; as well as a frantic search for cheap interpolation, the following is a recipe to analyse event count.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  | timechart count
  | appendpipe [
    | stats count
    | addinfo
    | eval temp=info_min_time."##".info_max_time
    | fields temp count
    | makemv temp delim="##"
    | mvexpand temp 
    | rename temp as _time
  ] | timechart max(count) as COUNT
  | fillnull
  | eventstats count as TOTAL
  | r "output=transform(input,FFT=Mod(fft(COUNT)),Freq=((1:TOTAL)-1)/(TOTAL*X_span))"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Application notes&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;You need to install the &lt;STRONG&gt;R app&lt;/STRONG&gt;.  See @martin_meuller's answer above.&lt;/LI&gt;
&lt;LI&gt;For event counts, gaps should be interpreted as 0.  The largest part of the above search is to do just that, thanks to &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/15147"&gt;@somesoni2&lt;/a&gt;'s &lt;A href="http://answers.splunk.com/answers/149425/how-to-produce-empty-time-buckets" target="_blank"&gt;answer to my question&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;The &lt;CODE&gt;eventstats&lt;/CODE&gt; to obtain &lt;CODE&gt;TOTAL&lt;/CODE&gt; is superficial and a waste of computation.  There should be a better way to do this within R.&lt;/LI&gt;
&lt;LI&gt;The above only outputs modulus of the transformation because counts are all real numbers.  You can output the complex numbers by ridding &lt;CODE&gt;Mod()&lt;/CODE&gt; from the above. (Interestingly, although Splunk lacks complex number arithmetics, its stats functions accepts complex numbers.  Maybe it takes the real part and discards imaginary part as NaN.)&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;Freq&lt;/CODE&gt; is a dummy sequence for interpretation, expressed in hertz.  You can chart over &lt;CODE&gt;Freq&lt;/CODE&gt;, for example.&lt;/LI&gt;
&lt;LI&gt;Maximum frequency you can analyse is 0.5/&lt;CODE&gt;span&lt;/CODE&gt;.  &lt;CODE&gt;span&lt;/CODE&gt; in both &lt;CODE&gt;timechart&lt;/CODE&gt; calls must be equal.&lt;/LI&gt;
&lt;LI&gt;Beware of an undesirable side effect of &lt;CODE&gt;timechart&lt;/CODE&gt; used to fill gaps: It forces an extra interval.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;A few F(FT)-words&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;As discrete Fourier transform goes, you only look at half of the output sequence (positive frequencies) when inputs are all real.&lt;/LI&gt;
&lt;LI&gt;When analyzing (all-positive) event counts, output at frequency 0 is meaningless, as this component contains the strong DC bias.&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;fft()&lt;/CODE&gt; uses a square sampling window.  Spectrum leakage could diffuse your analysis especially when dealing with black-and-white data such as event counts.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;R-rated notes&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Object &lt;CODE&gt;input&lt;/CODE&gt; from Splunk is in "data frame” class.  You need to “transform" it into arrays that most R functions deal with.  The &lt;CODE&gt;transform()&lt;/CODE&gt; function in the above has nothing to do with Fourier &lt;EM&gt;transformation&lt;/EM&gt;.  The latter is performed in &lt;CODE&gt;fft()&lt;/CODE&gt; function.&lt;/LI&gt;
&lt;LI&gt;In addition to fields you pass to R, &lt;CODE&gt;input&lt;/CODE&gt; also passes certain Splunk internal fields as X-rated objects.  In the above, X_span is &lt;CODE&gt;span&lt;/CODE&gt;  in the last stats function (&lt;CODE&gt;timechart&lt;/CODE&gt;); you also have access to X_time which corresponds to _time in Splunk. (This is perhaps not limited to R app.)&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;The above doesn’t address how to separate data series into R arrays then output transformed objects.  That will be my end goal.  But it’s a good start.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:16:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160876#M98032</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2020-09-28T17:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160877#M98033</link>
      <description>&lt;P&gt;Lovely writeup... however, you're suffering from a Splunk Answers bug that doesn't let you use more than a certain number of backtick-enclosed code segments &lt;CODE&gt;like this&lt;/CODE&gt;, see those eventstats0 eventstats1 etc. bits near the end.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Aug 2014 21:17:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160877#M98033</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-07T21:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160878#M98034</link>
      <description>&lt;P&gt;That's a really interesting bug.  It doesn't show in preview mode.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Aug 2014 05:16:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160878#M98034</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2014-08-08T05:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160879#M98035</link>
      <description>&lt;P&gt;Finally figured out how to handle multiple Splunk data series. R also has this concept of "multivalue", hence &lt;CODE&gt;mvfft()&lt;/CODE&gt;.&lt;BR /&gt;
&lt;CODE&gt;| r "&lt;BR /&gt;
D=length(input)-1&lt;BR /&gt;
N=length(input[[1]])&lt;BR /&gt;
N_span=N*input$X_span&lt;BR /&gt;
output=data.frame(Freq=((1:N)-1)/(N_span),Mod(mvfft(as.matrix(input[2:D]))))&lt;BR /&gt;
"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Here, X_span is from Splunk &lt;CODE&gt;_span&lt;/CODE&gt;.  (You can also access Splunk _time in X_time.)  R app adds "X" to input series names.  For example, if you do &lt;CODE&gt;timechart count as COUNT by host&lt;/CODE&gt;, it will output &lt;CODE&gt;Freq&lt;/CODE&gt; and &lt;CODE&gt;Xhost1&lt;/CODE&gt;, &lt;CODE&gt;Xhost2&lt;/CODE&gt;, etc.&lt;/P&gt;

&lt;P&gt;Filling 0 in timechart is not the best interpolation for FFT.  Better use R's own capability.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:19:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/160879#M98035</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2020-09-28T17:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform spectrum analysis?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/562629#M100264</link>
      <description>&lt;P&gt;A little bit dirty and of course not too fast, but ,&amp;nbsp; easy to implement as a macro without any library using builtin trigonometry from splunk:&lt;BR /&gt;&lt;BR /&gt;| makeresults&lt;BR /&gt;| eval x="35 21 39 88"&lt;BR /&gt;| makemv x&lt;BR /&gt;| mvexpand x&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;| eventstats count as N&lt;BR /&gt;| streamstats count as n&lt;BR /&gt;| eval n=n-1&lt;BR /&gt;| fields - _time&lt;BR /&gt;| eventstats values(n) as k&lt;BR /&gt;| mvexpand k&lt;BR /&gt;| stats sum(eval(x*cos(2*pi()/N * k * n))) as Fr sum(eval(x*sin(2*pi()/N * k * n) * -1)) as Fi by k&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 16:37:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-perform-spectrum-analysis/m-p/562629#M100264</guid>
      <dc:creator>eduardoduarte</dc:creator>
      <dc:date>2021-08-09T16:37:56Z</dc:date>
    </item>
  </channel>
</rss>

