1
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Have you tried Spectrogram[audio, Method -> "MelFrequency"] ? That's log scaled. $\endgroup$
    – flinty
    Commented Jul 26, 2020 at 13:45

1 Answer 1

2
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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 puzzling.stackexchange.com/a/100405/60449. btw, you might cosider removing the youtube download instruction. $\endgroup$
    – lineage
    Commented Jul 26, 2020 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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