Browse Search Popular Register Upload Rules User list Login:
Search:
Discrete Fourier Series

Image:
screenshot of the scene

Author: FRA32

Group: Default

Filesize: 52.29 kB

Date added: 2020-01-08

Rating: 6.8

Downloads: 1979

Views: 231

Comments: 6

Ratings: 5

Times favored: 0

Made with: Algodoo v2.1.0

Tags:

Scene tag

After many months and years, I finally fullfill XRay's ironic suggestion: Calculating the Fourier Series of an arbitrary curve!

What is a Fourier Series? It's is a series of sine waves, whose amplitude and initial angle are calculated in such a way that the sum of the waves is a close approximation of some given curve. They allow breaking up any curve into a multitude of frequencies and amplitudes, which is used, amongst other things, in signal processing to seperate a sound into its individual components. In this scene, these sine curves have been split up into cosine- and sine-waves to avoid dealing with the initial angle during calculation.
The difference between a discrete and continuous Fourier series is whether you only calculate using a selected few points(discrete) or from an infinite amount with infinitesimal width(continuous), which requires the curve to be expressable as a combination of equations.

How to use? The primary object in the scene is the area between the two red lasers. This is the active interval. Any curve drawn inside this area will be analysed and the corresponding fourrier series will be calculated. You can move these 2 lasers as long as the dark laser remains on the left side. The Drawing area will be resized accordingly, leaving some excess width to the left and right to display continuity later on. Please do note only the upper edge of your shape will be read, so if you want to read the lower edge, create a negative of your shape and cut away the upper half.

Alternatively, you can make use of the "Formula Mode". Toggle the button for it and edit the green bar's formula using the script menu in the fashion y=f(x). Note that x goes from 0 to 1 as the scanner moves from the left edge to the right edge. This allows you to create the Fourier Series of exact mathematic Formula's as opposed to geometric bodies.

To begin the process, left click the green box at the topleft. After your curve has been scanned and the series been calculated, the various degrees will begin drawing inside the interval, starting at red for the lower frequency and up to magenta for the highest. Additionally, the fourier series itself will be drawn in white. The amplitudes will also be shown in the diagram at the very bottom. A bright dot equals the amplitude of the sine wave, a dark dot the cosine wave, and a large dot the combination of both sine and cosine(the angle of the circle cake equals the initial angle of the combined wave)

You can change the details of the fourrier series using the two text boxes at the top right:

Degree - The amount of frequencies getting calculated. A higher degree means a better resolution with more attention to high frequencies, but also increases required processing power. Default: 50

Sample size - The amount of "samples" being collected for calculation. More samples allows more precise shape analysis, but also increases the time it takes before the calculation finishes. Default: 300

UPDATE: Performed some aesthetic improvements, added Formula mode, fixed some remaining Bugs.
Last edited at 2020/01/09 16:04:43 by FRA32
Please log in to rate this scene
edit
Similar scenes
Title: fourier 1
Rating: 5
Filesize: 6.97 kB
Downloads: 33
Comments: 1
Ratings: 1
Date added: 2019/09/12 13:19:14
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Squaring of the Circle
Rating: 7.3
Filesize: 55.53 kB
Downloads: 367
Comments: 1
Ratings: 10
Date added: 2008/07/12 16:02:31
Made with: Phun
Rating: rated 7.3
download
Title: A new series...
Rating: 5
Filesize: 1.65 MB
Downloads: 255
Comments: 14
Ratings: 1
Date added: 2018/01/28 03:07:58
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Algicosalthon Night 11
Rating: 5
Filesize: 1.21 MB
Downloads: 575
Comments: 8
Ratings: 1
Date added: 2018/09/05 00:16:28
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: New Series + Cancelled Series
Rating: 5
Filesize: 0.81 MB
Downloads: 148
Comments: 4
Ratings: 1
Date added: 2018/07/15 04:00:20
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Rotate the ball 30 (Series 1)
Rating: 5
Filesize: 403.52 kB
Downloads: 293
Comments: 2
Ratings: 1
Date added: 2011/08/28 00:18:29
Made with: Phun
Rating: rated 5
download
Nice work. :tup: Fourier, not Fourrier. See 4ier Series Robot.
Last edited at 2020/01/08 22:04:14 by s_noonan
Huh, I didn't notice you made something similar literally a month ago. Funny timing I guess. Nontheless, I am pretty glad to finally have understood Fourier transformations and series sufficiently enough to make this scene. Who knows, maybe I can figure out how to extend it over to quaternions to look into XRay's 3D-challenge. Would certainly be intriguing.
@The Linkage -- Sorry, had to delete your comment which contains a url to some other web site. The only links allowed are YouTube videos that are directly associated with the user's scene. We needed to do this when someone started promoting porn sites and other garbage links in his comments. Rather than for me to waste my time (and possibly my virginity) by checking out every link that someone posts, we simply do not allow any external links except for YT, as mentioned above.

FRA32 -- I haven't yet checked out your scene, but I am very excited about it. Your math skills are far beyond mine, but I am always ready to learn new things, even if they are so complex that my head starts to split open when trying to understand them.

Concerning my "3D challenge" I was half joking about it, because I don't even know if it's possible. But it surely would be interesting if you can do something like that! :tup:
@FRA32 -- Okay, I played around with it a bit, and I have a couple of comments and questions about it....

1. The first time I ran the scene, the initial image of a waveform that you placed there sort of jumped erratically, and a copy of the curve floated away and bounced around off some of the other objects in the scene. I'm sure that wasn't supposed to happen, but after I deleted your initial curve along with a box with data in it, I then was able to draw my own curves and run the program. Any idea why that happened? It happens each time I start the scene after loading it freshly from Algobox.

2. I tried to draw a sine wave in the time domain with the brush tool, but because of my shaky hand, the sine wave was anything but perfect. I was wondering if the thickness of the brush stroke has any effect on the calculations? What sort of input do you recommend instead of trying to draw waveforms freehand?

3. How many data points does the time domain signal have? Is it changeable with a variable, or is it not user-changeable? If it is changeable, does the number of data point have to be equal to a power of two (as is the case for FFT)?

4. Does this scene actually display a resulting frequency domain plot? If so, can you please explain where and how it is displayed? It doesn't seem to display things in a way that I am used to, and so this scene must be functioning differently than what I expect. The issue is ME not understanding it. It's NOT because of the way you made this scene! LOL

5. Since the input waveform is not continuous, I assume that you had to incorporate a windowing function (Hanning or Hamming?) to handle the end data points. Is that the case or am I (again) not understanding how this calculation functions?

Thanks again for your interesting scenes! :tup:
@Xray
Chances are the preview image box did not self-destruct when the scene was loaded and as such collided with the actual scene content. Sometimes I forget to add the code due to how volatile it is, or perhaps onSpawn doesn't execute properly when loading the scene from algobox.

The thickness does indeed change things a little. At minimum, your drawing is raised by the radius/thickness of the brush. If you draw at an angle, it is raised by radius/cos(angle), so steeper angles raise it more. At outer corners, you also end up with circular segments. If you want precise sine waves, you could trick the program a bit by using a scripted box that spans the entire interval and moves up and down according to your desired formula. This way, instead of measuring shape over position, you measure value over time. I could update the scene to take care of time synchronization and easy customization for this.

The amount of data points is determined by the scene.my.stepcount variable. Increasing it makes the laser move slower, thus increasing the recording time while squeezing the data points closer together.

To the right of the green trigger-box is a diagram with a frequency- and amplitude-axis. When the scan is complete, 3 points per calculated frequency are spawned in this diagram, with the large point being the total amplitude(and phase) per frequency, and the 2 smaller dots being the amplitudes of the wave when split up into phase-0 and phase-90 components(sine and cosine).

The Algorithm used is called Fourier series, which acts by multiplying the given curve by (co) sine waves of some frequency(frequency 1 means 1 cycle over the entire interval), calculating the average across the interval, and multiplying the result by the same (co)sine wave again. This is repeated for all integer frequencies for both sine and cosine and the resulting waves summed up to yield the final function. These individual waves are what the colored boxes draw when the redult is drawn, while the white box draws the sum. As all waves have a period thats some integer fraction of the entire interval, the result behaves the same beyond the interval.
OH YEAH!!! I like the updated scene, especially the waveform plots, much better than it originally was shown. Excellent work! Definitely a TEN rating. :tup: :tup: