壹: fft在数字信号处理领域是一个神一样的存在。要好好熟悉一下。这里给出频移的算法源码解析。 所谓的频移,就是把数字信号的频频顺序打乱,移动一些。这个在防止啸叫和辅听领域应用十分广泛。 贰: 这个源码不是很复杂,这里直接给出一个仿真源码:
#include <stdio.h> #include <math.h> typedef short spx_int16_t; typedef spx_int16_t spx_word16_t; void dump16(spx_word16_t *data,short len) { for (short i = 0; i < len; i++) { /* code */ printf("%d,",data[i]); } printf("\n\r"); } void swap(spx_int16_t *v1, spx_int16_t *v2) { spx_int16_t tmp = *v1; *v1 = *v2; *v2 = tmp; } void fftshift(spx_int16_t *data, int count) { int k = 0; int c = (int) floor((float)count/2); // For odd and for even numbers of element use different algorithm if (count % 2 == 0) { for (k = 0; k < c; k++) swap(&data[k], &data[k+c]); } else { spx_int16_t tmp = data[0]; for (k = 0; k < c; k++) { data[k] = data[c + k + 1]; data[c + k + 1] = data[k + 1]; } data[c] = tmp; } } void ifftshift(spx_int16_t *data, int count) { int k = 0; int c = (int) floor((float)count/2); if (count % 2 == 0) { for (k = 0; k < c; k++) swap(&data[k], &data[k+c]); } else { spx_int16_t tmp = data[count - 1]; for (k = c-1; k >= 0; k--) { data[c + k + 1] = data[k]; data[k] = data[c + k]; } data[c] = tmp; } } int main() { spx_int16_t array[8] = {1,2,3,4,5,6,7,8}; printf("before the fftshift is:\n\r"); dump16(array,8); fftshift(array,8); printf("after the fftshift is:\n\r"); dump16(array,8); return 0; }叁: 上面的结果是:
before the fftshift is: 1,2,3,4,5,6,7,8, after the fftshift is: 5,6,7,8,1,2,3,4,标签:spx,count,int16,int,频移,fft,fftshift,源码,data From: https://www.cnblogs.com/dylancao/p/17088478.html