/* Returns the power spectra of the ffted data (ie the square of the norm of the complex fourier coefficients. The returned value is a new Dvector of size about two times smaller than the original (precisely size/2 + 1) For some reasons, convolutions don't work for now. */ static VALUE dvector_fft_spectrum(VALUE self) { long len; const double * values = Dvector_Data_for_Read(self, &len); /* First compute the size of the target: */ long target_size = len/2+1; long i; VALUE retval = dvector_new2(target_size,target_size); double * ret = Dvector_Data_for_Write(retval,NULL); /* Pointer to real and imaginary parts */ const double * real; const double * img; ret[0] = values[0] * values[0]; /* The Nyquist frequency */ if(len % 2 == 0) ret[target_size - 1] = values[target_size-1] * values[target_size-1]; for(i = 1, real = values + 1, img = values + len-1; i < len/2; i++, real++, img--) ret[i] = *real * *real + *img * *img; return retval; }