How to design Mel filter bank in Simulink?
14 views (last 30 days)
Show older comments
Hello everyone
I wanna to design Mel filter bank in Simulink and now my way is that I copy m file of Mel filter in Embedded MATLAB Function. However, some problems occurs, error message is "Function output 'x' cannot be of MATLAB type.".
How to design Mel filter bank in Simulink?
following is melfilter code:
function x=melbankm(p,n,fs)
f0 = 700 / fs;
fn2 = floor(n/2);
lr = log(1 + 0.5/f0) / (p+1);
% convert to fft bin numbers with 0 for DC term
bl = n * (f0 * (exp([0 1 p p+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)/n/f0) / lr; 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)];
eml.extrinsic('sparse'); x = sparse(r, c, v, p, 1+fn2);
0 Comments
Answers (1)
Kaustubha Govind
on 14 Apr 2011
The output 'x' of this Embedded MATLAB block becomes a Simulink Signal - however, Simulink signals cannot be of any arbitrary MATLAB type - which is why you see this error.
If your 'p' and 'fn2' are not very large, you can convert the sparse matrix to a full matrix (using the 'full' function) and output the full matrix as a Simulink signal.
x = full(sparse(r, c, v, p, 1+fn2));
If 'p' and 'fn2' are indeed very large - you should consider applying the filter within the same Embedded MATLAB function block, and outputting the filtered signal itself.
5 Comments
Kaustubha Govind
on 12 Jun 2011
Zaid: This seems to be a slightly different question (How to use a sparse filter representing Mel filter bank coefficients in MATLAB) from your original issue of getting your code to work in an Embedded MATLAB Fcn block. I would recommend creating a new question for this.
See Also
Categories
Find more on Feature Extraction 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!