-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated beat histogram computation and replace matlab spectrogram fun…
…ction
- Loading branch information
1 parent
2a969d9
commit 39279ec
Showing
4 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
% ====================================================================== | ||
%> @brief computes a mel spectrogram from the audio data | ||
%> | ||
%> @param x: time domain sample data, dimension channels X samples | ||
%> @param f_s: sample rate of audio data | ||
%> @param afWindow: FFT window of length iBlockLength (default: hann), can be [] empty | ||
%> @param iBlockLength: internal block length (default: 4096 samples) | ||
%> @param iHopLength: internal hop length (default: 2048 samples) | ||
%> | ||
%> @retval X spectrogram | ||
%> @retval f frequency bands | ||
%> @retval t time stamps | ||
% ====================================================================== | ||
function [X, f, t] = ComputeSpectrogram (x, f_s, afWindow, iBlockLength, iHopLength, bNormalize) | ||
|
||
% set default parameters if necessary | ||
if (nargin < 6) | ||
bNormalize = true; | ||
end | ||
if (nargin < 5) | ||
iHopLength = 2048; | ||
end | ||
if (nargin < 4) | ||
iBlockLength = 4096; | ||
end | ||
if (nargin < 3 || isempty(afWindow)) | ||
afWindow = hann(iBlockLength,'periodic'); | ||
end | ||
|
||
if (length(afWindow) ~= iBlockLength) | ||
error('window length mismatch'); | ||
end | ||
|
||
if (size(afWindow,1) < size(afWindow,2)) | ||
afWindow = afWindow'; | ||
end | ||
if (size(x,1) < size(x,2)) | ||
x = x'; | ||
end | ||
|
||
% pre-processing: down-mixing | ||
x = ToolDownmix(x); | ||
|
||
% pre-processing: normalization | ||
if bNormalize | ||
x = ToolNormalizeAudio(x); | ||
end | ||
|
||
[x_b, t] = ToolBlockAudio (x, iBlockLength, iHopLength, f_s); | ||
|
||
X = zeros(size(x_b,2)/2+1, size(x_b,1)); | ||
f = linspace(0,(size(X,1)-1), f_s/2); | ||
|
||
for n=1:size(X,2) | ||
tmp = fft(x_b(n,:)' .* afWindow); | ||
X(:,n) = abs(tmp(1:size(X,1))) * 2 / iBlockLength; | ||
end | ||
|
||
% normalization | ||
X([1 end],:)= X([1 end],:)/sqrt(2); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
% ====================================================================== | ||
%> @brief blocks audio signal into overlapping blocks | ||
%> | ||
%> @param x: audio signal (dimension length x 1) | ||
%> @param iBlockLength: target block size | ||
%> @param iHopLength: target hopsize | ||
%> @param f_s: sample rate | ||
%> | ||
%> @retval x_b (dimension iNumOfBlocks x iBlockLength) | ||
%> @retval t time stamps for blocks | ||
% ====================================================================== | ||
function [x_b, t] = ToolBlockAudio(x, iBlockLength, iHopLength, f_s) | ||
|
||
iNumBlocks = ceil(size(x,1) / iHopLength ); | ||
|
||
% time stamp vector | ||
t = (0:(iNumBlocks-1)) * iHopLength / f_s; | ||
|
||
% pad with block length zeros just to make sure it runs for weird inputs, too | ||
xPadded = [x; zeros(iBlockLength+iHopLength, 1)]; | ||
|
||
x_b = zeros(iNumBlocks, iBlockLength); | ||
|
||
for n=1:iNumBlocks | ||
x_b(n,:) = xPadded((n-1)*iHopLength+1:(n-1)*iHopLength+iBlockLength); | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,7 @@ | |
|
||
if (length(x)> 1) | ||
x_norm = x/max(abs(x),[],'all'); | ||
else | ||
x_norm = x; | ||
end | ||
end |