On 01/20/2016 03:37 AM, Thor Andreassen wrote: > On Fri, Jan 08, 2016 at 03:31:18PM +0100, Markus Glugla wrote: >> Hi, > > Hi Markus > >> I read the spectrogram threads and affiliate a request. I'm using >> sometimes sox spectrogram to get an spectral overview of various >> measurement datas. But i want to plot the spectrogram with other tools >> e.g. gnuplot. >> >> I would be very grateful if it were possible to output the spectrogram >> data as plotable values in a file or stream. Does anybody have the >> same intention and more experience than me to produce a patch? > > I have been planning to implement an amplitude and water-fall output, > that can be sent to Gnuplot. I will need these in the coming months, so > perhaps it will get done. > > A crude way of getting the raw numbers could be to use the color values > from the generated png file, e.g. with Imagemagick: > > sox -n -n synth 1 synth 1k:5k spectrogram -r -o - | > convert png:- txt:- | > > # translate into Gnuplot compatible input > awk -v FS='[,:() ]+' 'NR > 2 { print $1, $2, ($3+$4+$5)/3 > }' | > awk 'NR > 2 && $2 != prev { printf "\n" } { prev = $2 } > 1' \ > > spectrogram.dat > > Note the use of the `-r` option to sox, which omits all decorations. See > `sox --help-effect spectrogram` for more. > > Now plot the data file with Gnuplot: > > echo 'splot "spectrogram.dat" with pm3d' | gnuplot --persist > > If you want to get at the raw spectrogram, you need to patch > spectrogram.c. The attached patch works best with single channel files. > Use the new `-O filename` switch to save the binary data. > > The default output is a sequence of floats which are 4 bytes long. This > is also Gnuplots default for binary input. This means you can plot the > output like this: > > echo 'plot "<sox -n -n synth 1 sine 1k:5k spectrogram -O -" \ > binary array=(513,800) flipy rotation=90d with image' | > gnuplot --persist > > Note that if your output from sox is short, the spectrogram dimensions > will be different from 800x513 and Gnuplot will barf.
Please note that there are some tricky side effects if you do it incorrectly. See my post https://sourceforge.net/p/sox/mailman/message/34724933/ on when to omit and when not to omit the last sample of spectrogram data. Only when that sample is completely filled, it may be included. That is the best approach. All others result in deformed or suboptimal energy spectra. > > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > > > > _______________________________________________ > SoX-devel mailing list > SoX-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sox-devel > ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 _______________________________________________ SoX-devel mailing list SoX-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sox-devel