Spectrogram computed on the Bark scale

9 visualizaciones (últimos 30 días)
Lazaros Moysis
Lazaros Moysis el 14 de Mzo. de 2023
Editada: Nayan el 11 de Abr. de 2023
I want to generate a spectrogram for a given song, segmented at 1 second intervals, with 50% overlap.
I want to reproduce the results of a paper, which suggests computing the spectrogram on the 21 first Bark bands. My code is as follows, and I am not sure if it is correct. I would appreciate feedback on the process. I use 1:7700, so I can obtain a matrix with 7700 rows, which I can then segment into each individual bin. But I am not sure if the result returned makes sense.
[sounds,freqs]=audioread(file_name);
windowsize=floor(freqs); %if i want to change the windowsize to 0.5sec, I can divide by 2. So floor here is not required
%you can start from 0 or 20.
BandBarks = [20, 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700];
Spectro=spectrogram(sounds,hann(windowsize),floor(0.5*windowsize),1:7700);
%OR should I use
Spectro=spectrogram(sounds,hann(windowsize),floor(0.5*windowsize),1:7700,freqs);

Respuestas (1)

Nayan
Nayan el 11 de Abr. de 2023
Editada: Nayan el 11 de Abr. de 2023
Hi
As I understand, you need to find the spectrogram on the bark-scale. This can be achieved by the following steps :-
  1. Read the wave-file using audioread(filename)
  2. Find the spectrogram of the signal with the desired "overlap", "number of frequency bins(nfft)" and the window type using spectrogram(x)
  3. Window length and the overlap can be calculated as per the requirement.
  4. Once the spectrogram is obtain, the spectrogram on bark-scale can be obtained using hz2bark(hz)
I would suggest you to take help of the following code snippet and the libraries mentioned above :-
N = 1024;
n = 0:N-1;
[x, fs] = audioread('farspeech.wav');
duration = length(x)/fs;
t = linspace(0, duration, length(x));
plot(t, x);
xlabel('Time (s)');
ylabel('Amplitude');
window = hann(256);
noverlap = 128; % can be adjusted as needed
nfft = 512; % can be adjusted as needed
spectrogram(x, window, noverlap, nfft, fs, 'yaxis');
[s, f, t] = spectrogram(x, window, noverlap, nfft, fs, 'yaxis');
f_bark = hz2bark(f);
imagesc(t, f_bark, 20*log10(abs(s)));
axis xy;
xlabel('Time (s)');
ylabel('Bark');
colorbar;
You can also obtain spectrogram with different scales directly by using simulink block. I would suggest you to go through the following link for you benifit and interest.
Hope this helps!

Categorías

Más información sobre Time-Frequency Analysis en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by