1

So I have written a quick script in Matlab do some visualization for me-

function spectro(filename,maxFreq)

wavchunksizefix(filename);

[y,fs] = wavread(filename);

subplot(2,1,1);
plot(y);
ylim([0 1]);
title('Signal Amplitude');

subplot(2,1,2);
specgram(y,1024,fs);
ylim([0 maxFreq]);
cb = colorbar;
set(get(cb,'title'),'string','dB');
title('Original Signal Spectrogram');

What I was wondering is this- how do modify the specgram() output to only show a specific dB range? Right now it shows a whole bunch of unnecessary noise in the 0 to 40 dB range and I only want to see 0 to -50 dB (unfortunately, I can't post an example picture because I'm new).

  • Yo have used ylim, try the zlim command. If that doesn't do what you want, extract the data from specgram ( data = specgram( . . .) ) and the threshold it manually before plotting – learnvst Jan 27 '12 at 10:38
  • As it turns out (I hadn't really checked this until now), the output data from Specgram() is a series of complex numbers. As I don't fully understand why they're complex numbers, I'll have to figure that out first. – user1172075 Jan 27 '12 at 17:34
  • The values are complex because spectrogram is giving you amplitude and phase components for each frequency bin at each epoch. When you use the spectrogram command to plot, it is the equivalent of doing surf(20*log10(abs(spectrogram_output))). The abs command converts the real/complex value pairs into a magnitude and the log term converts that into a db scale. – learnvst Jan 30 '12 at 17:42

1 Answers1

1

Very cool, thanks guys. I wrote this for filtering the signal over 40 dB and it seems to work-

[y,fs] = wavread('matrecord.wav'); 
centerval = mean(y); 
gdb = 20*log10(y/centerval);
ogv = (gdb > 40); 
x = y;
x(ogv) = 0; 

When I run specgram() on this, it seems to work.