Inspired after seeing a cool Youtube video of Fourier series... How do I implement a Fourier series for an irregular non periodic curve?

11 vues (au cours des 30 derniers jours)
I could understand the model for creating the square wave. I think it is easy too because we have a function to implement the code.
fourier series.png
But, How can one implement a model for a curve which is non periodic which does not have a function?
For example, At the end of the video, it shows a fourier series for a curve like in the picture below, He is definetly using 2 Dimensional fourier transform.
Screenshot (55).png
So, I took time trying to implement the Idea and this is how far I have come.
>>>>>>I took the picture of my profile and traced the edges into 3 ranges and concatenated them into a vector. So, when I create a functon, It can start to trace like shown in the picture below.
ADDY final.png
>>>>>>I thought 2D Fourier transform would be difficult, so I went for 1D first. I tried for implementing the idea for the 3 ranges separately. I used the curve fitting toolbox to approximate the curves.
Range 1.png Range 2.png Range 3.png
>>>>> I used 8 order fourier terms to get the fits as shown on the picture above. 8 was the maximum I could get.
>>>>> For Range 3 the fit was perfect. but for complicated shapes like Range 1, the maximum fit of 8 terms wasn't sufficient.
>>>>> From the picture from youtube, you can see that he goes for more than 40 terms. Then he gets more perfect fit for orders 200 or so..
Finally, how can I get to higher orders inspite of curve fitting tool allows only 8?
Is there any other way that I can approach this problem?
If i could slove this, I have ideas to implement this algorithm scientifically for various other purposes.
Kindly help me regarding this problem.
  3 commentaires
Addy
Addy le 28 Déc 2018
I already have the X and Y coordinates of the edges. I have attached the Data file if you would like to explore. Also, it has the Image matrix.
I understand what you are saying about doing it in an iteration. But I am actually looking for that. I have to learn about it first before implementing. So, Can you possibly link me to any posts/ forums as an example?
Rik
Rik le 28 Déc 2018
I'll try to get you going, but the code below shows what I mean by splitting it into two functions
x=Ranges_Concatenated(:,2);
y=Ranges_Concatenated(:,1);
t=1:numel(x);
figure(1),clf(1)
plot(t,x,'b','DisplayName','x-coordinate')
hold on
plot(t,y,'r','DisplayName','y-coordinate')
legend
I usually use fminsearch, but that tends to have trouble to find a good solution if your initial guess is too far off. Of course you could use fft directly to solve this, but that would be cheating. ;)

Connectez-vous pour commenter.

Réponse acceptée

Rik
Rik le 28 Déc 2018
First I misunderstood it a bit: I just let Matlab figure out the desired wavelenght as well, but that turns out to be quite tricky, and it doesn't work well either. The plots shown below were made with the attached code. The two left plots are only for the x component, but I'm sure the y will show something similar.
result.png
  4 commentaires
Rik
Rik le 28 Déc 2018
You are very welcome.
I wanted to take a shot at it when I saw the video come out, but I never came round to it, so thank you for giving me the final push to try it out (and handing me a usable trace to work with).
The next part should be fun as well: how to animate the circles? If you take a shot at that as well, let me know in a comment here so it shows up in my activity feed.
Addy
Addy le 28 Déc 2018
Hi again!
I succesfully implemented the fft method. I think we can use the fft approach inorder the find the radius of each circle. I have attached the script for fft method. So, each frequency, amplitude and phase from the fft can be formed into a function (A*cos(2*pi*f*t + phase)) and can be used to generate a circle. Finally, I have added the signals of all frequencies to get the Logo. But adding about 200 functions produced good result.
Now that I have the parameters for each circle, I will proceed with animation. I will update if I get some result.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by