How to implement Hermite spline in Simulink

Good morning everyone.
Can i ask if it there is a way to implement the Hermite spline (pchip) or Bezier curves in simulink?
In particular, i am using a look-up table to interpolate a curve between some point, but the cubic and akima splines don't do a good job. I was thinking about using a linear interpolating method and then smoothen up the curves, but i can't find any blockset.
Thank you very much in advance.

 Accepted Answer

There is a way to make blocks that wrap a matlab-function (matlab-functions-simulink_5), shouldn't that solve this task?
HTH

5 Comments

Oh ok, i see what you are telling me.
Can i ask if you have any idea on how to implement it in a look-up table?
I'd implement such a spline-interpolation-function in the simplest way like this:
function Yq = my_pchip(xq)
persisten X Y
if isempty(X) % think this works
load lookuptable.mat X Y
end
Yq = interp1(X,Y,xq,'pchip');
You could look at generating the PP (piece-wise polynomial form of the lookup-table) instead and use ppval instead of interp1, to possibly speed up the function...
Hi, i am sorry to bother again but i have 1 last question.
So in the picture i attached i wanted to show what i wanted to do (substitute the lookup tables). In the two block is going to enter a number between 0 and 90 deg.
The output of the upper block says that if the input is <15 the output must be 1 and if >15 the output must be 0. The transition from 1 to 0 is made between 15 and 30deg.
The output of the lower block says that if the input is <15 the output must be 0 and if >15 the output must be 1 The transition from 1 to 0 is made between 15 and 30deg.
I plugged this code for the upper block
function output = low_angles_Hermite_approximation(phase)
x = length(phase);
y = [0 0 0 0 0 0 0 1 1];
xq = [0 2.5 5 7.5 10 13 15 30 90];
output = pchip(x,y,xq);
I plugged this code for the lower block
function output = low_angles_Hermite_approximation(phase)
x = length(phase);
y = [1 1 1 1 1 1 1 0 0];
xq = [0 2.5 5 7.5 10 13 15 30 90];
output = pchip(x,y,xq);
Matlab returns the error "The first two inputs must have at least two elements"
i don't think it is hard but i do not know how to do it. Basically, based on the input, that goes from 0 to 90, the first block does this:
The second one this:
And the output is y.
To me it seems as you swapped the x and xq in the function. It ought to be:
function output = low_angles_Hermite_approximation(phase)
xq = phase;
y = [0 0 0 0 0 0 0 1 1];
x = [0 2.5 5 7.5 10 13 15 30 90];
output = pchip(x,y,xq);
When you program and run into errors like these read the help and documentation carefully - and calmly, far to often it is easy to rush that part. Also be prepared to use the debug-facilities of matlab, I typically turn on debug-stop after an error:
>> dbstop if error
Then you get a command-line prompt at the line where the error occurred with command-line access to all variables in the function and it is possible to step up in the function call-stack.

Sign in to comment.

More Answers (0)

Categories

Find more on Aerospace Applications in Help Center and File Exchange

Products

Release

R2020b

Tags

Community Treasure Hunt

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

Start Hunting!