How to design Mel filter bank in Simulink?
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);
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
alamo
on 15 Apr 2011
Kaustubha Govind
on 15 Apr 2011
I think the issue is to pre-define 'y' (see http://www.mathworks.com/help/toolbox/eml/ug/bq1h2z9-38.html#bq1h2z9-46)
Note that you need to specify both the size and type of 'y' (before R2009b, the size of 'y' had to be constant). If you are using R2010a or later, try something like:
x = full(sparse(r, c, v, p, fn2));
temp = u(1:129,:,:);
y = ones(size(x,1), size(temp,2)); %you need to correct this
y = x * abs().^2;
Note: this was just some sample code - i'm not sure what the shape of 'y' is, so you'll need to pre-define 'y' as appropriate.
Zaid Mustafa
on 11 Jun 2011
Excuse me, I'm a little confuse.
And I want to ask,
How to use the sparse matrix generated by those codes?
I mean, what should I do with the matrix generated if I want to filter (for an example) example.wav?
please explain as clear as possible, because I'm new to MATLAB.
thank you for your kindness.
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.
Zaid Mustafa
on 12 Jun 2011
ok, thank you for your suggestion
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!