How to calculate fft bin size
6 次查看(过去 30 天)
显示 更早的评论
i am using this code for mel frequency spectrum calculation, but i dont know how to calculate fft bin value?? what formula exactly use here in following code.
function z = melfspectrum(nMelf, nFFT, fs, data) %#codegen % MELFSPECTRUM Calculate Mel-frequency spectrum of frammed audio data % % Inputs: nMelf number of filters in filterbank % nFFT length of fft % fs sample rate in Hz % % Outputs: z the Mel-frequency spectrum % nFFT = 256; nMelf = 16;
%% Generate a bank of Mel-filter f0 = 700 / 22050; fn2 = floor(nFFT/2);
lr = log(1 + 0.5/f0) / (nMelf+1);
% convert to fft bin numbers with 0 for DC term bl = nFFT * (f0 * (exp([0 1 nMelf nMelf+1] * lr) - 1));
b1 = floor(bl(1)) + 1; b2 = ceil(bl(2)); b3 = floor(bl(3)); b4 = min(fn2, ceil(bl(4))) - 1;
pf = log(1 + (b1:b4)/nFFT/f0) / lr; %%%%% frequency to mel conversion fp = floor(pf); pm = pf - fp;
r = [fp(b2:b4) 1+fp(1:b3)]; c = [b2:b4 1:b3] + 1; v = 2 * [1-pm(b2:b4) pm(1:b3)];
%% Calculating Mel-frequency spectrum % by applying the Mel-filters to the spectrum of audio data % implement product of sparse matrices
data_Frq=framedFFT(1:1+fn2, :).^2; [nRow,nCol]=size(data_Frq); z=zeros(nMelf,nCol); for k=1:nCol for i=1:nMelf ind=find(r==i); c_ithrow=c(ind); f_ithrow=v(ind); z(i,k)=f_ithrow*data_Frq(c_ithrow,k); end; end; % for double check the implementation of sparse matric % m = sparse(r, c, v, nMelf, 1+fn2); % z0 = m * data(1:1+fn2, :).^2;
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!