x=zeros(1,1000);
Fx=zeros(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
end

for n=1:1:1000
    for k=1:1:20
        Fx(n)=Fx(n)+(2*cos(2*pi*(n-1)*(k-1)*T)*x(k-1))
    end
    end
