% Teste

clear all
clc
close all

for n=0:3
    F1=[];
    F2=[];
    for w=-0.99*pi : 0.01 : 0.99*pi
        
        fase1=angle(j*exp(-j*w/2)*sin(w/2)*exp(j*w*n));
        F1 = [F1,fase1];
        
%         fase2=pi-0.5*pi*(w/abs(w))-0.5*w+w*n;
        fase2=0.5*pi*(w/abs(w))-0.5*w+w*n;
        if fase2>pi
            fase2 = fase2-2*pi;
        elseif fase2<-pi
            fase2 = fase2+2*pi;
        end
        F2 = [F2,fase2];
        
    end
    w=-0.99*pi:0.01:0.99*pi;
    
    figure
    plot(w,F1)
    hold on
    plot(w,F2,'r--')
    axis([-1.1*pi,1.1*pi,-inf,inf])
    xlabel('w')
    ylabel('\phi(y[n])')
    titulo = strcat(['n = ',num2str(n)]);
    title(titulo)
end

    