melbankm函数的代码
时间: 2024-05-14 13:17:42 浏览: 218
以下是melbankm函数的代码,它用于计算梅尔倒谱系数:
```matlab
function [m, f, c] = melbankm(p, n, fs, fmin, fmax, s)
% MELBANKM Determine matrix for a mel-spaced filterbank
%
% [M,F,C]=MELBANKM(P,N,FS,FMIN,FMAX,S) returns matrix M (size P x N) for
% a mel-spaced filterbank which is to be applied to the rows of a N-point
% signal X. The filter bank ranges from FMIN to FMAX (in Hz) and
% contains P filters (default 20). Each filter has a triangular
% spectral shape, as prescribed by the MEL scale, and is uniformly
% spaced on that scale. The triangular shape extends three bins
% (one on each side) into the neighbouring filters. S is the scale
% factor for the FFT (default 2). Thus, if the FFT is of length N,
% the triangular filters are N/S points wide. FS is the sample rate
% (default 16000).
%
% The output matrix F (size P x 1) contains the center frequencies
% of each band in the filterbank. The final output C (size N x P)
% can be used to plot the response of the filterbank to a signal
% using PLOT(F,20*log10(abs(C))), for example.
%
% See also HZ2MEL, FFT2BANK, AUD2DB, FILTERBANK.
% References:
% [1] Huang, X., Acero, A., Hon, H., 2001. Spoken Language Processing:
% A guide to theory, algorithm, and system development. Prentice Hall.
% [2] Fant, G., 1960. Acoustic Theory of Speech Production. Mouton.
% [3] T. Barnwell, "Speech analysis/synthesis based on a sinusoidal
% representation," IEEE Trans. Acoust., Speech, Signal Process.,
% vol. 34, pp. 744-754, Aug. 1986.
% Author: Kamil Wojcicki, UTD, June 2011
if nargin<6; s = 2; end
if nargin<5; fmax = fs/2; end
if nargin<4; fmin = 0; end
if nargin<3; fs = 16000; end
if nargin<2; n = 256; end
if nargin<1; p = 20; end
fmin = max(fmin,0);
if (2*s*floor(n/2))~=n; n=n+1; end % Make sure that N is even
fmax = min(fmax,fs/2);
n2 = floor(n/2);
% Compute Mel scale and corresponding frequencies
melmax = hz2mel(fmax);
melmin = hz2mel(fmin);
melp = linspace(melmin,melmax,p+2);
f = mel2hz(melp);
r = round(f/fs*n);
% Design matrix using triangular filters
c = zeros(n,p);
for k = 2:p+1
f1 = r(k-1);
f2 = r(k);
f3 = r(k+1);
c(f1:f2,k-1) = (0:(f2-f1))/(f2-f1);
c(f2:f3,k-1) = (f3-(0:(f3-f2)))/(f3-f2);
end
% Done!
m = dctmtx(p)';
m(1,:) = m(1,:) * sqrt(1/2);
m = m*c;
end
function f = mel2hz(m)
% MEL2HZ Convert frequency from mel scale
%
% F = MEL2HZ(M) converts frequencies M from the mel scale to the
% Hz scale. Input and output are in units of Hz.
% Author: Kamil Wojcicki, UTD, June 2011
f = 700*(10.^(m/2595)-1);
end
function m = hz2mel(f)
% HZ2MEL Convert frequency from Hz scale to mel scale
%
% M = HZ2MEL(F) converts frequencies F from the Hz scale to the
% mel scale. Input and output are in units of Hz and mel,
% respectively.
% Author: Kamil Wojcicki, UTD, June 2011
m = 2595*log10(1+f/700);
end
```
此函数的功能是生成一个用于计算梅尔倒谱系数的滤波器组。
阅读全文