1

Is there a way to make the $ y $-axis for a spectrogram logarithmic? I couldn't find an option for it and was doing it explicitly.

Consider for e.g. the spectrogram of this audio:

spectrogram

which after log adjustment would look like

logAdjustedSpectrogram

lineage
  • 1,144
  • 4
  • 10

1 Answers1

2

You can either use the Mel scale:

Spectrogram[audio, Method -> {"MelFrequency", 100, 100, 7000}, 
 ColorFunction -> GrayLevel, AspectRatio -> 1/5]

mel spectrogram

Or you can construct an Image and apply a non-linear transformation. I've used FourierParameters->{0,1} as it makes the image more crisp and it's a bit easier to notice that they're storm troopers from Star Wars:

spec = SpectrogramArray[audio, FourierParameters -> {0, 1}];
(* cut the data in half and take the Abs *)
img = Image[Map[Abs, Reverse[Transpose[spec][[1 ;; Round[Length[spec]/2]]]], {2}]];
(* move pixels to log position in y-coordinate *)
ImageForwardTransformation[img, {#[[1]], Log[#[[2]]*1308]/Log[1308]/2} &]

spectro image

flinty
  • 25,147
  • 2
  • 20
  • 86
  • thnx...i was using an explicit log on values which was taking a lot of time. You went further and improved the spectrogram itself. I have credited you here https://puzzling.stackexchange.com/a/100405/60449. btw, you might cosider removing the youtube download instruction. – lineage Jul 26 '20 at 16:26