1

I'm trying to plot a spectrogram of a vibration signal using Matlab, but I'm not happy with the way that the spectrogram-function plots the signal (I would like to customize the axes and use a mapped vector instead of time). Right now I'm trying to plot the thing myself using pcolor:

[M_s, M_w, M_t] = spectrogram(M_i, 2^16, ceil(2^16*0.95), [0:0.2:15000], Sample_rate);
figure;
[M_t, M_w] = meshgrid(M_t, M_w);
h = pcolor(M_t, M_w, mag2db(abs(M_s)));
set(h, 'LineStyle', 'none);

However, doing this, my plotted figure is extremely slow and I can't really work with that, because it takes ages to zoom in or do anything with it. When I just use spectrogram to plot the figure, it's super fast. So my question is, what exactly does spectrogram do, to plot the figure?

Vince
  • 1,517
  • 2
  • 18
  • 43
  • 2
    To look at the code of `spectrogram`, you can type `edit spectrogram.m` in the command window. – ViG Jan 26 '18 at 08:50
  • 1
    @rayryeng I'm not sure this is a dupe. This question asks how `spectrogram` _plots_ the image, as opposed to getting the outputs of `spectrogram` and doing the plot yourself. There seems to be a difference in the resulting image. I haven't found any difference in the size of `CData` in the two options, though – Luis Mendo Jan 26 '18 at 12:40
  • @Vince `spectrogram` calls a function call `pspectrogram`. You can view what its contents with `type pspectrogram`. Be prepared for that function calling other functions and so on... – Luis Mendo Jan 26 '18 at 12:41
  • 2
    Try replace `pcolor` with `imagesc`. – Andrei Davydov Jan 26 '18 at 13:41
  • `pcolor` is extremely inefficient. You can try setting the shading to 'interp', but, like suggested above, `imagesc` would probably be better and easier. – AnonSubmitter85 Jan 26 '18 at 14:43

0 Answers0