# Customizing output of Spectrogram[], units of Periodogram[]?

I am analyzing spectrum of recorded sound. For that purpose I am using Mathematica's built in functions Spectrogram[] and Periodogram[]. I have three questions regarding those:

1. What is the way to set desired range on frequency axis (y-axis) in Spectrogram[]'s output, so that it "zooms in" to frequencies at specific interval? I managed to accomplish this with Show[], but it removes my x axis ticks.

2. How to change tick positions on frequency axis (so for example that I have them every 200 Hz)?

1. Regarding the Periodogram[] function, what y axis represents (what are the units)?

It seems to me like something in decibels, I looked in MMA's documentation, searched on internet, and I couldn't find answer. Documentation says:

plots the squared magnitude of the discrete Fourier transform (power spectrum) of list

And I understand that the periodogram tells me which frequency is most present. But what are the units?

You can zoom in; just use PlotRange ( I have combined the tick specification and zooming-in in one plot)

Spectrogram[data, 64, 2, BlackmanHarrisWindow, ImageSize -> 500,  ImageMargins -> 10,
SampleRate -> 483, PlotRange -> All]


ticksY = Reverse@Transpose[{30 #1, 10 #1}]& @ Range@7
ticksX = Transpose[{.25 #1, .25 #1}]& @ Range@4
Spectrogram[data, 64, 2, BlackmanHarrisWindow, ImageSize -> 500, ImageMargins -> 10,
SampleRate -> 483, PlotRange -> {All, {10, 100}}, FrameTicks -> {ticksY, ticksX}]


As for the Periodogram, read under Properties & Relations. The example is the following

data = Table[2 Sin[0.2 π n] + Sin[0.5 π n] + RandomReal[{-1, 1}], {n, 0, 127}];
{Periodogram[data], ListLinePlot[Take[20 Log[10, Abs[Fourier[data]]], 64]]}


Now, there is a relationship that states $10\; log_{10}(\frac{v^{2}}{w^{2}}) = 20\; log_{10}(\frac{v}{w})$ Great; Let's put that to the test !

{Periodogram[data], ListLinePlot[Take[10 Log[10, Abs[Fourier[data]]^2], 64]]}]


So, they are the same thing and the units are dB

• I will leave to you the task of reversing the ticks in the Spectrogram plot Mar 16, 2015 at 23:17
• Thank you for your answer, it helped me a lot. Just one thing is left unsolved. The way you proposed for generating ticks works great, but for some reason they are not drawn correctly to the spectrogram. If you check on your graph from top to bottom it is 50, 60, 70 instead 70, 60, 50. Reversing the ticks list does not solve the issue. And this gives wrong values of frequencies. What I understood that happens is that frame is showing ticks relative to top, while spectrogram frequencies are drawn relative to bottom. Any ideas on how to solve this? Mar 17, 2015 at 19:46
• And now I understand your previous comment :) But it's not as easy as it seems... Mar 17, 2015 at 19:47