function[] = runCapacityFun(ch_lim, con, fn)
% clear all
% close all
% clc

% define style
set(0, "defaultlinelinewidth", 2);
set(0, "defaultaxesfontsize", 8);
set(0, "defaultaxesfontname", "Helvetica");
set(0, "defaulttextfontsize", 8);
set(0, "defaulttextfontname", "Helvetica");

% input variables
switch ch_lim
	case 0
		channel_lim = 'bipolar';
	case 1	
		channel_lim = 'unipolar';
end

switch con
	case 0
		constr = 'pwr';
	case 1 
		constr = 'avg';
	case 2
		constr = 'amp';
end

% load corresponding file
switch channel_lim
    case 'bipolar'
        load capacity_bipolar.mat
    case 'unipolar'
        load capacity_unipolar.mat
    otherwise
        error('Channel limitation unknown!')
end

chart_notpossible = false;

switch constr
    case 'pwr'
        x = x_pwr;
        log_px_set = log(px_set_pwr);
    case 'amp'
        x = x_amp;
        log_px_set = log(px_set_amp);
    case 'avg'
        switch channel_lim
            case 'unipolar'
                log_px_set = log(px_set_mean);
                x = x_mean;
            case 'bipolar'
                log_px_set = log(px_set_amp);
                chart_notpossible = true;
        end
end

% ANIMATION
az = 90;
el = 9;
fn_counter = 0;

%for c = 0:9
for c = 0:19
    figure(1);
    % 3-D PDF CHART
    if chart_notpossible
        text(0.075,0.5,'The selected chart is not available','Color',[0.043 0.518 0.780],'FontSize',10);
        grid on
    else
        surf(-20.*log10(sigma_range),x,log_px_set','EdgeColor','none')
        cb = colorbar;
        xlabel('-20*log_{10}(\sigma_n)')
        ylabel('x')
	zlabel('ln(p_x(x))')
        zlab = get(cb,'ylabel');
        set(zlab,'String','ln(p_x(x))');
        [a,~] = caxis;
        caxis([a,0])
        grid on
    end

    if ~chart_notpossible    
        view(az+c*9.5,el+c*4) % view(az+c*20,el+c*9)
        %     if el+c*5<55
        %         view(az+c*20,el+c*5)
        %     else
        %         view(az+c*20,55)
        %     end
    end
        
    filename = strcat(fn,'_',num2str(fn_counter));
    print(filename,'-dpng','-S640,480','-tight');
    % print(filename,'-dpng', '-r0');
    fn_counter = fn_counter + 1;
end



