%//************************************************************************
%//    fig_3.m: MATLAB visualization program
%//***********************************************************************
%//    Program author: Dr.-Ing. René Marklein
%//                    University of Kassel, Department of Electrical and 
%//                    Computer Engineering, Electromagnetic Theory
%//                    Wilhelmshöher Allee 71
%//                    D-34121 Kassel
%//                    Tel. 0561 804 6426, marklein@uni-kassel.de
%//
%//    Date of this version:  January 15, 2002
%//
%//    This program reads the binary data of the time history of the excitation
%//    pulsem plots the time history, computes the temporal frequency spectrum,
%//    and plots the magnitude of the temporal frequency spectrum.
%//************************************************************************

clear all;
close all;

Nt = 250;
fprintf('Nt         = %d\n', Nt);

Dt = 2.5e-12;

fprintf('Dt         = %g s\n', Dt);

f=zeros(Nt);
e=zeros(Nt);

figure(1);

fp=fopen('pulse.bin','rb')
[e,nread] = fread(fp,Nt,'float32')
nread

j=1;
for i=1:4:Nt
    f(j) = e(i);
    j=j+1;
end

Dt=4*Dt;
T= Dt*Nt;

omega_min = -pi/Dt;
Domega    = -2.0*omega_min/Nt;
omega_max = -omega_min+Domega;

fprintf('omega_min = %g Hz\n', omega_min);
fprintf('omega_max = %g Hz\n', omega_max);
fprintf('Domega    = %g Hz\n', Domega);


f_min = -1/Dt/2;
Df    = -omega_min/Nt/pi;
f_max = -f_min+Df;

fprintf('f_min = %g Hz\n', f_min);
fprintf('f_max = %g Hz\n', f_max);
fprintf('Df    = %g Hz\n', Df);


subplot(2,1,1)
plot(f,'b')
%set(gca, 'Ytick',[pulse_min pulse_max],'FontSize',6);
%axis([1 Nz pulse_min pulse_max]);
grid on 

F=fft(f);

Fabs = abs(F);

subplot(2,1,2)
plot(Fabs,'b')
%set(gca, 'Ytick',[pulse_min pulse_max],'FontSize',6);
%axis([1 Nz pulse_min pulse_max]);
grid on 

subplot(2,1,1)
title('Excitation Pulse: RC2(t) --- (Time-Domain)','FontSize',11)
axis([1 Nt -0.6 1]);   
set(gca, 'XTick',[1 200e-12/T*Nt Nt/4 Nt/2 3*Nt/4 Nt],'FontSize',10);
set(gca, 'XTickLabel',[0 200e-12 T/4 T/2 3*T/4 T],'FontSize',10);
xlabel('t in s','FontSize',10);    
set(gca, 'YTick',[-0.5 0 0.5 1],'FontSize',10);
set(gca, 'YTickLabel',[-0.5 0 0.5 1],'FontSize',10);
ylabel('Amplitude of RCn(t)','FontSize',10);


subplot(2,1,2)
title('Excitation Pulse: |RC2(f)| --- (Frequency-Domain)','FontSize',11)

axis([1 Nt 0 6]);   
set(gca, 'XTick',[1 pi*10e9/omega_max*Nt Nt/4 Nt/2 3*Nt/4 Nt],'FontSize',10);
set(gca, 'XTickLabel',[0 10e9/1e9 f_max/2/1e9 f_max/1e9 f_min/2/1e9 -Df/1e9],'FontSize',10);
xlabel('f in GHz');    
set(gca, 'YTick',[0 2.5 5],'FontSize',10);
set(gca, 'YTickLabel',[0 2.5 5],'FontSize',10);
ylabel('Magnitude of |RCn(f)|');

set(gcf,'PaperType','a4');

fprintf('Generate EPS file: fdtd1d_fig_3.eps\n');
print -depsc2 -r300 fdtd1d_fig_3.eps
fprintf('Generate EPS file: fdtd1d_fig_3.jpg\n');
print -djpeg -r150 fdtd1d_fig_3.jpg

figure(1)
colormap(gray)

fprintf('Generate EPS file: fdtd1d_fig_3_sw.eps\n');
print -deps2 -r300 fdtd1d_fig_3_sw.eps
fprintf('Generate EPS file: fdtd1d_fig_3_sw.jpg\n');
print -djpeg -r150 fdtd1d_fig_3_sw.jpg