%
%  fade.m  ver 1.2  March 14, 2013
%
function[y,figure_number]=fade(nba,ist,t,y,figure_number)
    n = max(size(y)); 
    disp(' ');
    if(nba==1)
    	disp(' Apply fade in prior to integration?');
    else
    	disp(' Apply fade in after integration?');
    end
    disp('  1=yes  2=no ');
    fin=input(' ');
    if(fin==1)
        fper=input(' Enter percent ');
        if(fper>100)
            disp(' percentage error ');
        end    
        fper=fper/100;
        na=round(fper*n);
%
        for i=1:na
                arg=pi*(( (i-1)/(na-1) )+1); 
                y(i)=y(i)*0.5*(1+(cos(arg)));
        end 
    end
%
    disp(' ');
    if(nba==1)
    	disp(' Apply fade out prior to integration?');
    else
    	disp(' Apply fade out after integration?');
    end
    disp('  1=yes  2=no ');
    fout=input(' ');
    if(fout==1)
        fper=input(' Enter percent ');
        if(fper>100)
            disp(' percentage error ');
        end           
        fper=fper/100;   
        na=round(fper*n);          
        nb=n-na;
        delta=n-nb;
 %       
        for i=nb:n
                arg=pi*( (i-nb)/delta );
                y(i)=y(i)*(1+cos(arg))*0.5;
        end
    end
%
    if(fin==1 || fout==1)      
        figure(figure_number);
        figure_number=figure_number+1;
        plot(t,y)
        grid on;
        xlabel('Time (sec)');
        if(nba==1)
            if(ist==1)
                title(' Acceleration with Fade prior to Integration');
            else
                title(' Velocity with Fade prior to Integration');                
            end
        else
            if(ist==1)
                title(' Velocity with Fade after Integration');
            else
                title(' Displacement with Fade Prior after Integration');                
            end
        end       
    end     