How to interpolate/extract row from essentially 1-D lookup table

42 views (last 30 days)
I have an n x 3 matrix of backEMF values (one per phase) that all map to the same n x 1 vector of position data. For a given position, I would like to interpolate the backEMF value of each phase in the most efficient way possible.
I can use 3 1-D lookup tables (one per phase), but that seems wasteful with respect to re-calculating the index and fraction and then the interpolation definitely isn't parallelized. I could also use a single 2-D lookup table with the 2nd dimension of breakpoints set to [1,2,3] and the second input also set to [1,2,3] but that seems innefficent as it is now doing a 2D lookup for each value. I also looked at the Prelookup->Interpolation Using Prelookup both in parallel (one per phase) and a 2-D "vectorized" version in which the 'Number of subtable selection dimensions' is set to 1 with an input of [0 1 2] (I couldn't get it to give all three results otherwise, only the first two with an input of [0 1 2] and [0 0 0]) and it performs somewhere between the 3*1D table look ups and the 2D table lookup block.
Matlab does a great job vectorizing things and I would love to take advantage of that for this application.
I am essentially looking for the equivalent of the Selector block having "Select all" as an Index Option. If that's not possible, then I'll probably go with the 2D table lookup as it's consistently slightly faster than the 2D prelookup method and much faster than the other two.
Cheers!

Accepted Answer

Matt J
Matt J on 13 Dec 2024 at 22:07
Edited: Matt J on 13 Dec 2024 at 22:14
The interpolated table data given to a 1D Lookup Table can have multiple columns. So just set it to backEMF as is.
  3 Comments
Matt J
Matt J on 13 Dec 2024 at 23:07
I don't know what "complains" means. You need to copy /paste the error messages.
Another approach might be to use a Matlab Function block, coded as below:
function y = fcn(x)
% Example column-wise interpolation using interp1
% Define the breakpoints (input values) and table data (MxN matrix)
breakpoints = [1, 2, 3, 4, 5]; % Input breakpoints (rows)
tableData = [ 1 2 3;
4 5 6;
7 8 9;
10 11 12;
13 14 15]; % MxN matrix
% Perform column-wise interpolation
y = interp1(breakpoints, tableData, x, 'linear', 'extrap');
end
Sanders
Sanders on 13 Dec 2024 at 23:41
Thank you again for the response!
The error had been "In block 'lookupTableEfficiency/vectorized/1-D Lookup Table', the number of dimensions of 'Table data' is 2, but the block parameter 'Number of table dimensions' is 1. The dimensions of 'Table data' and value of 'Number of table dimensions' must match."
I implemented your suggested Matlab Function block and with a few minor adapting tweaks it was giving the correct values! But at 1/3 the speed. With that, I'll consider this tangent for a marginal speed gain to be at an end (though it could be an interesting feature to add to the block).
Thank you!

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!