On Thursday, July 21, 2016 at 12:08:19 PM UTC+1, Daniel Mulholland wrote:
>
> I'd like to carry out a discrete fourier transformer on some data but 
> attempts so far have not been successful.
>
> I've been able to do an FFT in the following manner:
>
> def mmag(a):
>     return sqrt(a[0]^2+a[1]^2)
>
> a = FastFourierTransform(4)
> a[0]=0.707
> a[1]=-0.707
> a[2]=-0.707
> a[3]=0.707
> print a
> print a.forward_transform()
> print [mmag(kk) for kk in a]
>
>
> However I don't know how to do the magnitude properly (I tried abs, norm 
> and was not able to get either to work).
>
> However to sort out the DFT:
>
> J = range(4)
> B = [707/1000,-707/1000,-707/1000,707/1000]
> A = [QQ(i) for i in B]
> print A
> s = IndexedSequence(A,J)
> print s.dft()
>
>
> This gives me:
>
> [(0.707, 0.0), (-0.707, 0.0), (-0.707, 0.0), (0.707, 0.0)]
>
> None
>
> [0.0, 1.999697977195556, 0.0, 1.9996979771955563]
>
> [707/1000, -707/1000, -707/1000, 707/1000]
>
> Indexed sequence: [0, -707/500*zeta4 + 707/500, 0, 707/500*zeta4 + 707/500]
>
>     indexed by [0, 1, 2, 3]
>
> Is this the expected result? I was not expecting the zeta4 multiplies and was 
> hoping to get the same result as the FFT above.
>
>
this looks (up to complex conjugation - perhaps x+I*y should be x-I*y) OK:

sage: map(lambda (x,y): x+I*y, a)
[0.0, 1.4139999999999997 + 1.414*I, 0.0, 1.4140000000000001 - 1.414*I]
sage: map(N,s.dft().list())
[0.000000000000000, 1.41400000000000 - 1.41400000000000*I, 
0.000000000000000, 1.41400000000000 + 1.41400000000000*I]

Note that you do DFT in exact arithmetic, this is why you get zeta(4) there.

Dima

 

>
>
> regards
>
> Dan
> -- 
>
> --
> Private or confidential message? Public Key available here 
> <https://pgp.mit.edu/pks/lookup?search=dan.mulholland%40gmail.com&op=index>
> : 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to