spectrogram plotting in matlab
8 views (last 30 days)
Show older comments
Hello, I am trying to plot a spectrogram of audio directly from microphone. i did it and the plot looks like this: http://i56.tinypic.com/avg93a.jpg, but i would like something like this, certain range of frequency have a certain colour as the background and in there when i get a signal depended on the intensity of it, it should be light or darker. like this: http://i55.tinypic.com/28holg5.jpg. I am not so sure how to do it, please help and thank you
0 Comments
Accepted Answer
Bjorn Gustavsson
on 14 Jul 2011
Ok, for this I guess you could do something like this:
t=0:0.001:2; % 2 secs @ 1kHz sample rate
x=chirp(t,0,1,150); % Start @ DC, cross 150Hz at t=1sec
F = 0:.1:100;
[y,f,t,p] = spectrogram(x,256,250,F,1E3,'yaxis');
pcolor(t,f,10*log10(abs(p)));shading flat
% That should be your spectrogram.
% But you wanted the colour to represent frequency
% so make an HSV image with the frequency linearly scaled
% between 0-1 into the hue chanel:
for i2 = 1:size(t,2),
hsv(:,i2,1) = f/max(f);
end
% Then you have to map your amplitude/power to the
% Saturation and value/intensity chanels (and keep the
% values between 0-1):
hsv(:,:,3) = ((p-min(p(:)))/(max(p(:)-min(p(:))))).^0.2;
hsv(:,:,2) = (p-min(p(:)))/(max(p(:)-min(p(:))));
[min(min(hsv(:,:,2))), max(max(hsv(:,:,2)))]
hsv(:,:,2) = log10(1+10*hsv(:,:,2));
[min(min(hsv(:,:,2))), max(max(hsv(:,:,2)))]
hsv(:,:,2) = hsv(:,:,2)/max(max(hsv(:,:,2)));
% Change these after taste...
% Then convert from HSV to RGB:
rgb = hsv2rgb(hsv);
% And display:
imagesc(rgb)
For more advanced displaying of rgb-images I like: http://www.mathworks.com/matlabcentral/fileexchange/3777-tcolor-a-fast-pcolor-that-likes-rgb-images
0 Comments
More Answers (0)
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!