function animate_conv_slide(slide_func, scale_func, n_frames);

  box_scale = 1.2;

  kp = xget("pixmap"); xset("pixmap", 1);

  xselect(); xbasc();

  max_slide_axis = (size(slide_func,2)-1)/2;
  slide_axis = [-max_slide_axis:max_slide_axis];

  max_scale_axis = (size(scale_func,2)-1)/2;
  scale_axis = [-max_scale_axis:max_scale_axis];

  convolution = convol(slide_func, scale_func);

  max_conv_axis = (size(convolution,2)-1)/2;
  conv_axis  = [-max_conv_axis:max_conv_axis];

  min_slide  = min(slide_func);
  max_slide  = max(slide_func);
  min_scale  = min(scale_func);
  max_scale  = max(scale_func);
  min_conv   = min(convolution);
  max_conv   = max(convolution);

  low_pt  = min(min_slide*min_scale, min_slide*max_scale, ...
                max_slide*min_scale, max_slide*max_scale, min_scale);
  high_pt = max(min_slide*min_scale, min_slide*max_scale, ...
                max_slide*min_scale, max_slide*max_scale, max_scale);

  plot_box = [-max_scale_axis-max_slide_axis low_pt*box_scale ...
               max_scale_axis+max_slide_axis high_pt*box_scale];
 
  plot2d(0, 0, [0], "012", " ", plot_box);

  pos_inc = size(scale_func,2) / n_frames;

  for ind = 0:n_frames do

    pos = min(-max_scale_axis+ind*pos_inc, max_scale_axis);

    axis = slide_axis+pos;
    scale_pt = interpln([scale_axis; scale_func], pos);

    partial_conv = convol(slide_func, scale_func([1:max_scale_axis+pos+1]));
    part_conv_axis = [-max_scale_axis-max_slide_axis:pos+max_slide_axis];

    xset("wwpc");

    plot2d([-max_scale_axis-max_slide_axis max_scale_axis+max_slide_axis], ...
           [0 0], [1], "000", " ");
    plot2d(scale_axis, scale_func, [2], "001", " ");
    plot2d(axis, slide_func*scale_pt, [5], "000", " ");
    plot2d(part_conv_axis, partial_conv, [15], "000", " ");
    plot2d(pos, scale_pt, [-15], "000", " ");

    xset("wshow");

  end //for

  xset("pixmap", kp);

//end animate_conv_slide

function plot_conv_slide(slide_func, scale_func, n_frames);

  box_scale = 1.2;

  max_slide_axis = (size(slide_func,2)-1)/2;
  slide_axis = [-max_slide_axis:max_slide_axis];

  max_scale_axis = (size(scale_func,2)-1)/2;
  scale_axis = [-max_scale_axis:max_scale_axis];

  convolution = convol(slide_func, scale_func);

  max_conv_axis = (size(convolution,2)-1)/2;
  conv_axis  = [-max_conv_axis:max_conv_axis];

  xselect(); xbasc();

  min_slide  = min(slide_func);
  max_slide  = max(slide_func);
  min_scale = min(scale_func);
  max_scale = max(scale_func);
  min_conv  = min(convolution);
  max_conv  = max(convolution);

  low_pt  = min(min_slide*min_scale, min_slide*max_scale, min_conv, ...
                max_slide*min_scale, max_slide*max_scale, min_scale);
  high_pt = max(min_slide*min_scale, min_slide*max_scale, max_conv, ...
                max_slide*min_scale, max_slide*max_scale, max_scale);

  plot_box = [-max_scale_axis-max_slide_axis low_pt*box_scale ...
               max_scale_axis+max_slide_axis high_pt*box_scale];
 
  plot2d(0, 0, [0], "012", " ", plot_box);

  pos_inc = size(scale_func,2) / n_frames;

  plot2d([-max_scale_axis-max_slide_axis max_scale_axis+max_slide_axis], ...
         [0 0], [1], "000", " ");
  plot2d(scale_axis, scale_func, [2], "001", " ");

  for ind = 0:n_frames do

    pos = min(-max_scale_axis+ind*pos_inc, max_scale_axis);

    axis = slide_axis+pos;
    scale_pt = interpln([scale_axis; scale_func], pos);

    plot2d(axis, slide_func*scale_pt, [5], "000", " ");

  end //for

  plot2d([-max_conv_axis:max_conv_axis], convolution, [15], "000", " ");

//end plot_conv_slide

function conv_tri_uhgauss_demo;

  triangle_function = [0:100 99:-1:0]/100;

  animate_conv_slide(gauss(21), triangle_function, 100);

//end conv_tri_uhgauss_demo

function conv_tri_uhgauss_plot;

  triangle_function = [0:100 99:-1:0]/100;

  plot_conv_slide(gauss(21), triangle_function, 50);

//end conv_tri_uhgauss_plot

function conv_tri_uagauss_demo;

  triangle_function = [0:100 99:-1:0]/100;

  animate_conv_slide(gauss(21)/sum(gauss(21)), triangle_function, 100);  

//end conv_tri_uagauss_demo

function conv_tri_uagauss_plot;

  triangle_function = [0:100 99:-1:0]/100;

  plot_conv_slide(gauss(21)/sum(gauss(21)), triangle_function, 50);

//end conv_tri_uagauss_plot

function conv_tri_wuagauss_demo;

  triangle_function = [0:100 99:-1:0]/100;

  animate_conv_slide(gauss(41,1)/sum(gauss(41,1)), triangle_function, 100);  

//end conv_tri_wuagauss_demo

function conv_tri_wuagauss_plot;

  triangle_function = [0:100 99:-1:0]/100;

  plot_conv_slide(gauss(41,1)/sum(gauss(41,1)), triangle_function, 20);

//end conv_tri_wuagauss_plot

function conv_tri_spike_demo;

  triangle_function = [0:100 99:-1:0]/100;

  animate_conv_slide([0 1 0], triangle_function, 100);  

//end conv_tri_spike_demo

function conv_tri_spike_plot;

  triangle_function = [0:100 99:-1:0]/100;

  plot_conv_slide([0 1 0], triangle_function, 50);

//end conv_tri_spike_plot

function conv_tri_nspike_demo;

  triangle_function = [0:100 99:-1:0]/100;

  animate_conv_slide([0 -1 0], triangle_function, 100);  

//end conv_tri_nspike_demo

function conv_tri_nspike_plot;

  triangle_function = [0:100 99:-1:0]/100;

  plot_conv_slide([0 -1 0], triangle_function, 50);

//end conv_tri_nspike_plot

function conv_triwv_spikepr_demo;

  tf = [0:10 9:-1:1]/10;
  triwv_function =[tf tf tf tf tf tf tf tf tf tf 0];

  animate_conv_slide([0 1 0 -1 0], triwv_function, 100);  

//end conv_triwv_spikepr_demo

function conv_triwv_spikepr_plot;

  tf = [0:10 9:-1:1]/10;
  triwv_function =[tf tf tf tf tf tf tf tf tf tf 0];

  plot_conv_slide([0 1 0 -1 0], triwv_function, 50);

//end conv_triwv_spikepr_plot

function conv_triwv_gauss_demo;

  tf = [-5:5 4:-1:-4]/5;
  triwv_function =[tf tf tf tf tf tf tf tf tf tf -1];

  animate_conv_slide(gauss(21)/sum(gauss(21)), triwv_function, 100);  

//end conv_triwv_gauss_demo

function conv_triwv_gauss_plot;

  tf = [-5:5 4:-1:-4]/5;
  triwv_function =[tf tf tf tf tf tf tf tf tf tf -1];

  plot_conv_slide(gauss(21)/sum(gauss(21)), triwv_function, 55);

//end conv_triwv_gauss_plot

function conv_sqwv_spikepr_demo;

  sqwv_function =[ones(1,10) -ones(1,10) ones(1,10) -ones(1,10) ...
                  ones(1,10) -ones(1,9)];

  animate_conv_slide([0 1 0 -1 0], sqwv_function, 100);  

//end conv_sqwv_spikepr_demo

function conv_sqwv_spikepr_plot;

  sqwv_function =[ones(1,10) -ones(1,10) ones(1,10) -ones(1,10) ...
                  ones(1,10) -ones(1,9)];

  plot_conv_slide([0 1 0 -1 0], sqwv_function, 25);

//end conv_sqwv_spikepr_plot

function conv_sqwv_gauss_demo;

  sqwv_function =[ones(1,40) -ones(1,40) ones(1,40) -ones(1,39)];

  animate_conv_slide(gauss(21)/sum(gauss(21)), sqwv_function, 100);  

//end conv_sqwv_gauss_demo

function conv_sqwv_gauss_plot;

  sqwv_function =[ones(1,40) -ones(1,40) ones(1,40) -ones(1,39)];

  plot_conv_slide(gauss(21)/sum(gauss(21)), sqwv_function, 25);

//end conv_sqwv_gauss_plot

function conv_sin_junk_demo;

  weird_func = [-1:0.2:0 0 0:0.1:0.5 0.5 -0.5:0.2:1]/2.5;

  animate_conv_slide(weird_func, sin(0:0.01:10), 100);  

//end conv_sin_junk_demo

function conv_sin_junk_plot;

  weird_func = [-1:0.2:0 0 0:0.1:0.5 0.5 -0.5:0.2:1]/2.5;

  plot_conv_slide(weird_func, sin(0:0.01:10), 50);

//end conv_sin_junk_plot
