Statistical programming, matrix languages, and more

Complex Number and Fast Fourier Transform

Reply
New Contributor
Posts: 2

Complex Number and Fast Fourier Transform

Hello :

I'm new in SAS, for my projet i have to use SAS to compute the FFT vector for a vector x :

let x be a complex vector (size = n), I need to find the vector z (size = n) after a FFT with my vector x.

So I'm looking for an function similar with z=fft(x) in R.

On SAS documentation website, all i can find concerning FFT is these following link :

http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_kde_sect015....

-> theoretical explaination, not exctly what i need

http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/viewer.htm#langref_sect80.htm

-> x here is a NUMERIC vector, so here comes my second question : HOW DO I WORK WITH COMPLEX NOMBER IN SAS ?

-> this function returns a vector of size np*2 with np=floor(n/2+1), i don't understand why its size is not n*2 ?

Thank you for your help Smiley Happy

Oscar C

SAS Super FREQ
Posts: 3,232

Re: Complex Number and Fast Fourier Transform

The FFT function in SAS/IML returns a matrix with two column. The first column is the cosine component (or the real part) and the second column is the sine component (or the imaginary component).

If your data are complex, convert them to a real signal to analyze them SAS. With limited exceptions (eigenvalues, eigenvectors), SAS deals with real numbers.

New Contributor
Posts: 2

Re: Complex Number and Fast Fourier Transform

Thank you Rick.

So FFT in SAS can only deal with real vector.

But I don't know how to convert complex signal to real signal :smileyplain:, it's that possible with some functions in SAS ? I can't find informations on Google about this conversion.

Thank you a lot for your precious help.

Oscar

SAS Super FREQ
Posts: 3,232

Re: Complex Number and Fast Fourier Transform

Perhaps I am not understanding your data. To me, all signals are real. At each time t_i, we measure the amplitude h_i = h(t_i). The discrete Fourier transform converts the function from a finite time series with N data points into frequencies f_i. We then model the (unknown continuous) signal as a sum of sines and cosines with the given frequencies.

Granted, the Fourier transform formulas still make sense if the h_i are chosen to be complex numbers, and mathematicians study this complex transformation, but in the applications that I know of, the h_i are real.  SAS software handles the real case.  If you really want to use complex inputs (whatever that means), you can write h_k = hr_k + i hi_k and the problem splits into two real Fourier transforms.

Super Contributor
Posts: 339

Re: Complex Number and Fast Fourier Transform

My first project here at STC 6 months ago was to translate a spectral theory related code from R to SAS. R has a defined complex type. SAS only has numeric and character variable types. I might be wrong but I did not, at the time, find any way to handle complex numbers naturally in SAS.

As such, I had to breakdown my FFT results into 2 matrices, one real and one complex and manually rebuild all subsequent complex processing steps. E.g. if I I needed to multiply FFTA and FFTB matrix results the code would look like

tempRe=FFTARe*FFTBRe - FFTAIm*FFTBIm;

tempIm=FFTARe*FFTBIm + FFTAIm*FFTBRe;

etc.

Anyway, you see the point. It looked like a big deal at first but aside from reducing code readability and requiring additionnal commenting to group single logical operations together, it went smoothly.

As to answer your question on why the vector is only of size floor(n/2-1). The expected size n vector in R has all the values a+bi and a-bi. Since SAS doesn't support, per say, the complex type, it simply returns a column for a and a column for b. Thus, you can recreate your size n vector by horizontally concatenating FFT[,1]||(-FFT[,2]). The appearent potential truncation has to do with that either even or odd length initial vector will always produce a duplicate (1+0i) value. I can't give more details on the top of my head, it's been too long. Sorry.

Good luck!

Vincent

Post a Question
Discussion Stats
  • 4 replies
  • 1052 views
  • 0 likes
  • 3 in conversation