CODE % LightningFFTs2 clf clc if (~exist('AL10','var')) (1) load Lightning.mat end x=input('Input Lightning Data Variable: '); (2) COMMENTS (1) Loads data file containing lightning data. Lightning.mat can be downloaded off the Cosmiac wiki site. (2) Input lightning data variable name (e.g. AL2, AL10) (3) Computes period and length of signal which is then used to find frequency in variable “hertz” (4) Fourier Transform of lightning signal (5) Plots semi-logarithmic graph of frequency versus magnitude of the Fourier Transform (6) Plots two vertical lines that specify 30-300 MHz frequency range (7) Table of antenna factor values. Antenna factor can be seen on the wiki site. (8) Used to define domain of signal that needs to be attenuated by antenna factor. T=1/2.5e9; N=length(x); (3) k=0:N-1; X=fft(x(:,2)); (4) magX=abs(X); hertz=k*(1/(N*T)); figure(1) (5) semilogy((hertz(1:N/2)),magX(1:N/2) ),... title('Magnitude of X(k)'),... xlabel('Hz'),ylabel('|X(k)|'), grid hold on plot([3e7;3e7],[10^4;10^4],'r','LineWidth',2) plot([3e8;3e8],[10^4;10^4],'r','LineWidth',2) (6) hold off a=hertz; b=magX; tab=[30e6 12.5; 75e6 6; 90e6 8; 14;... 135e6 14.5; 180e6 15; 195e6 17.5;... 225e6 16.5; 16; 270e6 17.5; 20];(7) 45e6 11; 60e6 12; 105e6 13; 120e6 150e6 14; 165e6 14; 17.5; 210e6 240e6 16.5; 255e6 285e6 18; 300e6 subdomain=[30e6,300e6]; (8) xsub=N*T*subdomain(1):N*T*subdomain (2); xbefore=1:N*T*subdomain(1); end_x=size(x)/2; xafter=N*T*subdomain(2):end_x; xi=linspace(0,300e6,length(xsub)); pp=interp1(tab(:,1),tab(:,2),'pchip ','pp'); (9) yi=ppval(pp,xi); figure(2) semilogy(abs(X(xsub))) title('Magnitude of X(k)'),... xlabel('Hz'),ylabel('|X(k)|'), grid (10) figure(3) sig_af=abs(X(xsub))+yi’; (11) phase_af=angle(X(xsub)); total_sig=phase_af./sig_af; complex_corrected=sig_af.*(cos(phas e_af)+1*i.*(sin(phase_af))); plot(abs(sig_af)) title('Signal minus Antenna Factor'),... xlabel('Magnitude of X(k)'),ylabel('|X(k)|'), grid (12) [maxX_k,maxloc]=max(abs(sig_af)); [minX_k,minloc]=min(abs(sig_af)); (13) xsub=N*T*subdomain(1):N*T*subdomain (2); signal = [ ... X(1:N*T*subdomain(1)-1); ... complex_corrected; ... X(N*T*subdomain(2)+1:500e3); ... X(500e3:-1:N*T*subdomain(2)+1); ... complex_corrected(size(complex_corr ected,1):-1:1); ... X(N*T*subdomain(1)-1:-1:2); ... ]; (14) sig=ifft(signal); (15) figure(4) (16) subplot(2,1,1) plot(1:size(x),x) title('Signal') xlabel('Time') ylabel('Volts') grid on subplot(2,1,2) (9) Creation of polynomial function used to define antenna factor (10) Semi-logarithmic plot of 30-300 MHz region (11) Correcting signal using antenna factor (12) Plot of 30-300 MHz region after antenna gain or loss is considered (13) Returns minimum and maximum values of X(k) in the 30-300 MHz region (14) Reconstruction of original signal with antenna factor taken into account in the frequency domain (15) Inverse Fourier Transform of corrected signal (16) Plots of original signal and corrected signal plot(real(1:size(sig),sig)) (17) Maximum intensity of electric field [v,loc]=max(sig); correct_sig=real(sig(loc100:loc+100,:)); (18) Impedance of free space: Z0=120π Ω E_max=max(sig); (17) (19) z0=120*pi; (18) (20) Calculates time length of the corrected signal. The code then calculates the energy of the signal by numerical integration and the power of the signal noise=[x(1:4e5) x(6e5:1e6)]; energy_noise=trapz(real(noise.^2))/ z0; (19) time_sig=length(x)*(x(2)-x(1)); energy_sig=trapz(real(correct_sig.^ 2))/z0-energy_noise; power_sig=energy_sig/time_sig; (20) fprintf('\nMaximum value of X(k): %f dBV \n',maxX_k) fprintf('\nLocation of Maximum dBV: %f Hz \n',maxloc) fprintf('\nMinimum value of X(k): %f dBV \n',minX_k) fprintf('\nLocation of Minimum dBV: %f Hz \n',minloc) fprintf('\nMaximum Intensity of EField: %f volts/meter \n',E_max) fprintf('\nAverage Power of EField: %f Watts \n',power_sig) fprintf('\nEnergy: %f Joules \n',energy_sig)(21) R=input('\nInput "1" to exit program and close plots: '); if R==1 close all end Calculates noise energy (21) Returns maximum and minimum frequency and their locations, maximum intensity, and average power and displays them on the command window