clear all
close all

% Example 1: RCS of a 0.5 meter PEC sphere from 10 MHz to 2.0 GHz
nMax = 100; % maximum mode number
nFreq = 256;
frequency = linspace(10e6, 2.0e9, nFreq)';  
radius = 0.5;

for iFreq = 1:nFreq
    [eTheta(iFreq,:), a] = mie(radius, frequency(iFreq), 0.0, 0.0, nMax);
    [a, ePhi(iFreq,:)] = mie(radius, frequency(iFreq), 0.0, pi/2, nMax);
end

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

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

for iFreq = 1:nFreq
    [eTheta(iFreq,:), a] = mie(radius, frequency(iFreq), pi, 0.0, nMax);
    [a, ePhi(iFreq,:)] = mie(radius, frequency(iFreq), pi, pi/2, nMax);
end

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

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

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

clear eTheta 
clear ePhi 

for iTheta = 1:nTheta
    [eTheta(iTheta,:), a] = mie(radius, frequency, theta(iTheta), 0.0, nMax);
    [a, ePhi(iTheta,:)] = mie(radius, frequency, theta(iTheta), pi/2, nMax);
end

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

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

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

clear eTheta 
clear ePhi 

for iTheta = 1:nTheta
    [eTheta(iTheta,:), a] = mie(radius, frequency, theta(iTheta), 0.0, nMax);
    [a, ePhi(iTheta,:)] = mie(radius, frequency, theta(iTheta), pi/2, nMax);
end

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

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

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

clear eTheta 
clear ePhi 

for iTheta = 1:nTheta
    [eTheta(iTheta,:), a] = mie(radius, frequency, theta(iTheta), 0.0, nMax);
    [a, ePhi(iTheta,:)] = mie(radius, frequency, theta(iTheta), pi/2, nMax);
end

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

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


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

clear eTheta 
clear ePhi 

for iTheta = 1:nTheta
    [eTheta(iTheta,:), a] = mie(radius, frequency, theta(iTheta), 0.0, nMax);
    [a, ePhi(iTheta,:)] = mie(radius, frequency, theta(iTheta), pi/2, nMax);
end

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

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



