I am looking to plot a spectrogram of a signal, but I am running into some issues. I have created a minimal working example, and will walk through it. What follows is a bit messy, but I think that I clear question emerges at the end, and that showing the messy-ness is a good way of showing my confusion, which is the problem:
So I load the packages, create a signal, and have a look to confirm that I have generated a signal that rises in frequency with time:
using DSP, Plots; plotlyjs() fs = 44_100 ts = range(0, stop=5, step=1/fs) signal = @. sin(2π*ts^2) plot(ts, signal)
I did an FFT on it as well to make sure that things look allright:
fftplot(signal, fs) = plot( FFTW.fftfreq(length(signal), fs), abs.(fft(signal)./length(signal)), xguide="Frequency / Hz", yguide="Magnitude" ) fftplot(signal, fs)
So now I am looking to create a spectrogram. I do it, and plot it, as follows:
spec = spectrogram(signal, fs) plot(spec.time, spec.freq, spec.power, xguide="Time / s", yguide="Frequency / Hz")
Can you see the skinny line down along the x-axis? That is the only content of the plot. So initially, the axis-scaling is all messed up. This has been the case for all 3 times I have tried, and every time, the data is squished up against the x-axis. But lets zoom in on the output we got:
Now, I can make out that we have a frequency that rises with time, but the plot does look quite bad. The y-ticks are gone, and I can not hover to see the y-values. I also would prefer it to be continuos in colour instead of controur-lines. I have tried calling the last plot-command with
heatmap instead of
plot, which produces the following:
I can zoom into this as well, but the resolution seems horrible, and I can not see what in m example should reduce :
In addition there is no colorbar, which I have not been able to add.
Soooooo after a while I realized that I have been specifying the
n argument with my
fs variable, which of course leads to issues. But when I sortet that out, I got the following:
spec = spectrogram(signal, 10; fs=fs) heatmap(spec.time, spec.freq, spec.power, xguide="Time / s", yguide="Frequency / Hz")
The bars become shorter the larger my n-value is, which I don’t understand. This seems to be the reason why the default, which takes the signal length divided by 8 as n, ends up so “short”. Additionally, I no longer see the linear rise in frequency over time that I am expecting, so I think that this is even less correct somehow.
What is the correct way to plot a spectrogram produced by DPS.jl? Could a recipe for it be built in, so that new users do not have to run into the issues I have had?
PS: Switching to GR did the exact same ting, without the ability to zoom in.