function ids = nmos(vds,vgs,KP,W,L,vto) % This function generates the drain-source current values "ids" for % and NMOS Transistor as a function of the drain-source voltage "vds". % % ids = nmos(vds,vgs,KP,W,L,vto) % % where "vds" is a vector of drain-source values % "vgs" is the gate voltage % "KP" is the device parameter % "W" is the channel width % "L" is the channel length % "vto" is the threshold voltage % and output "ids" is a vector of the same size of "vds" % containing the drain-source current values. ids = zeros(size(vds)); % Initialize output array with all zeros k = (W/L)*KP/2; % Combine devices material parameters % For non-cutoff operation: if vgs >= vto % Find points in vds that are in the triode region ktri = find(vds<=(vgs-vto) & vds >= 0); % Only take point up to the gate voltage minus the threshold. % If points are found in the triode region compute ids with proper formula if ~isempty(ktri) ids(ktri) = k*(2*(vgs-vto).*vds(ktri)-vds(ktri).^2); end % Find points in staturation region ksat = find(vds>(vgs-vto) & vds >= 0); % Take points greater than the excess voltage % if points are found in the saturation regions compute ids with proper formula if ~isempty(ksat) ids(ksat) = k*((vgs-vto).^2); end % If points of vds are outside these ranges then the ids values remain zero end