% File: Table5_2.m for Table 5-2
%modified to calculate theoretical power collected to nth term, avo2014

clear;
clc;
fprintf('\nThis file creates a column list of J0(0,Beta) through Jn(n,Beta)');
fprintf('\nfor a specified value of Beta\n\n');
Beta = input('Enter the desired value of Beta: ');
n = input('Enter the desired value of n: ');
% k=input('order n for power calculation:   ');

n = floor(n);
Jn = zeros(n,1);
m = zeros(n,1);
p=zeros(floor(Beta),1);
pt=zeros(n,1);
for (i = 0:1:n)
  Jn(i+1) = besselj(i,Beta);
  m(i+1) = i;
end;
for (i = 0:1:n) 
    if i == 0
        pn(i+1)=besselj(i,Beta)^2;
    else pn(i+1)=2*besselj(i,Beta)^2;
    end;
    ptn(i+1)=sum(pn)*100;
    k(i+1)=1;
end;

A = [m(:) Jn ptn(:)];  %bessel number, value, total power summed to nth bessel

% Saving output to file
% In save command below set the path to the folder 
% where you want Table5_2.txt to be saved
save('Table5_2.txt','A','-ascii');

fprintf('\nThe first column lists the values for n.\n');
fprintf('The second column lists the values for Jn(n,Beta) where Beta = %g\n',Beta);
fprintf('The third column liste the total power of the signal summed to n');
fprintf('\nThe output data has been stored in the file Table5_2.txt\n');

%******************** format screen output *******************

disp('    n         Jn        %power')
disp( A ) 


