WAV 파일의 SC (spectral centroid)를 검사하고 싶습니다. 내가 그렇게 다음 MATLAB 코드를 사용하고MATLAB의 SC (Spectral Centroid) 계산
:
function C = SpectralCentroid2(signal,windowLength, step, fs)
% function C = SpectralCentroid(signal,windowLength, step, fs)
%
% This function computes the spectral centroid feature of an audio signal
% ARGUMENTS:
% - signal: the audio samples
% - windowLength: the length of the window analysis (in number of samples)
% - step: the step of the window analysis (in number of samples)
% - fs: the sampling frequency
%
% RETURNS:
% - C: the sequence of the spectral centroid feature
%
signal = signal/max(abs(signal));
curPos = 1;
L = length(signal);
numOfFrames = floor((L-windowLength)/step) + 1;
H = hamming(windowLength);
m = ((fs/(2*windowLength))*[1:windowLength])';
C = zeros(numOfFrames,1);
for (i=1:numOfFrames)
window = H.*(signal(curPos:curPos+windowLength-1));
FFT = (abs(fft(window,2*windowLength)));
FFT = FFT(1:windowLength);
FFT = FFT/max(FFT);
C(i) = sum(m.*FFT)/sum(FFT);
if (sum(window.^2)<0.010)
C(i) = 0.0;
end
curPos = curPos + step;
end
C = C/(fs/2);
을 내가 입력하면 'SpectralCentroid2는 (366,383은, 1024, 128, 44100)는'MATLAB는 말한다 :
>> SpectralCentroid2(366383, 1024, 128, 44100)
ans =
Empty matrix: 0-by-1
I 이 문제가 발생한 이유를 모릅니다.
신호는 단지 숫자가 아닌 숫자의 배열이어야합니다. 테스트와 마찬가지로'1 : 366383'을 시도하십시오. –
>> >> SpectralCentroid2 (1 : 366383, 1024, 128, 44100) ** 오류 . * 행렬 치수가 일치해야합니다. SpectralCentroid2 오류 (행 24) 창 = H. * (신호 (curPos : curPos + windowLength-1)); ** Matlab은 위의 오류 메시지를 말했습니다 .. – Westporch