x = zeros (1,1000);
Fx =zeros (1,1000);
Fg =zeros (1,2000);
Fk= zeros (1,2000);
h = 0:1:1000;
T=1/1000;
for m=1:1:1000
    h=mod ((m-1),6);
    switch h
        case 0
            x(m)=3
        case 1
            x(m)=2
        case 2
            x(m)=1
        case 3
            x(m)=0
        case 4
            x(m)=1
        case 5
            x(m)=2
    end
    for f=1:1:1000
    Fx(f)=Fx(f)+ 2*cos((f-1)*(m-1)*T);
    Fk(f+999)=Fx(f);
    if (f>1)
    Fg(999-(f-2))=Fx(f);
    end
    end
end
Fk=Fk+Fg;
stem((-999/1000):0.001:1, Fk);
xlabel('alpha');
ylabel('Fourier xk');