%------------------------------------------------------------------------ % NAME: h_weights_integr % % Determines weights for performing an integration as a matrix % multiplication. With other words: % We want to calculate the integral of the product of G and H % by a vector multiplication as W*G % % The function H is known, but only the abscissa of G is known. % % The two functions (G and H) can be treated to be piecewise % linear or cubic (ORDERG/H = 1 or 3). % % FORMAT: w = h_weights_integr(fg,orderg,fh,orderh,h) % % RETURN: w matrix weights % IN: fg position (e.g. frequency) of values of G % orderg assumed polynomial order for G (1 or 3) % fh position of values of H % orderh assumed polynomial order for H (1 or 3) % h values of the H function (at fh) %------------------------------------------------------------------------ % HISTORY: 99.11.12 Created for Skuld by Patrick Eriksson. % 00.08.25 Adapted to AMI by Patrick Eriksson % 00.11.16 Adapted to handle linear/cubic (PE) function w = h_weights_integr(fg,orderg,fh,orderh,h) %=== Check if orders are 1 or 3 if ~( (orderg==1) | (orderg==3) ) | ~( (orderh==1) | (orderh==3) ) error('The polynomial order must be 1 or 3.'); end %=== Main sizes ng = length(fg); nh = length(fh); w = zeros(1,ng); %=== Check lengths if ( (ng<=orderg) | (nh<=orderh) ) error('The vector lengths must be larger then the corresponding order.'); end %=== Check input if ( length(h) ~= nh ) error('Lengths of integration grid and function do not match'); end %=== Init index and loop until freqs. of G are inside freqs. of H ig = 1; ih = 1; while ( (ig