function Out = triproduce(Locations,length)

% This function is designed to create create transfer functions that consist of simple triangles according to the input matrices.  
% Locations is a nx3 matrix.  Each row of 3 column; the first two columns correspond to the two base points of an isoceles 
% triangle and the third is the peak value of the triangle.  
% Length is the total length of the output vector.

[rows,cols]=size(Locations);

% Initializes an Output vector
Out = zeros(1,length);

% Determines the midpoint (and peak's x-location) of each specified input interval
Midpoints(:,1) = (Locations(:,2)+Locations(:,1))./2;

% Makes sure that all values are integers
for i = 1:rows
   if (mod(Midpoints(i,1),1) == 0.5)
      Midpoints(i,1) = Midpoints(i,1) + 0.5;
   end
end

% Creates the output
for i = 1:rows
   
   % Extracts interval dimensions and locations
   instart = Locations(i,1);
   infin = Locations(i,2);
   peak = Locations(i,3);
   inmid = Midpoints(i,1);
   
   % Creates the upward slope
   for j = instart:inmid
      relloc = (j-instart)/(inmid-instart);
      Out(j) = peak*relloc;
   end
   
   % Creates the downward slope
   for j = inmid:infin
      relloc = (infin-j)/(infin-inmid);
      Out(j) = peak*relloc;
   end
end

      
      

