My Spectrogram doesn't look right, and has negative values

37 vues (au cours des 30 derniers jours)
LJC
LJC le 5 Déc 2022
Hi,
I am attempting to create a MATLAB App that displays a spectrogram for a chunk of audio. I have it displaying a spectrogram but I want it to look slightly different. The Spectrogram created by my application has negative values and is upside down for some reason. I have included an image of what my Spectrogram looks like and also a photo of what I want it to look like. I don't care so much about the colour scheme, I'm just unsure how to go about removing the negative values, flipping the Spectrogram so increased frequency is going up on the Y-axis, and how to get a non-linear scale for the Y-axis.
This is what my spectrogram looks like for a given piece of audio:
And this is what I would like it to look like using the same piece of audio:
Here is my code, where chunk is just a chunk of a larger piece of audio:
(The negative values in both yticks and yticklabels is just to illustrate that the negative values are there and displayed above positive ones)
[S, F, T] = stft(chunk, app.Fs,Window=kaiser(256,5),OverlapLength=220,FFTLength=512);
imagesc(app.Spectogram, T, F, rot90(log(abs(S'))));
axis(app.Spectogram, 'tight');
yticks(app.Spectogram, [-5000, 50, 100, 500, 1000, 2000, 5000, 10000]);
yticklabels(app.Spectogram, {'-5000Hz' ,'50Hz', '100Hz', '500Hz', '1000Hz', '2000Hz', '5000Hz', '10000Hz'});
set(gca,'YDir','normal');
set(gca, 'YScale', 'log');

Réponse acceptée

Mathieu NOE
Mathieu NOE le 5 Déc 2022
hello
stft : use option 'FrequencyRange','onesided'
to have only positive frequencies (or use spectrogram)
also y log scale works fine with surf but not with imagesc
[signal, Fs] = audioread ("test_voice_mono.wav");
[S, F, T] = stft(signal,Fs,'Window',kaiser(256,5),'OverlapLength',220,'FFTLength',512,'FrequencyRange','onesided'); % or use spectrogram
surf(T,F,abs(S),'EdgeColor' ,'none');
view([0 90])
hcb = colorbar('vert');
set(get(hcb,'Title'),'String','dB')
axis('tight');
yticks([50, 100, 500, 1000, 2000, 5000, 10000]);
yticklabels({'50Hz', '100Hz', '500Hz', '1000Hz', '2000Hz', '5000Hz', '10000Hz'});
set(gca,'YDir','normal');
set(gca, 'YScale', 'log');

Plus de réponses (0)

Catégories

En savoir plus sur Time-Frequency Analysis dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by