What is the most efficient code for calculating a signal based on voltage time history and a calibration curve.

1 view (last 30 days)
% Lets assume that you have a voltage signal v = v(t) from a measurement (120 seconds at 500 hz sample rate)
t = 0:0.002:120;
v = randn(size(t));
% The calibration curve for the data is a curve that CANNOT be describe with a polynomial function.
vc = linspace(-2,2,15); % voltage
yc = [-9.9353 -8.2974 -5.7543 -3.5560 -2.0043 -1.2284 -0.5819 0.3233 2.0043 4.8491 6.9612 8.5991 9.4181 9.6336 9.8060]; % physical unit
% The trivial solution to calculate y is
tstart = tic;
for i=1:length(t)
y(i) = interp1(vc,yc,v(i),'cubic');
end
telapsed = toc(tstart);
The question is: What is the most efficient way to implement the calculation of y?

Accepted Answer

dpb
dpb on 13 Jan 2016
Use the vectorized form for interp1
vOut=interp1(vc,yc,v,'cubic');
A comparison showed almost no difference between using 'cubic' vis a vis 'linear' as the interpolating method; I didn't compare timings.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!