Skip to content

Math FastFourierTransformation

Serge Stinckwich edited this page Jun 26, 2018 · 1 revision

this package is just an adaptation of Squeaks fft package. you can use it eg like this:

"first we construct some data to play with:"
data := (1 to: 11.23 by: 0.01) collect: [:i|i sin + (i *3) cos].
"the data for a FastFourierTransform must have a size of a power of two:"
data size." -->1024"    "that is ok (you'll get an error otherwise, 
when you initialize the FastFourierTransform)"
"lets blur that data a bit:"
blurredData := data collect: [:i|i + Float random -0.5].
"lets have look with Roassal2 (can be found and loaded via 
the Configuration Browser) at our data"
b := RTGrapher new.
ds := RTDataSet new.
ds noDot.
ds points: (1 to: 1024).
ds y: [:i| blurredData at: i].
ds x: #yourself.
ds connectColor: (Color green).
b add: ds.
ds := RTDataSet new.
ds noDot.
ds points: (1 to: 1024).
ds y: [:i| data at: i].
ds x: #yourself.
ds connectColor: (Color blue).
b add: ds.
b

FFT1

"you initialize a FastFourierTransform simply like that:"
f:=FastFourierTransform data:blurredData.
"and do the transform:"
f transform.
"lets have look at the transform:"
a := RTGrapher new.
ds := RTDataSet new.
ds noDot.
ds points: (1to:1024).
ds y: [:i|f imaginaryData at:i].
ds x: #yourself.
ds connectColor: (Color blue).
a add: ds.
ds := RTDataSet new.
ds noDot.
ds points: (1to:1024).
ds y: [:i|f realData at:i].
ds x: #yourself.
ds connectColor: (Color red).
a add: ds.
a build.
a view openWithMenu .

fftf2

"the boring part is obviously in the middle, lets have
 a more detailed look at this part:"
a := RTGrapher new.
ds := RTDataSet new.
ds noDot.
ds points: (14to:1010).
ds y: [:i|f imaginaryData at:i].
ds x: #yourself.
ds connectColor: (Color blue).
a add: ds.
ds := RTDataSet new.
ds noDot.
ds points: (14to:1010).
ds y: [:i|f realData at:i].
ds x: #yourself.
ds connectColor: (Color red).
a add: ds.
a build.
a view openWithMenu .

fft3

"it seems that the boring part is within a +-0.75 range.
we simply set that part to zero"
f chop:0.75.
"and then do an inverse transform:"
f inverseTransform.
"now lets see what we got as a smoothed form of the blurred data:"
ds := RTDataSet new.
ds noDot.
ds points: (1to:1024).
ds y: [:i|f realData at:i].
ds x: #yourself.
ds connectColor: (Color red).
b add: ds.
b build.
b view open.

fft4