Monday, December 14, 2009

Spectral Flux (SF) in Audio

Also called Spectral Variation. Spectral flux measures how quickly the power spectrum changes. Spectral flux is defined as the variation value of spectrum between the adjacent two frames in a short-time analyze window. Spectral flux can be used to determine the timbre of an audio signal. The MATLAB code:

[wav fs] = wavread('DEMO.wav');
wav = wav / max(max(wav));
window_length = 2 * fs; % assume the windows is 2 seconds
step = 1 * fs; % and it has overlap in windows
frame_num = floor((length(wav)-window_length)/step) + 1;

H = hamming(window_length);
flux = zeros(frame_num, 1);
pos = 1;
FFT_prev = 0;

for i=1:frame_num
wav_window = H .* wav(pos:pos + window_length-1);
FFT = abs(fft(wav_window, 2*window_length));
FFT = FFT(1 : window_length);
FFT = FFT/max(FFT);

flux(i) = sum((FFT - FFT_prev) .^ 2);
FFT_prev = FFT;
pos = pos + step;
end

No comments:

Post a Comment