How to calculate fft bin size
6 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!