9

I'm trying to reproduce the result of Spectrogram from SpectrogramArray, but having no luck, any help?

What I've got so far:

x = "some-audio.wav";
colorFunc = (Blend[{White, Orange, Red, Black}, #] &);

(* The spectrogram plotted by the Spectrogram function *)
Spectrogram[
 Audio[x], 400, 160, HammingWindow, ColorFunction -> colorFunc, 
 Frame -> None]

(* Trying to reproduce it *)
spect = SpectrogramArray[Audio[x], 400, 160, HammingWindow];
half = spect[[All, 1 ;; Dimensions[spect][[2]]/2]];
data = Abs[half];
ArrayPlot[Reverse@Transpose[data], AspectRatio -> 1/3, Frame -> None, 
 ColorFunction -> colorFunc]

The result:

enter image description here

enter image description here

AsukaMinato
  • 9,758
  • 1
  • 14
  • 40

1 Answers1

1

There are two ways, both showing the same result. I use the sound of an empty glass when hitting a side surface - see here

x=AudioCapture["C:\\Users\\...\\Desktop\\\\glass0.wav", MaxDuration -> 2]
colorFunc = (Blend[{White, Orange, Red, Black}, #] &);

(*The spectrogram plotted by the Spectrogram function*)
Spectrogram[Audio[x], 400, 160, HammingWindow, 
 ColorFunction -> colorFunc, FrameTicks -> None]

(*Trying to reproduce it*)
spect = SpectrogramArray[Audio[x], 400, 160, HammingWindow];
half = spect[[All, 1 ;; Dimensions[spect][[2]]/2]];
data = Abs[half];
ArrayPlot[Reverse@Transpose[data], AspectRatio -> 1/3, 
 ColorFunction -> colorFunc, FrameTicks -> None, 
 ColorFunctionScaling -> False]
(* Second way*)
ListDensityPlot[Transpose[Abs[spect]][[;; 200]], AspectRatio -> 1/3, 
 PlotRange -> All, ColorFunction -> colorFunc, 
 ColorFunctionScaling -> False, FrameTicks -> None]

Figure 1

Alex Trounev
  • 44,369
  • 3
  • 48
  • 106