Tag: fftw

在C中使用FFTW的高通滤波器

我有一个关于FFT的问题。 我已经设法在C中使用FFTW向前和向后进行FFT。现在,我想应用高通滤波器进行边缘检测,我的一些消息来源说只是将幅度的中心归零。 这是我的输入图片http://sofzh.miximages.com/c/2wnxvfl.jpg 基本上我所做的是: 正向FFT 将输出转换为2D数组 进行FFT移位 当距离中心的距离为高度的25%时,将real和imag值设为0 产生幅度 进行反向FFT移位 转换为1D数组 做后向FFT。 这是原始幅度,处理幅度和结果 http://sofzh.miximages.com/c/aysx9s.png 有人可以帮助我,告诉我哪个部分是错的,以及如何在C中使用FFTW进行高通滤波 谢谢。 源代码: unsigned char **FFT2(int width,int height, unsigned char **pixel, char line1[100],char line2[100], char line3[100],char filename[100]) { fftw_complex* in, * dft, * idft, * dft2; //fftw_complex tmp1,tmp2; fftw_plan plan_f,plan_i; int i,j,k,w,h,N,w2,h2; w = width; h = height; N = w*h; […]

用FFTW计算音频数据的离散傅里叶变换

我对信号处理很陌生,所以请原谅我,如果我吵了一下。 我已经下载并安装了适用于Windows的FFTW。 文档还可以,但我仍然有疑问。 我的总体目标是从计算机上的声卡中捕获以44100采样/秒采样的原始音频数据(此任务已使用库和我的代码实现),然后对此音频数据块执行DFT。 我只对在音频中找到一系列频率成分感兴趣,而且我不会执行任何逆DFT。 在这种情况下,所有必要的是真实到真实的转换,因此fftw_plan_r2r_1d()函数? 我要转换的数据块长度为11025个样本。 我的函数调用如下所示。 这将产生11025个频段的频谱arrays。 我如何知道结果中的最大频率成分? 我相信bin间距是Fs / n,44100/11025,所以4.这是否意味着我将在arrays中从0 Hz一直到44100Hz,步长为4,或者高达一半的频谱奈奎斯特频率22200? 这对我来说是一个问题,因为我只想搜索60Hz到3000Hz的频率。 有没有办法限制变换范围? 我没有看到该函数的任何参数,或者可能还有另一种方法? 非常感谢您提供任何帮助。 p = fftw_plan_r2r_1d(11025, audioData, spectrum, FFTW_REDFT00, FFTW_ESTIMATE);

在系统verilog代码中集成fftw C函数调用

我在linux系统上成功安装了fftw C库。 以下是有关fftw c => http://www.fftw.org/的更多信息。我有一个示例C代码,可以成功调用fftw C函数。 下面是一个C ccode和命令来运行C代码:代码: #include #include #include #include #include int main(void) { double FFT_in[] = {0.1, 0.6, 0.1, 0.4, 0.5, 0, 0.8, 0.7, 0.8, 0.6, 0.1,0}; double *IFFT_out; int i,size = 12; fftw_complex *middle; fftw_plan fft; fftw_plan ifft; middle = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*size); IFFT_out = (double *) malloc(size*sizeof(double)); fft = fftw_plan_dft_r2c_1d(size, […]

如何在FFTW库中实现逆实数FFT

我正在尝试用FFT进行一些过滤。 我正在使用r2r_1d计划,我不知道如何进行逆变换… void PerformFiltering(double* data, int n) { /* FFT */ double* spectrum = new double[n]; fftw_plan plan; plan = fftw_plan_r2r_1d(n, data, spectrum, FFTW_REDFT00, FFTW_ESTIMATE); fftw_execute(plan); // signal to spectrum fftw_destroy_plan(plan); /* some filtering here */ /* Inverse FFT */ plan = fftw_plan_r2r_1d(n, spectrum, data, FFTW_REDFT00, FFTW_ESTIMATE); fftw_execute(plan); // spectrum to signal (inverse FFT) fftw_destroy_plan(plan); […]

使用FFTW为架构x86_64取消定义符号

Ceeloss-MacBook-Pro:desktop ceelos$ gcc -o prog -I/usr/local/include test.c Undefined symbols for architecture x86_64: “_fftw_destroy_plan”, referenced from: _main in test-IBqBdS.o “_fftw_execute”, referenced from: _main in test-IBqBdS.o “_fftw_plan_dft_1d”, referenced from: _main in test-IBqBdS.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Ceeloss-MacBook-Pro:desktop ceelos$ 这告诉我什么?

无法链接到fftw3库

我正在编译测试程序以测试fftw3(ver3.3.4)。 由于它没有安装root previlidge,我使用的命令是: gcc -lm -L/home/my_name/opt/fftw-3.3.4/lib/ -I/home/my_name/opt/fftw-3.3.4/include/ fftwtest.c 安装库的位置 /home/my_name/opt/fftw-3.3.4/ 我的代码是fftw3网站上的第一个教程: #include #include int main(){ int n = 10; fftw_complex *in, *out; fftw_plan p; in = (fftw_complex*) fftw_malloc(n*sizeof(fftw_complex)); out = (fftw_complex*) fftw_malloc(n*sizeof(fftw_complex)); p = fftw_plan_dft_1d(n, in, out, FFTW_FORWARD, FFTW_ESTIMATE); fftw_execute(p); /* repeat as needed */ fftw_destroy_plan(p); fftw_free(in); fftw_free(out); return 0; } 当我编译程序时它会返回以下错误: /tmp/ccFsDL1n.o: In function […]

FFTW:前向fft的反向不等于原始函数

我正在尝试使用FFTW来计算快速求和,我遇到了一个问题: int numFreq3 = numFreq*numFreq*numFreq; FFTW_complex* dummy_sq_fft = (FFTW_complex*)FFTW_malloc( sizeof(FFTW_complex)*numFreq3 ); FFTW_complex* dummy_sq = (FFTW_complex*)FFTW_malloc( sizeof(FFTW_complex)*numFreq3 ); FFTW_complex* orig = (FFTW_complex*)FFTW_malloc( sizeof(FFTW_complex)*numFreq3 ); FFTW_plan dummyPlan = FFTW_plan_dft_3d( numFreq, numFreq, numFreq, orig, dummy_sq_fft, FFTW_FORWARD, FFTW_MEASURE ); FFTW_plan dummyInvPlan = FFTW_plan_dft_3d( numFreq, numFreq, numFreq, dummy_sq_fft, dummy_sq, FFTW_BACKWARD, FFTW_MEASURE ); for(int i= 0; i < numFreq3; i++) { […]

向前FFT FFT图像并向后FFT图像以获得相同的结果

我正在尝试使用来自http://www.fftw.org/的库来对图像进行FFT,以便我可以在频域中进行卷积。 但我无法弄清楚如何让它发挥作用。 为了理解如何做到这一点,我试图将FFT图像作为像素颜色数组转发,然后反向FFT,得到相同的像素颜色数组。 这是我做的: fftw_plan planR, planG, planB; fftw_complex *inR, *inG, *inB, *outR, *outG, *outB, *resultR, *resultG, *resultB; //Allocate arrays. inR = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * width * width); inG = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * width * width); inB = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * width * width); outR = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * width * width); outG = (fftw_complex*) […]

PSD使用FFTW Halfcomplex变换

我问了一个类似的问题,这个问题得到了解答,但当我尝试按照自己的方式进行操作时,我会得到“奇怪的”值。 我想得到一个sin波的PSD使用半复数变换,如: #include #include #include #include #include #define PI 3.141592653589793 int main (){ double* inputValues; double* outputValues; double realVal; double imagVal; double powVal=0.0; double absVal; double timer; fftw_plan plan; double timeIntervall= 1.0; // 1sec int numberOfSamples =512; double timeSteps = timeIntervall/numberOfSamples; float frequency=10.0; float dcValue = 0.2; float value=0.0; int index=0; // allocating the memory […]

计算功率谱密度

我试图通过使用fftw3库来获取真实数据集的PSD为了测试我写了一个如下所示的小程序,它产生一个遵循正弦函数的信号 #include #include #define PI 3.14 int main (){ double value= 0.0; float frequency = 5; int i = 0 ; double time = 0.0; FILE* outputFile = NULL; outputFile = fopen(“sinvalues”,”wb+”); if(outputFile==NULL){ printf(” couldn’t open the file \n”); return -1; } for (i = 0; i<=5000;i++){ value = sin(2*PI*frequency*zeit); fwrite(&value,sizeof(double),1,outputFile); zeit += (1.0/frequency); } […]