FFT and reconstruct

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

FFT and reconstruct

yellowhat
Hi all,
I am trying to understand how FFT work, so I wrote the attached script.
The idea is to extract amplitude and phase of a signal and then reconstruct using amplitude and phase information.
As you can see, I create some cosine curve on the interval t0-t1.
Let's start with t0=1.0 and t1=3.0 and consider just y['1'] = cos(1.0*omega*t), the signal is.
Immagine incorporata 1
The amplitude and phase for each order are:
Immagine incorporata 2
But if I try to reconstruct the signal using amplitude and phase:
Immagine incorporata 3
So as you can see there is a shifting of 180 deg.

Now let's consider another case, t0=2 and t1=3, the signal is 
y['Signal'] = 1.0*cos(1.0*omega*t) + 2.0*cos(2.0*omega*t) + 3.0*cos(3.0*omega*t + pi/4) + 4.0*cos(4.0*omega*t) + 5.0*cos(5.0*omega*t) + 1.0
The reconstructed signal is very similar to the initial one:
Immagine incorporata 4
but is not exactly the same.
Any advice?

Thanks



_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/numpy-discussion

FFT.py (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: FFT and reconstruct

Feng Yu
Hi Vasco,

It looks slightly strange that you are using cos instead of exp in the reconstruction of the signal.

I'd recommend you take a look at http://docs.scipy.org/doc/numpy-1.10.1/reference/routines.fft.html

Also the documents of fftfreq, fftshift, and ifft.

Best,

- Yu

On Sat, May 14, 2016 at 6:27 AM, Vasco Gervasi <[hidden email]> wrote:
Hi all,
I am trying to understand how FFT work, so I wrote the attached script.
The idea is to extract amplitude and phase of a signal and then reconstruct using amplitude and phase information.
As you can see, I create some cosine curve on the interval t0-t1.
Let's start with t0=1.0 and t1=3.0 and consider just y['1'] = cos(1.0*omega*t), the signal is.
Immagine incorporata 1
The amplitude and phase for each order are:
Immagine incorporata 2
But if I try to reconstruct the signal using amplitude and phase:
Immagine incorporata 3
So as you can see there is a shifting of 180 deg.

Now let's consider another case, t0=2 and t1=3, the signal is 
y['Signal'] = 1.0*cos(1.0*omega*t) + 2.0*cos(2.0*omega*t) + 3.0*cos(3.0*omega*t + pi/4) + 4.0*cos(4.0*omega*t) + 5.0*cos(5.0*omega*t) + 1.0
The reconstructed signal is very similar to the initial one:
Immagine incorporata 4
but is not exactly the same.
Any advice?

Thanks



_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/numpy-discussion



_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: FFT and reconstruct

yellowhat
I would like to use cos, to reconstruct the signal, to verify phase angle.
I will try ifft.

Thanks,

2016-05-16 8:46 GMT+02:00 Feng Yu <[hidden email]>:
Hi Vasco,

It looks slightly strange that you are using cos instead of exp in the reconstruction of the signal.

I'd recommend you take a look at http://docs.scipy.org/doc/numpy-1.10.1/reference/routines.fft.html

Also the documents of fftfreq, fftshift, and ifft.

Best,

- Yu

On Sat, May 14, 2016 at 6:27 AM, Vasco Gervasi <[hidden email]> wrote:
Hi all,
I am trying to understand how FFT work, so I wrote the attached script.
The idea is to extract amplitude and phase of a signal and then reconstruct using amplitude and phase information.
As you can see, I create some cosine curve on the interval t0-t1.
Let's start with t0=1.0 and t1=3.0 and consider just y['1'] = cos(1.0*omega*t), the signal is.
Immagine incorporata 1
The amplitude and phase for each order are:
Immagine incorporata 2
But if I try to reconstruct the signal using amplitude and phase:
Immagine incorporata 3
So as you can see there is a shifting of 180 deg.

Now let's consider another case, t0=2 and t1=3, the signal is 
y['Signal'] = 1.0*cos(1.0*omega*t) + 2.0*cos(2.0*omega*t) + 3.0*cos(3.0*omega*t + pi/4) + 4.0*cos(4.0*omega*t) + 5.0*cos(5.0*omega*t) + 1.0
The reconstructed signal is very similar to the initial one:
Immagine incorporata 4
but is not exactly the same.
Any advice?

Thanks



_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/numpy-discussion



_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/numpy-discussion



_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: FFT and reconstruct

yellowhat
Maybe I found the problems;

1. t0=1.0, t1=3.0, y['1'] = cos(1.0*omega*t): I have to reconstruct the signal using
 yRec += a * cos(omega*i*(t-t0) + f)
not
 yRec += a * cos(omega*i*t + f)

2.  t0=2, t1=3, y['Signal'] = 1.0*cos(1.0*omega*t) + ... + 5.0*cos(5.0*omega*t) + 1.0: starting point and end point must not be the same, so to generate the signal I have to use
t = linspace(t0, t1, 1000, endpoint=False)
not
t = linspace(t0, t1, 1000)

Thanks

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/numpy-discussion