0

I would like to get a plot of the same type of the one that I get with spectrogram function, I am trying with contour but I do not get the same result. I have written a small function which compares the two plot. The function records audio for one second and then plot the spectrogram.

function graph_comparison
    a = audiorecorder(44100,16,1);
    recordblocking(a,1);
    y = getaudiodata(a);
    figure
    subplot(1,2,1);
    spectrogram(y);
    s = spectrogram(y);
    subplot(1,2,2);
    contour(mag2db(abs(s))); %mag2db converts intensity in db
    %rotate the second plot
    view(-90, 90); 
    set(gca, 'ydir', 'reverse');
end

Example of plot result: enter image description here

Nisba
  • 3,210
  • 2
  • 27
  • 46
  • 1
    If you want to achieve the same result of `spectrogram`, why you don't simply use it? – Jepessen Aug 30 '17 at 09:42
  • because I need to manipulate data first, so in my real code I use the variable `s`, but I like the kind of plot given by `spectrogram`. – Nisba Aug 30 '17 at 09:43

1 Answers1

1

I found it, it is sufficient to replace contour with imagesc.

Nisba
  • 3,210
  • 2
  • 27
  • 46
  • You can also try `contourf`. – Ahmed Fasih Aug 30 '17 at 12:54
  • Thanks, but looks uglier than contour if with a lot of levels And otherwise I get few informations – Nisba Aug 30 '17 at 13:14
  • 1
    Yup, `imagesc` is the way to go. But be careful with imagesc: when you call `imagesc(x, y, z)`, it doesn’t assign pixel locations to `x` and `y`. E.g., this works: `imagesc([-1 1], [10 20], randn(100,100))`, because `imagesc` just uses `x` and `y` to get the extents. That's one confusion that took a while it figure out. – Ahmed Fasih Aug 30 '17 at 16:23
  • @AhmedFasih actually setting 'LineColor' to 'none', with contourf I can use a lot of levels and get still a good plot! Thank you – Nisba Aug 30 '17 at 17:48