help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with fourier transform


From: Glenn Golden
Subject: Re: Problem with fourier transform
Date: Wed, 05 May 2004 10:13:43 -0600

"Antonio L." writes:
> 
> Hello, I have a problem dealing with fourier transform in octave.
> How is it possible to recover the value of a discrete periodic
> function, given its fourier armonics coeficients?
> I tried something like this:
> 
> -------- code ------------
> y = [1,2,3,4,5]';     # original function
> z = fftshift(fft(y)); # armonics
> 
> # given an integer value of x like -2,-1,0,1,2,3,4,5,6,....
> x = <integer value>;
> 
> # we would get y(x) with this expression
> y_x = sum(z.*exp((-2:2)'*i*pi*x/rows(z)))
> ------ end code ----------
> 
> But it doesn't give us even close original values of y suposed
> value i for x will give us i-th value from vector y.
> What am I doing wrong? Is it suposed to wortk other way octave
> fourier series?.
> 
> And what about the two dimentional case, in wich y is a general
> matrix and z = fft2(y)? whould there be a similar way of finding
> original function values?
> 

Later, "Antonio L." writes:

> That is, without using ifft(z). Because the idea is to compute real
> values of y between its discrete elements.
>


I'm not sure I understand why you don't want to use the inverse
transform rather than writing out the Fourier series summation
explicitly.  Seems like you could get what you want by using ifft()
like this:


    y = [99 88 77 66 55];       # Original time series
    y_period = length(y);       # Period of y
    z = fft(y);                 # Transform domain representation of y
    x = -2:6;                   # Set of desired 0-origin indices into the
                                # original time series (i.e. y(0) = 99).
    tsz = real(ifft(z));        # tsz is one period of original time series.
    tsz(1+mod(x,y_period))      # Indices into tsz are taken modulo the
                                # period of the original time series, so
                                # you can index from -inf to +inf.

    ans =

      66.000  55.000  99.000  88.000  77.000  66.000  55.000  99.000  88.000


Note that the computation of tsz above assumes that y is known to be real;
taking the real part of ifft(z) just ensures that you won't wind up with
any floating point fuzz on the imaginary part.

The above is equivalent to the explicit computation

     real((1/N) * sum(z .* exp(J * 2 * pi * x * (0:N-1) / N)))

where N = length(y), and x is the desired zero-origin index into the
original time series y.

Glenn Golden



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]