How can i filter the spectrogram colours and take as matrix?
Show older comments
Hello, I am trying to change spectrogram matrix colours. I am writing audio and music recognition system based on Spectrogram.
function spectrogram_graph(audiofile_name)
[y,fs]=audioread(audiofile_name);
fprintf("Amount of Fs is:%d \n",fs)
specgram(y);
xlabel("Samples")
ylabel("Normalized Frequency (x pi radians/sample)")
colormap gray
c=colorbar;
c.Label.String="Powerfrequency dB(rad/sample)";
end
I have this table from this function:

I need to filter, for example: Higher than -40dB will be white and lowers will be black. I need to recieve this as matrix with only ones and zeros. Thats why i am using grayscale.
Firsty, I couldnt filter and change the colours of the spectrogram.
Secondly, I couldnt obtain 2D matrix of the spectrogram.
Can you help me please guys, best wishes
Altemur
5 Comments
Mathieu NOE
on 3 Mar 2021
hello
so if I understand right, the spectrogram should be converted to 0 and 1 only based on threshold value -40 dB ?
this is how I modified your code and the outcome of it :
[y,fs]=audioread('test_voice.wav');
fprintf("Amount of Fs is:%d \n",fs)
[yo,fo,to] = specgram(y(:,1)); % NB the amplitude of spectrogram is not in dB but in linear scale
yo = abs(yo);
figure(1),imagesc(to,fo,yo);axis('xy');
colormap jet
c=colorbar;
% apply threshold to make binary image
threshold = 0.01*max(yo,[],'all'); % equivalement in linear scale to -40 dB of max (in dB) )
spg_thres = zeros(size(yo));
ind = find(yo>threshold);
spg_thres(ind) = 1;
figure(2),imagesc(to,fo,spg_thres);axis('xy');
xlabel("Samples")
ylabel("Normalized Frequency (x pi radians/sample)")
colormap gray
c=colorbar;

Altemur Çelikayar
on 4 Mar 2021
Mathieu NOE
on 5 Mar 2021
the data are stored in array spg_thres
Altemur Çelikayar
on 6 Mar 2021
Mathieu NOE
on 8 Mar 2021
You're welcome !
Answers (0)
Categories
Find more on Multirate Signal Processing 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!