Thursday, December 2, 2010

interleaving two sine waves

when I was doing some experiments on genome design in genetic algorithms, I had a idea of testing the coross-over operator effect on FFTs.

suppose you have two genomes of since waves (all code below are written in python and spyder 2)

x1=array(range(2**10))*2*pi/2**6  (green curve below)

x2=array(range(2**10))*2*pi/2**5  (red curve below )

 

you can do a cross-over operation between them to make a new genome.

x[:-1:2],x[1:-1:2]=x1[:-1:2], x2[1:-1:2] (blue curve below)

and you feed this new genome to your FFT algorithm,

you get the following

image

instead of two spikes (if you just add the two waves), you now have a mirrored the two in to the other end of the FFT spectrum.

quite interesting, I am wondering what would be the effect of having more complex genome operations to the FFT algorithms.

in case you want the plotting code to try it yourself, here it is.

--------------------

subplot(211)

plt.plot(sin(x))

plt.plot(sin(x1))

plt.plot(sin(x2))

subplot(212)

plt.plot(abs(fft(sin(x))))

No comments: