ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 27 Oct 2012 04:18:01 +0200Implementing the basic Fourier-Transformationhttps://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/Hi there!
I'm currently plaing around with sage and I'm really excited about it.
I'd love to do my computations at university and home with a neat opensource-tool instead of the higly prices closed competitors.
Now, the problem I am facing is the symbolif computation of a fourier transformation.
Below is my current naive approach (I'm still learning fourier and complex mathematics, but with large interest!)
x,w,f_0,t = var("x,w,f_0,t")
w = 2*pi*f_0
x(t) = sin(w*t)
integrate(x*exp(-I*w*t),t, -oo, oo)
which results in the following (obviously equal) result:
integrate(e^(-2*I*pi*f_0*t)*sin(2*pi*f_0*t), t, -Infinity, +Infinity)
My expectiation would be an equation without the t (since it has been substituted through integration) and an floating f_0 which I can set according to my desired sine frequency.
Please, could someone tell me, what exactly I am missing here?
Greetings
JakobThu, 25 Oct 2012 06:43:37 +0200https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/Answer by koukourikos for <p>Hi there!</p>
<p>I'm currently plaing around with sage and I'm really excited about it.</p>
<p>I'd love to do my computations at university and home with a neat opensource-tool instead of the higly prices closed competitors.</p>
<p>Now, the problem I am facing is the symbolif computation of a fourier transformation.</p>
<p>Below is my current naive approach (I'm still learning fourier and complex mathematics, but with large interest!)</p>
<pre><code>x,w,f_0,t = var("x,w,f_0,t")
w = 2*pi*f_0
x(t) = sin(w*t)
integrate(x*exp(-I*w*t),t, -oo, oo)
</code></pre>
<p>which results in the following (obviously equal) result:</p>
<pre><code>integrate(e^(-2*I*pi*f_0*t)*sin(2*pi*f_0*t), t, -Infinity, +Infinity)
</code></pre>
<p>My expectiation would be an equation without the t (since it has been substituted through integration) and an floating f_0 which I can set according to my desired sine frequency.</p>
<p>Please, could someone tell me, what exactly I am missing here?</p>
<p>Greetings
Jakob</p>
https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/?answer=14190#post-id-14190The integral that you want to calculate it is not so simple because as you can see it evolves the imaginary unit.
I would suggest to define f_0 first and then calculate the integral [numerically ](http://www.sagemath.org/doc/reference/sage/gsl/integration.html).Thu, 25 Oct 2012 07:11:47 +0200https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/?answer=14190#post-id-14190Answer by Dirk Danckaert for <p>Hi there!</p>
<p>I'm currently plaing around with sage and I'm really excited about it.</p>
<p>I'd love to do my computations at university and home with a neat opensource-tool instead of the higly prices closed competitors.</p>
<p>Now, the problem I am facing is the symbolif computation of a fourier transformation.</p>
<p>Below is my current naive approach (I'm still learning fourier and complex mathematics, but with large interest!)</p>
<pre><code>x,w,f_0,t = var("x,w,f_0,t")
w = 2*pi*f_0
x(t) = sin(w*t)
integrate(x*exp(-I*w*t),t, -oo, oo)
</code></pre>
<p>which results in the following (obviously equal) result:</p>
<pre><code>integrate(e^(-2*I*pi*f_0*t)*sin(2*pi*f_0*t), t, -Infinity, +Infinity)
</code></pre>
<p>My expectiation would be an equation without the t (since it has been substituted through integration) and an floating f_0 which I can set according to my desired sine frequency.</p>
<p>Please, could someone tell me, what exactly I am missing here?</p>
<p>Greetings
Jakob</p>
https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/?answer=14107#post-id-14107Not every function *has* a wel defined fourier transform, sin(omega*t) being an example of those. Try transforming a more 'well-behaved' function, such as exp(-a*t^2), or 1/(1+t^2). I didn't check, but I bet SAGE will return a correct answer for those.Thu, 25 Oct 2012 18:39:52 +0200https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/?answer=14107#post-id-14107Answer by Jakob Holderbaum for <p>Hi there!</p>
<p>I'm currently plaing around with sage and I'm really excited about it.</p>
<p>I'd love to do my computations at university and home with a neat opensource-tool instead of the higly prices closed competitors.</p>
<p>Now, the problem I am facing is the symbolif computation of a fourier transformation.</p>
<p>Below is my current naive approach (I'm still learning fourier and complex mathematics, but with large interest!)</p>
<pre><code>x,w,f_0,t = var("x,w,f_0,t")
w = 2*pi*f_0
x(t) = sin(w*t)
integrate(x*exp(-I*w*t),t, -oo, oo)
</code></pre>
<p>which results in the following (obviously equal) result:</p>
<pre><code>integrate(e^(-2*I*pi*f_0*t)*sin(2*pi*f_0*t), t, -Infinity, +Infinity)
</code></pre>
<p>My expectiation would be an equation without the t (since it has been substituted through integration) and an floating f_0 which I can set according to my desired sine frequency.</p>
<p>Please, could someone tell me, what exactly I am missing here?</p>
<p>Greetings
Jakob</p>
https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/?answer=14191#post-id-14191So, as you suggested, I added a numerical Definition for f_0, now I'm getting an error:
x,w,f_0,t = var("x,w,f_0,t")
f_0 = 1
w = 2*pi*f_0
x(t) = sin(w*t)
integrate(x*exp(-I*w*t),t, -oo, oo)
This is the actual result:
Traceback (click to the left of this block for traceback)
...
ValueError: Integral is divergent.Thu, 25 Oct 2012 07:36:41 +0200https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/?answer=14191#post-id-14191Comment by benjaminfjones for <p>So, as you suggested, I added a numerical Definition for f_0, now I'm getting an error:</p>
<pre><code>x,w,f_0,t = var("x,w,f_0,t")
f_0 = 1
w = 2*pi*f_0
x(t) = sin(w*t)
integrate(x*exp(-I*w*t),t, -oo, oo)
</code></pre>
<p>This is the actual result:</p>
<pre><code>Traceback (click to the left of this block for traceback)
...
ValueError: Integral is divergent.
</code></pre>
https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/?comment=18805#post-id-18805That's because the integral is actually divergent. The function $\sin(w t)$ is not integrable on $(-\infty, \infty)$. Sat, 27 Oct 2012 04:18:01 +0200https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/?comment=18805#post-id-18805Comment by Jakob Holderbaum for <p>So, as you suggested, I added a numerical Definition for f_0, now I'm getting an error:</p>
<pre><code>x,w,f_0,t = var("x,w,f_0,t")
f_0 = 1
w = 2*pi*f_0
x(t) = sin(w*t)
integrate(x*exp(-I*w*t),t, -oo, oo)
</code></pre>
<p>This is the actual result:</p>
<pre><code>Traceback (click to the left of this block for traceback)
...
ValueError: Integral is divergent.
</code></pre>
https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/?comment=18817#post-id-18817numerical_integral returns: TypeError: unable to coerce to a real numberThu, 25 Oct 2012 07:39:11 +0200https://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/?comment=18817#post-id-18817