# Spectrogram to ArrayPlot

I have an Audio that I want to extract the Spectrogram data from such that when I plot it using ArrayPlot it looks the same as the Spectrogram (I reversed it and then 1 minus to make it look exactly the same). It was working when I retrieved it from Spectrogram[audio][[1,1,All,All,1]], but after a Mathematica crash it no longer outputs the same matrix with the same audio. It used to be something like 512x954 but now its 256x5080.

EDIT: Turns out that changing the partition and offset parameters changes the dimensions of the matrix. With default values it reverts to 512x954 but with partition=512 and offset=64 it becomes 256x5080. But when I ArrayPlot the matrix from the default parameters it looks the same as the Spectrogram, this however doesn't happen for other values of the parameters. Is there a way to reconstruct the spectogram with Arrayplot for non-default values of partition and offset'?

CODE:

Export["sound.wav", Play[(2 + Cos[50 t])*Sin[2000*(1 + Round[2 t, 0.1])* t] , {t, 0, 1}]]
audio = Import["sound.wav"]
spec = Spectrogram[audio, ColorFunction -> GrayLevel]
ArrayPlot[1 - Reverse@spec[[1, 1, All, All, 1]]]


produces an ArrayPlot that looks like spec, but changing spec to spec = Spectrogram[audio, 2048, 32, BlackmanHarrisWindow] produces an ArrayPlot that does not look like spec.

• So you just want to re-create the output of Spectrogram using ArrayPlot? – Alexey Popkov May 1 '17 at 6:29
• Technically, I want the matrix that represents the Spectrogram data and I use an ArrayPlot to verify that they are the same. But short answer is yes. – I should change my Username May 1 '17 at 8:05
• Instead of using that unreadable Part expression use SpectrogramArray and Transpose. – Sektor May 1 '17 at 11:50
• Could you be a bit more specific. I have tried using SpectrogramArray. I know I can remove half of the array because the amplitudes are mirrored but then I'm stumped. I'm not that familiar with DSP or STFT but I just want the data to play with. Is SpectrogramArray outputted as Freq. x Time or some other dimensions? (I used Re on the whole array just so I could plot it to see what the data looked like. I don't know what the imaginary component is supposed to represent) – I should change my Username May 1 '17 at 23:09
• The documentation for Spectrogram shows how to create a spectrogram from SpectrogramArray (see the Properties & Relations section) – Simon Woods May 17 '17 at 18:33

You say you just want to verify it,so you can try SpectrogramArray

spec = Spectrogram[audio, 2048, 32, BlackmanHarrisWindow,
ColorFunction -> GrayLevel, Frame -> None, ImageSize -> Medium];
data = SpectrogramArray[audio, 2048, 32, BlackmanHarrisWindow];

ImageResize[ImageCrop@ArrayPlot[1 - Reverse@spec[[1, 1, All, All, 1]],
Frame -> None], ImageDimensions@spec]