clear all
close all

% Example 1: RCS of a 0.5 meter lossless coated sphere from 10 MHz to 2.0 GHz
nMax = 100; % maximum mode number
nFreq = 256;
frequency = linspace(10e6, 2.0e9, nFreq)';  
 
radius = [0.55 0.5]; % radius of each interface, outermost first
mu = [1.0 1.0 1.0]; % 3rd entry is a dummy value for the PEC region
epsilon = [1.0 2.56 1.0]; % 3rd entry is a dummy value for the PEC region
isPEC = 1; % innermost region is conducting
 
for iFreq = 1:nFreq
    [An Bn] = mieLayeredTerms(mu, epsilon, radius, isPEC, frequency(iFreq), nMax);
    [eTheta(iFreq,:) a] = mieScatteredField(An, Bn, 0.0, 0.0, frequency(iFreq));
    [a ePhi(iFreq,:)] = mieScatteredField(An, Bn, 0.0, pi/2, frequency(iFreq));
end

data = [frequency/1e9 20.0*log10(abs(eTheta))].';

fout = fopen('multifreq/mie/lossless_coated_sphere_multifreq_bs.rcs', 'w');
fprintf(fout, '%f %f\n', data);
fclose(fout);

for iFreq = 1:nFreq
    [An Bn] = mieLayeredTerms(mu, epsilon, radius, isPEC, frequency(iFreq), nMax);
    [eTheta(iFreq,:) a] = mieScatteredField(An, Bn, pi, 0.0, frequency(iFreq));
    [a ePhi(iFreq,:)] = mieScatteredField(An, Bn, pi, pi/2, frequency(iFreq));
end

data = [frequency/1e9 20.0*log10(abs(eTheta))].';

fout = fopen('multifreq/mie/lossless_coated_sphere_multifreq_fs.rcs', 'w');
fprintf(fout, '%f %f\n', data);
fclose(fout);


% Example 2: Bistatic RCS of a 0.5 meter lossless coated sphere at 1.0 GHz
frequency = 1.0e9;
nTheta = 721;
theta = linspace(0, pi, nTheta)';

clear eTheta 
clear ePhi 

[An Bn] = mieLayeredTerms(mu, epsilon, radius, isPEC, frequency, nMax);
for iTheta = 1:nTheta
    [eTheta(iTheta,:) a] = mieScatteredField(An, Bn, theta(iTheta), 0.0, frequency);
    [a ePhi(iTheta,:)] = mieScatteredField(An, Bn, theta(iTheta), pi/2, frequency);
end

data = [(theta*180/pi) 20.0*log10(abs(eTheta)) 20.0*log10(abs(ePhi))].';

fout = fopen('bistatic/mie/1.0ghz/lossless_coated_sphere_1.0ghz.rcs', 'w');
fprintf(fout, '%f %f %f\n', data);
fclose(fout);


% Example 3: Bistatic RCS of a 0.5 meter lossless coated sphere at 2.0 GHz
frequency = 2.0e9;

clear eTheta 
clear ePhi 

[An Bn] = mieLayeredTerms(mu, epsilon, radius, isPEC, frequency, nMax);
for iTheta = 1:nTheta
    [eTheta(iTheta,:) a] = mieScatteredField(An, Bn, theta(iTheta), 0.0, frequency);
    [a ePhi(iTheta,:)] = mieScatteredField(An, Bn, theta(iTheta), pi/2, frequency);
end

data = [(theta*180/pi) 20.0*log10(abs(eTheta)) 20.0*log10(abs(ePhi))].';

fout = fopen('bistatic/mie/2.0ghz/lossless_coated_sphere_2.0ghz.rcs', 'w');
fprintf(fout, '%f %f %f\n', data);
fclose(fout);



% Example 4: Bistatic RCS of a 0.5 meter lossless coated sphere at 4.0 GHz
frequency = 4.0e9;

clear eTheta 
clear ePhi 

[An Bn] = mieLayeredTerms(mu, epsilon, radius, isPEC, frequency, nMax);
for iTheta = 1:nTheta
    [eTheta(iTheta,:) a] = mieScatteredField(An, Bn, theta(iTheta), 0.0, frequency);
    [a ePhi(iTheta,:)] = mieScatteredField(An, Bn, theta(iTheta), pi/2, frequency);
end

data = [(theta*180/pi) 20.0*log10(abs(eTheta)) 20.0*log10(abs(ePhi))].';

fout = fopen('bistatic/mie/4.0ghz/lossless_coated_sphere_4.0ghz.rcs', 'w');
fprintf(fout, '%f %f %f\n', data);
fclose(fout);




% Example 5: Bistatic RCS of a 0.5 meter lossless coated sphere at 8.0 GHz
frequency = 8.0e9;

clear eTheta 
clear ePhi 

[An Bn] = mieLayeredTerms(mu, epsilon, radius, isPEC, frequency, nMax);
for iTheta = 1:nTheta
    [eTheta(iTheta,:) a] = mieScatteredField(An, Bn, theta(iTheta), 0.0, frequency);
    [a ePhi(iTheta,:)] = mieScatteredField(An, Bn, theta(iTheta), pi/2, frequency);
end

data = [(theta*180/pi) 20.0*log10(abs(eTheta)) 20.0*log10(abs(ePhi))].';

fout = fopen('bistatic/mie/8.0ghz/lossless_coated_sphere_8.0ghz.rcs', 'w');
fprintf(fout, '%f %f %f\n', data);
fclose(fout);


