%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Datei:        Schalttabelle_DTC.m
% Autor:        EIM-E/LEA, Universität Paderborn
% Beschreibung: Schaltabelle für die DTC (Takahashi) 
%               Zweipunktregler für den Fluss
%               Dreipunktregler für das Drehmoment
%               mit Nullspannungsvektoren
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [Schaltsignale] = Switching_Table_DTC(d_psi, d_m, sector)

U(8) = 0;%[0 0 0];
U(1) = 1;%[1 0 0];
U(2) = 2;%[1 1 0];
U(3) = 3;%[0 1 0];
U(4) = 4;%[0 1 1];
U(5) = 5;%[0 0 1];
U(6) = 6;%[1 0 1];
U(7) = 7;%[1 1 1];
hilf = mod(sector,2);
% Initialisierung
Schaltsignale = U(8);

switch d_psi
    case 1
        switch d_m
            case 1
                if sector == 6
                    Schaltsignale = U(1);
                else
                    Schaltsignale = U(sector + 1);
                end
            case 0
                if hilf == 0
                    Schaltsignale = U(8);
                elseif hilf ~= 0
                    Schaltsignale = U(7);
                end
            case -1
                if sector == 1
                    Schaltsignale = U(6);
                else
                    Schaltsignale = U(sector-1);
                end
        end

    case 0
        switch d_m
            case 1
                if sector == 5
                    Schaltsignale = U(1);
                elseif sector == 6
                    Schaltsignale = U(2);
                else
                    Schaltsignale = U(sector + 2);
                end
            case 0
                if hilf == 0
                    Schaltsignale = U(7);
                elseif hilf ~= 0
                    Schaltsignale = U(8);
                end
            case -1
                if sector == 1
                    Schaltsignale = U(5);
                elseif sector == 2
                    Schaltsignale = U(6);
                else
                    Schaltsignale = U(sector - 2);
                end
        end
end
end
