Dear fellows,

I have another question concerning the FFT of the GSL. I wanted to start low and tried to transform a sine signal.

Since I assume a data set I take into account real values and a length of any magnitude. Thus I end up with Section 16.7: Mixed - radix FFT routines for real data, am I right?

But to be honest I do not fully grasp between the two methods real_transform and halfcomplex_transform. The first leads to an expected \delta - peak while the second method leads to 'oscillating boundaries'.

Furthermore I am highly confused that the FFT functions only need the data in the sense of the 'values' of a function and not the corresponding x values.

I thought to be quiete familier with the fouriertransform by solving equations with paper and pencil but this GSL implementation is curious.

Can someone give me a little more insight?

In the appendix is a minimal example together with a makefile.

Kind regards,

    Klaus Huthmacher.
/*
main.cpp
*/
#include <fstream>
#include <gsl/gsl_fft_real.h>
#include <gsl/gsl_fft_halfcomplex.h>
#include <iostream>
#include <math.h>
#include <memory>
#include <vector>


int main()
{
	std::fstream f;

	std::vector<double> data;
	
	double const dx = 0.01;

	double x = 0.0;

	while( x <= 2 * M_PI )
	{
		data.push_back( sin( x ) );
		x += dx;
	}

	f.open("data.dat",std::ios::out);

	for(double x : data)
		f << x << std::endl;

	f.close();
	
	std::unique_ptr<gsl_fft_real_wavetable,void(*)(gsl_fft_real_wavetable*)>
		real(gsl_fft_real_wavetable_alloc(data.size()),gsl_fft_real_wavetable_free);

	std::unique_ptr<gsl_fft_real_workspace,void(*)(gsl_fft_real_workspace*)>
		work(gsl_fft_real_workspace_alloc(data.size()),gsl_fft_real_workspace_free);

	std::unique_ptr<gsl_fft_halfcomplex_wavetable,void(*)(gsl_fft_halfcomplex_wavetable*)>
		hc(gsl_fft_halfcomplex_wavetable_alloc(data.size()),gsl_fft_halfcomplex_wavetable_free);

	gsl_fft_real_transform(data.data(),1,data.size(),real.get(),work.get());

	//gsl_fft_halfcomplex_transform(data.data(),1,data.size(),hc.get(),work.get());

	f.open("fft-data.dat",std::ios::out);

	for(double x : data)
		f << x << std::endl;

	f.close();

	return 0;
}
CC=g++
CCOPT=-Wall -pedantic -std=c++11 -c
OPTI=-O2
MAIN=main
LINK=-Wall -pedantic -std=c++11 -o "$(MAIN)" $(MAIN).o
GSL=-lm -lgsl -lgslcblas
$(MAIN): $(MAIN).o
        $(CC) $(LINK) $(OBJ) $(GSL)

%.o: %.cpp
        $(CC) $(CCOPT) $(OPTI) $< 

run:
        ./$(MAIN)

clean:
        rm *.o

<<attachment: huthmacher.vcf>>

Reply via email to