Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What possibilities are there for time-frequency analysis in Mathematica beyond wavelet decomposition? I could not even find a simple STFT.

share|improve this question
See this question for a spectrogram. – R. M. May 23 '12 at 23:49
See: Fractional Fourier transform, it has a downloadable notebook – Jagra May 23 '12 at 23:50
you can use Wigner distribution function ... see demos...…… – s.s.o May 24 '12 at 0:03
up vote 2 down vote accepted

we can do a STFT of Sin[Pi*t^4]

f[t_] := Sin[Pi*t^4];
data = Table[f[t], {t, 0, 5, 0.001}];
Spectrogram[data, SampleRate -> 1000]

enter image description here

the instantaneous frequency of f[t] is $$\frac{\frac{\partial f(t)}{\partial t}}{2 \pi }$$.So the ideal instantaneous frequency is:

Plot[Evaluate[D[Pi*t^4, t]/(2 Pi)], {t, 0, 5}]

enter image description here

Ok,Combine the two image: enter image description here

Well done.Mathematica gives a fine result.

share|improve this answer

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.

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

STFT[r_]:= Fourier /@ Partition[r, 2^13, 2^12];

That's the end of it.

Of course it would take a little more to make a function with options such as Overlap, 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 implementation. You should go check it out.

Legacy code from before having seen the link with enough attention:

Options[STFT] = {"Overlap" -> 0.5, 
   "DropNegativeFrequenciesForRealInputs" -> True, 
   "Window" -> ConstantArray[1, 2^10], "DFTLength" -> 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], #] &[
     Fourier /@ (w # &) /@ Partition[r, wlen, wstep]]]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.