# Discrete Fourier Transform: GeoGebra logo

θ = Slider(-pi, pi, 0.01, 1, 140, false, true, false, false) kMax = Slider(1, 98, 1, 1, 140, false, true, false, false) #Execute(Sequence("", i, 1, m)) ##Set the number of points for approximating the curve. The bigger the number the more complex the curve can be ## m=197 ##Create Points: I need sliders so the points can be changed by user## Execute(Sequence("XP"+i+" = Slider(-300, 300, 0.01, 1, 130, false, true, false, false)", i, 1, m)) Execute(Sequence("YP"+i+" = Slider(-300, 300, 0.01, 1, 130, false, true, false, false)", i, 1, m)) Execute(Sequence("SetValue(XP"+i+", A"+i+")", i, 1, m)) Execute(Sequence("SetValue(YP"+i+", B"+i+")", i, 1, m)) Execute(Sequence("SetVisibleInView(XP"+i+", 1, false)", i, 1, m)) Execute(Sequence("SetVisibleInView(YP"+i+", 1, false)", i, 1, m)) Polygonal = true SetVisibleInView(Polygonal, 1, false) SetVisibleInView(Polygonal, 2, true) Execute(Sequence("P"+i+" = (XP"+i+", YP"+i+")", i, 1, m)) Execute(Sequence("SetConditionToShowObject(P"+i+", Polygonal)", i, 1, m)) Execute(Sequence("ShowLabel(P"+i+", false)", i, 1, m)) listP = P1:P197 size = Length(listP) n = (size - 1)/2 ##This will be used for the Discrete Fourier Series## listT = Sequence(2π k / (2n + 1), k, 0, 2n) ##This slider is for showing a number of orbits. In this case, the number of orbits is 2 times kMax## ##I need to divide the list of points determined by their position: Positive and Negative## listPPos = Sequence(Element(listP, k), k, (size + 1) / 2 + 1, size) SetVisibleInView(listPPos, 1, false) listPNeg = Sequence(Element(listP, k), k, 1, (size + 1) / 2 - 1) SetVisibleInView(listPNeg, 1, false) ##Not sure why I need this T## T = Element(listT, (size + 1) / 2) ##Here we find the constants in the Discrete Fourier transform## listC = Sequence(Sum(Sequence(((cos(k Element(listT, l)) x(Element(listP, l)) + sin(k Element(listT, l)) y(Element(listP, l))) / size, (cos(k Element(listT, l)) y(Element(listP, l)) - sin(k Element(listT, l)) x(Element(listP, l))) / size), l, 1, size)), k, -n, n) SetVisibleInView(listC, 1, false) listCPos = Sequence(Element(listC, k), k, (size + 1) / 2 + 1, size) SetVisibleInView(listCPos, 1, false) listCNeg = Reverse(Sequence(Element(listC, k), k, 1, (size + 1) / 2 - 1)) SetVisibleInView(listCNeg, 1, false) C = Element(listC, (size + 1) / 2) xC = x(C) yC = y(C) fx(x) = Sum(Sequence(cos(k x) x(Element(listCPos, k)) - sin(k x) y(Element(listCPos, k)) + cos(-k x) x(Element(listCNeg, k)) - sin(-k x) y(Element(listCNeg, k)), k, 1, kMax)) SetVisibleInView(fx, 1, false) fy(x) = Sum(Sequence(cos(k x) y(Element(listCPos, k)) + sin(k x) x(Element(listCPos, k)) + cos(-k x) y(Element(listCNeg, k)) + sin(-k x) x(Element(listCNeg, k)), k, 1, kMax)) SetVisibleInView(fy, 1, false) Curve = true SetVisibleInView(Curve, 1, false) SetVisibleInView(Curve, 2, true) path = Curve(x(C) + fx(t), y(C) + fy(t), t, -3.14159, π) SetConditionToShowObject(path, Curve) listCOrd = Join(Sequence({Element(listCPos, k), Element(listCNeg, k)}, k, 1, n)) SetVisibleInView(listCOrd, 1, false) listCRho = Sequence(Length(Element(listCOrd, k)), k, 1, size - 1) listCAng = Sequence(Angle(Element(listCOrd, k)), k, 1, size - 1) ##I need to create a list of numbers in order to have a specific order to create the orbits. This order is not unique. listHelp = Sequence((Length(Element(listCOrd, k)); Angle(Element(listCOrd, k))), k, 1, size - 1) SetVisibleInView(listHelp, 1, false) sortHelper = Reverse(Sort(Sequence((Length(Element(listHelp, i)), i), i, 1, Length(listHelp)))) SetVisibleInView(sortHelper, 1, false) listSorted = Sequence(y(Element(sortHelper, i)), i, 1, Length(sortHelper)) #Reverse(Sequence(Element(listHelp, y(Element(sortHelper, i))), i, 1, Length(listHelp))) listK = Join(Sequence({k, -k}, k, 1, n)) Orbits = false SetVisibleInView(Orbits, 1, false) SetVisibleInView(Orbits, 2, true) #Centers of orbits listCenters = Join({{C}, Sequence(C + Sum(Sequence((Element(listCRho, Element(listSorted, r)) cos(Element(listCAng, Element(listSorted, r)) + Element(listK, Element(listSorted, r)) θ), Element(listCRho, Element(listSorted, r)) sin(Element(listCAng, Element(listSorted, r)) + Element(listK, Element(listSorted, r)) θ)), r, 1, l)), l, 1, 2kMax)}) SetConditionToShowObject(listCenters, Orbits) P = Element(listCenters, 2*kMax + 1) Play = false SetVisibleInView(Play, 1, false) SetVisibleInView(Play, 2, true) listCircles = Sequence(Circle(Element(listCenters, k), Element(listCRho, Element(listSorted, k))), k, 1, 2*kMax) SetConditionToShowObject(listCircles, Orbits) #Radii listS = Sequence(Segment(Element(listCenters, k), Element(listCenters, k + 1)), k, 1, 2*kMax) SetConditionToShowObject(listS, Orbits) #Polygonal curve listPC = Sequence(Segment(Element(listP, u), Element(listP, Mod(u, size) + 1)), u, 1, size) SetConditionToShowObject(listPC, Polygonal)