Code covered by the BSD License  

Highlights from
Lightning Protection Circuit Design Tool for Avionics

image thumbnail

Lightning Protection Circuit Design Tool for Avionics

by

Clay McCreary

 

26 Dec 2012 (Updated )

This tool performs the calculations to optimize the design of lightning protection circuits

Lightning_Protection(varargin)
function varargout = Lightning_Protection(varargin)
% LIGHTNING_PROTECTION M-file for Lightning_Protection.fig
%      LIGHTNING_PROTECTION, by itself, creates a new LIGHTNING_PROTECTION or raises the existing
%      singleton*.
%
%      H = LIGHTNING_PROTECTION returns the handle to a new LIGHTNING_PROTECTION or the handle to
%      the existing singleton*.
%
%      LIGHTNING_PROTECTION('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in LIGHTNING_PROTECTION.M with the given input arguments.
%
%      LIGHTNING_PROTECTION('Property','Value',...) creates a new LIGHTNING_PROTECTION or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Lightning_Protection_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Lightning_Protection_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Lightning_Protection

% Last Modified by GUIDE v2.5 24-Nov-2012 19:54:11

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Lightning_Protection_OpeningFcn, ...
                   'gui_OutputFcn',  @Lightning_Protection_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Lightning_Protection is made visible.
function Lightning_Protection_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Lightning_Protection (see VARARGIN)

% Choose default command line output for Lightning_Protection
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Lightning_Protection wait for user response (see UIRESUME)
 %uiwait(handles.figure1);
 





% --- Outputs from this function are returned to the command line.
function varargout = Lightning_Protection_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;


function res_Callback(hObject, eventdata, handles);
% hObject    handle to res (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of res as text
%str2double(get(hObject,'String')); %returns contents of res as a double


% --- Executes during object creation, after setting all properties.
function res_CreateFcn(hObject, eventdata, handles)
% hObject    handle to res (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Vclamp_Callback(hObject, eventdata, handles)
% hObject    handle to Vclamp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Vclamp as text
%str2double(get(hObject,'String')); %returns contents of Vclamp as a double


% --- Executes during object creation, after setting all properties.
function Vclamp_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Vclamp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Rret_Callback(hObject, eventdata, handles)
% hObject    handle to Rret (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Rret as text
%str2double(get(hObject,'String')); %returns contents of Rret as a double


% --- Executes during object creation, after setting all properties.
function Rret_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Rret (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in WF.
function WF=WF_Callback(hObject, eventdata, handles)
% hObject    handle to WF (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%contents = cellstr(get(hObject,'String')) %returns WF contents as cell array
%contents{get(hObject,'Value')}; %returns selected item from WF


% --- Executes during object creation, after setting all properties.
function WF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to WF (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in freq.
function freq_Callback(hObject, eventdata, handles)
% hObject    handle to freq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns freq contents as cell array
%        contents{get(hObject,'Value')} returns selected item from freq


% --- Executes during object creation, after setting all properties.
function freq_CreateFcn(hObject, eventdata, handles)
% hObject    handle to freq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in direction.
function direction_Callback(hObject, eventdata, handles)
% hObject    handle to direction (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns direction contents as cell array
%        contents{get(hObject,'Value')} returns selected item from direction


% --- Executes during object creation, after setting all properties.
function direction_CreateFcn(hObject, eventdata, handles)
% hObject    handle to direction (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function voc1_Callback(hObject, eventdata, handles)
% hObject    handle to voc1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of voc1 as text
%str2double(get(hObject,'String'));% returns contents of voc1 as a double


% --- Executes during object creation, after setting all properties.
function voc1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to voc1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function isc_Callback(hObject, eventdata, handles)
% hObject    handle to isc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of isc as text
%str2double(get(hObject,'String')); %returns contents of isc as a double


% --- Executes during object creation, after setting all properties.
function isc_CreateFcn(hObject, eventdata, handles)
% hObject    handle to isc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in T.
function T_Callback(hObject, eventdata, handles)
% hObject    handle to T (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns T contents as cell array
%contents{get(hObject,'Value')}; %returns selected item from T


% --- Executes during object creation, after setting all properties.
function T_CreateFcn(hObject, eventdata, handles)
% hObject    handle to T (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function Vtestpk_Callback(hObject, eventdata, handles)
% hObject    handle to Vtestpk (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Vtestpk as text
%        str2double(get(hObject,'String')) returns contents of Vtestpk as a double


% --- Executes during object creation, after setting all properties.
function Vtestpk_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Vtestpk (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Resistor_Rectangular_Pulse_Duration_Callback(hObject, eventdata, handles)
% hObject    handle to Resistor_Rectangular_Pulse_Duration (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Resistor_Rectangular_Pulse_Duration as text
%        str2double(get(hObject,'String')) returns contents of Resistor_Rectangular_Pulse_Duration as a double


% --- Executes during object creation, after setting all properties.
function Resistor_Rectangular_Pulse_Duration_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Resistor_Rectangular_Pulse_Duration (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Resistor_Peak_Power_Callback(hObject, eventdata, handles)
% hObject    handle to Resistor_Peak_Power (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Resistor_Peak_Power as text
%        str2double(get(hObject,'String')) returns contents of Resistor_Peak_Power as a double


% --- Executes during object creation, after setting all properties.
function Resistor_Peak_Power_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Resistor_Peak_Power (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function energy_res_Callback(hObject, eventdata, handles)
% hObject    handle to energy_res (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of energy_res as text
%        str2double(get(hObject,'String')) returns contents of energy_res as a double


% --- Executes during object creation, after setting all properties.
function energy_res_CreateFcn(hObject, eventdata, handles)
% hObject    handle to energy_res (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Imov_Callback(hObject, eventdata, handles)
% hObject    handle to Imov (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Imov as text
%        str2double(get(hObject,'String')) returns contents of Imov as a double


% --- Executes during object creation, after setting all properties.
function Imov_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Imov (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function Ptvs8_Callback(hObject, eventdata, handles)
% hObject    handle to Ptvs8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Ptvs8 as text
%        str2double(get(hObject,'String')) returns contents of Ptvs8 as a double


% --- Executes during object creation, after setting all properties.
function Ptvs8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Ptvs8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function tpTVS_Callback(hObject, eventdata, handles)
% hObject    handle to tpTVS (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of tpTVS as text
%        str2double(get(hObject,'String')) returns contents of tpTVS as a double


% --- Executes during object creation, after setting all properties.
function tpTVS_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tpTVS (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function PkpwrTVS_Callback(hObject, eventdata, handles)
% hObject    handle to PkpwrTVS (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of PkpwrTVS as text
%        str2double(get(hObject,'String')) returns contents of PkpwrTVS as a double


% --- Executes during object creation, after setting all properties.
function PkpwrTVS_CreateFcn(hObject, eventdata, handles)
% hObject    handle to PkpwrTVS (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function W1_Callback(hObject, eventdata, handles)
% hObject    handle to W1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of W1 as text
%        str2double(get(hObject,'String')) returns contents of W1 as a double


% --- Executes during object creation, after setting all properties.
function W1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to W1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function W2_Callback(hObject, eventdata, handles)
% hObject    handle to W2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of W2 as text
%        str2double(get(hObject,'String')) returns contents of W2 as a double


% --- Executes during object creation, after setting all properties.
function W2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to W2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function error_msg_Callback(hObject, eventdata, handles)
% hObject    handle to error_msg (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of error_msg as text
%        str2double(get(hObject,'String')) returns contents of error_msg as a double


% --- Executes during object creation, after setting all properties.
function error_msg_CreateFcn(hObject, eventdata, handles)
% hObject    handle to error_msg (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes during object creation, after setting all properties.
function Calculate_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Calculate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes on button press in Calculate.
function Calculate_Callback(hObject, eventdata, handles)
% hObject    handle to Calculate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%%Get variables from the GUI%%
res=str2double(get(handles.res,'String'));
vclamp=str2double(get(handles.Vclamp,'String'));
Rret=str2double(get(handles.Rret,'String'));
waveform=cellstr(get(handles.WF,'String'));
WF=waveform(get(handles.WF,'Value')); %returns selected item from WF
f=cellstr(get(handles.freq,'String'));
freq=str2double(f(get(handles.freq,'Value')));
dir=cellstr(get(handles.direction,'String'));
direction=dir(get(handles.direction,'Value'));
voc1=str2double(get(handles.voc1,'String'));
isc=str2double(get(handles.isc,'String'));
thickness=cellstr(get(handles.T,'String'));
Th=thickness(get(handles.T,'Value'));
T=str2double(Th{1,1});


%%Perform Calculations
wf5a=strcmpi(WF,'5A');
wf4=strcmpi(WF,'4');
wf2=strcmpi(WF,'2');
wf3=strcmpi(WF,'3');
txtfile=strcmpi(WF,'.txt_file');

%%Convert copper weight to thickness
if (T==2);
    T=2.8;
elseif (T==1.5)
    T=2.1;
else
    T=1.4;
end
if (res+isc+Rret==0);
    set(handles.error_msg,'FontSize',14.0)
    set(handles.error_msg,'String','Either Series Resistance or Isc must have a value');
    return;
else
    set(handles.error_msg,'String','');
end
zsrc=voc1/isc;                                           %Calculate source impedance
voc=isc*(zsrc+Rret);                                     %The EMI Lab increases the 
                                                         %the generator
                                                         %voltage until isc
                                                         %is acheived, thus
                                                         %accounting for
                                                         %Rret

if (wf5a==1);
    t=[1e-7:1e-7:1e-3];
    vo=voc./0.4006;
    vapplied=vo*(exp(-13000*t)-exp(-41000*t));             %double exponential waveform, 
                                                           %constants found by trial and error
elseif (wf2==1);
    t=[1e-9:1e-9:1e-4];
    vo=voc./0.9844;
    vapplied=vo*(exp(-1100000*t)-exp(-50000000*t));
elseif (wf4==1);
    t=[1e-7:1e-7:1e-3];
    vo=voc./0.9166;
    vapplied=vo*(exp(-11300*t)-exp(-670000*t));                                                                                                               %
elseif (wf3==1);                                         
    if (freq==1);
        t=[0:1e-9:4e-5];
        vapplied=voc*exp(-170000*t).*sin(2*pi*1e6*t);
        %plot(t,vapplied);
    elseif (freq==10);
        t=[0:1e-10:4e-6];
        vapplied=voc*exp(-1700000*t).*sin(2*pi*1e7*t);
        %plot(t,vapplied);
    end
else (txtfile==1);
    [file,path]=uigetfile('*.txt','Select the voltage file');  
    tempfile=strcat(path,file);
    [t,vapplied]=textread(tempfile,'%n %n','headerlines',1);  %read data from text file
    vapplied=vapplied';
    zsrc=0;
end

if (wf3==1);    
    bidir=strcmpi(direction,'y');
    if (bidir==1);
        for k=1:length(vapplied);                               %simulate voltage clamping
                                                                %of a
                                                                %bidirectio
                                                                %nal part
            if (abs(vapplied(k))<vclamp);
                vmov(k)=vapplied(k);
            else
                if (vapplied(k)<0);
                    vmov(k)=-vclamp;
                else
                    vmov(k)=vclamp;
                end
            end
        end
    else
        for k=1:length(vapplied);                               %simulate voltage clamping
                                                                %of a
                                                                %unidirecti
                                                                %onal part
            if (vapplied(k)<vclamp)&&(vapplied(k)>-0.6);
                vmov(k)=vapplied(k);
            else
                if (vapplied(k)<-0.6);
                    vmov(k)=-0.6;
                else
                    vmov(k)=vclamp;
                end
            end
        end
    end
else        
    for k=1:length(vapplied);                               %simulate voltage clamping
                                                            %for double
                                                            %exponential
                                                            %waveforms
        if vapplied(k)<vclamp;
            vmov(k)=vapplied(k);
        else
            vmov(k)=vclamp;
        end
    end
end



Vr=vapplied-vmov;
I=Vr./(res+zsrc+Rret);                               %calculate current
Vtestpk=max(I)*(res+Rret)+vmov(I==max(I));              %Max voltage shown
                                                        %on oscope during
                                                        %test

%RESISTOR
Power_res=I.^2*res;                                     %calculate power dissipated in the resistor
%plot(t,Power_res);
energy_res=trapz(t,Power_res);                          %calculate energy to convert to a rectangular pulse
                                                        %Important for wire wound, do not yet know where
                                                        %the graph
                                                        %plateaus
Resistor_Rectangular_Pulse_Duration=1e6*energy_res./(max(Power_res)); %calculate duration of rectangular pulse
Resistor_Peak_Power=max(Power_res);                      %show peak power dissipated in the resistor
                           
%MOV or TVS
Power_mov=vmov.*I;                                      %calculate power dissipated in MOV
energy_mov=trapz(t,Power_mov);                          %calculate energy absorbed by MOV 

%Convert current to 8/20 waveform used in most datasheets
charge_mov=trapz(t,abs(I));                                  
eight_twenty=exp(-120000*t)-exp(-140000*t);
C8_20=trapz(t,eight_twenty);
Imovo=charge_mov/C8_20;
Imov=Imovo*(exp(-120000*t)-exp(-140000*t));

%Convert power to 8/20 waveform used in some TVS datasheets
%Assumes that 8/20 is the power waveform, not the current waveform
Ptvs8o=energy_mov/C8_20;
Ptvs8=Ptvs8o*(exp(-120000*t)-exp(-140000*t));

%****Convert waveform into a double exponential with <10us rise time and 
%using Ppk of the transient as Ppk, calculate tp. These values can be 
%plotted on the Ppk vs. tp graph in the datasheet. This is the same process
%as the resistor above, just a different reference waveform.****
t_10_1000=[1e-7:1e-7:1e-2];
PkpwrTVS=max(Power_mov);
tpTVS=10e-6;
energy=0;
while energy<energy_mov;    %Start at tp=10us and recursively determine tp.
    tpTVS=tpTVS+1e-6;
    ten_thousand=exp((log(0.25)./tpTVS)*t_10_1000)-exp(-500000*t_10_1000); %Used log(0.25) because the 
                                                                                %datasheet is based on the 
                                                                                %current waveform. Thus, 1/2
                                                                                %of the peak current will be 
                                                                                %1/4 of the peak power.
                                                                                %There is a little inaccuracy
                                                                                %due to no closed form
                                                                                %to determine the coefficients
                                                                                %of the double exponential, but
                                                                                %this is in the ballpark.
    Pkpwro=PkpwrTVS/max(ten_thousand);
    Pwrwav=Pkpwro.*(exp((log(0.25)./tpTVS)*t_10_1000)-exp(-500000*t_10_1000));
    energy=trapz(t_10_1000,Pwrwav);
end
tpTVS=tpTVS*1e6;

Ishort=vapplied./(res+zsrc+Rret);   %the suppression device may fail short
                                    %it is highly unlikely that the series
                                    %resistor will short, sothe only
                                    %difference is that vapplied is used
                                    %instead of Vr

%%Brooks model for trace width

W3=1;
energyo=0;
energy=1;

while(energy>energyo);                  %Recursively find the coefficient 
                                        %to result in a double exponential
                                        %waveform of power containing the
                                        %same energy as the fusing
                                        %criteria. 
W3=W3+1;
%R=(1.68e-8/0.0254)*L/(T*W);
%papplied=I.^2*R;
energy=trapz(t,I.^2); 
time_to_fuse=0.233*sqrt(W3*T);
fusing_current=12277*(W3*T*1e-6)^0.75;        %Fusing current and time to fuse 
                                        %based on an article from Douglas
                                        %Brooks, "Fusing Current when 
                                        %traces melt without a trace".  

energyo=fusing_current^2*time_to_fuse; %Energy required to fuse the trace.

end
%Ipeak=sqrt(max(power)/R)                %I=sqrt(P/R)



W4=1;
energyo1=0;
energy1=1;

while(energy1>energyo1);                  %Recursively find the coefficient 
                                        %to result in a double exponential
                                        %waveform of power containing the
                                        %same energy as the fusing
                                        %criteria. 
W4=W4+1;
%R=(1.68e-8/0.0254)*L/(T*W);
%papplied=I.^2*R;
energy1=trapz(t,Ishort.^2); 
time_to_fuse1=0.233*sqrt(W4*T);
fusing_current1=12277*(W4*T*1e-6)^0.75;        %Fusing current and time to fuse 
                                        %based on an article from Douglas
                                        %Brooks, "Fusing Current when 
                                        %traces melt without a trace".  

energyo1=fusing_current1^2*time_to_fuse1; %Energy required to fuse the trace.

end
%Ipeak=sqrt(max(power)/R)                %I=sqrt(P/R)



set(handles.Vtestpk,'String',round(Vtestpk));
set(handles.Resistor_Rectangular_Pulse_Duration,'String',...
    round(Resistor_Rectangular_Pulse_Duration));
set(handles.Resistor_Peak_Power,'String',round(Resistor_Peak_Power));
set(handles.energy_res,'String',roundn(energy_res,-2));
set(handles.Imov,'String',round(max(Imov)));
set(handles.Ptvs8,'String',round(max(Ptvs8)));
set(handles.tpTVS,'String',tpTVS);
set(handles.PkpwrTVS,'String',round(PkpwrTVS));
set(handles.W1,'String',W3);
set(handles.W2,'String',W4);

Contact us