Time-frequency analysis beyond wavelets - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-21T18:42:32Z https://mathematica.stackexchange.com/feeds/question/5977 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/5977 8 Time-frequency analysis beyond wavelets Emre https://mathematica.stackexchange.com/users/888 2012-05-23T23:35:25Z 2017-07-14T06:45:52Z <p>What possibilities are there for time-frequency analysis in Mathematica beyond wavelet decomposition? I could not even find a simple STFT.</p> https://mathematica.stackexchange.com/questions/5977/-/5982#5982 12 Answer by Rojo for Time-frequency analysis beyond wavelets Rojo https://mathematica.stackexchange.com/users/109 2012-05-24T05:31:31Z 2012-05-24T06:10:27Z <p>The links provide you with everything you need I think. The goal of this answer is to show you that even though it's not built in, a discrete STFT is quite easy and short to code.</p> <p>This would take the DFT of the data set partitioned into chunks of length 2^13, with half a window overlap, and a rectangular window</p> <pre><code>STFT[r_]:= Fourier /@ Partition[r, 2^13, 2^12]; </code></pre> <p>That's the end of it.</p> <p>Of course it would take a little more to make a function with options such as <code>Overlap</code>, some option to automatically drop the negative frequencies for real inputs, window type, DFT length... But all of them are immediate to implement. I just saw the very neat @RM's <a href="https://mathematica.stackexchange.com/a/4027/109">implementation</a>. You should go check it out.</p> <p><em>Legacy code from before having seen the link with enough attention:</em></p> <pre><code>Options[STFT] = {"Overlap" -&gt; 0.5, "DropNegativeFrequenciesForRealInputs" -&gt; True, "Window" -&gt; ConstantArray[1, 2^10], "DFTLength" -&gt; 2^10}; STFT[r_, OptionsPattern[]] := With[{wlen = OptionValue["DFTLength"]}, With[{w = PadRight[OptionValue["Window"], wlen], wstep = Round[wlen (1 - OptionValue["Overlap"])]}, If[r \[Element] Reals, Take[#, All, Round[Last@Dimensions@#]/2], #] &amp;[ Fourier /@ (w # &amp;) /@ Partition[r, wlen, wstep]]] ]; </code></pre> https://mathematica.stackexchange.com/questions/5977/-/104414#104414 5 Answer by partida for Time-frequency analysis beyond wavelets partida https://mathematica.stackexchange.com/users/15961 2016-01-19T12:46:17Z 2017-07-14T06:45:52Z <p>we can do a STFT of <code>Sin[Pi*t^4]</code></p> <pre><code>f[t_] := Sin[Pi*t^4]; fs=1000.(*Hz*); data = Table[f[t], {t, 0, 5, 1/fs}]; Spectrogram[data, SampleRate -&gt; fs] </code></pre> <p><a href="https://i.stack.imgur.com/M359n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M359n.png" alt="enter image description here"></a></p> <p>the instantaneous frequency of f[t] is $$\frac{f'(t)}{2 \pi }$$ So the ideal instantaneous frequency is:</p> <pre><code>Plot[Evaluate[D[Pi*t^4, t]/(2 Pi)], {t, 0, 5}] </code></pre> <p><a href="https://i.stack.imgur.com/8d4LM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8d4LM.png" alt="enter image description here"></a></p> <p>Ok,Combine the two image: <a href="https://i.stack.imgur.com/Y4MWF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y4MWF.png" alt="enter image description here"></a></p> <p>Well done.Mathematica gives a fine result.</p>