Skip to content

Commit

Permalink
fix FFT incorrect output bug. add FFT test.
Browse files Browse the repository at this point in the history
  • Loading branch information
aikiriao committed Sep 22, 2024
1 parent e7ce640 commit ffdb8fc
Show file tree
Hide file tree
Showing 4 changed files with 416 additions and 5 deletions.
10 changes: 5 additions & 5 deletions libs/fft/src/fft.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ static void FFT_ComplexFFT(int n, const int flag, FFTComplex *x, FFTComplex *y)
const int n3 = n1 + n2;
const double theta0 = 2.0 * FFT_PI / n;
FFTComplex j, wdelta, w1p;
j.real = 0.0; j.imag = flag;
wdelta.real = cos(theta0); wdelta.imag = -flag * sin(theta0);
j.real = 0.0; j.imag = -flag;
wdelta.real = cos(theta0); wdelta.imag = flag * sin(theta0);
w1p.real = 1.0; w1p.imag = 0.0;
for (p = 0; p < n1; p++) {
/* より精密 しかしsin,cosの関数呼び出しがある
Expand Down Expand Up @@ -147,13 +147,13 @@ void FFT_FloatFFT(int n, const int flag, double *x, double *y)
void FFT_RealFFT(int n, const int flag, double *x, double *y)
{
int i;
const double theta = -flag * 2.0 * FFT_PI / n;
const double theta = flag * 2.0 * FFT_PI / n;
const double wpi = sin(theta);
const double wpr = cos(theta) - 1.0;
const double c2 = flag * 0.5;
double wr, wi, wtmp;

/* FFTの場合は先に順変換 */
/* FFTの場合は先に変換 */
if (flag == -1) {
FFT_FloatFFT(n >> 1, -1, x, y);
}
Expand All @@ -164,7 +164,7 @@ void FFT_RealFFT(int n, const int flag, double *x, double *y)

/* スペクトルの対称性を使用し */
/* FFTの場合は最終結果をまとめ、IFFTの場合は元に戻るよう整理 */
for (i = 1; i < (n >> 2); i++) {
for (i = 1; i <= (n >> 2); i++) {
const int i1 = (i << 1);
const int i2 = i1 + 1;
const int i3 = n - i1;
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ add_subdirectory(srla_encoder)
add_subdirectory(srla_decoder)
add_subdirectory(srla_encode_decode)
add_subdirectory(lpc)
add_subdirectory(fft)
add_subdirectory(static_huffman)
add_subdirectory(wav)
35 changes: 35 additions & 0 deletions test/fft/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.15)

set(PROJECT_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../..)

# テスト名
set(TEST_NAME fft_test)

# 実行形式ファイル
add_executable(${TEST_NAME} main.cpp)

# インクルードディレクトリ
include_directories(${PROJECT_ROOT_PATH}/libs/fft/include)

# リンクするライブラリ
target_link_libraries(${TEST_NAME} gtest gtest_main)
if (NOT MSVC)
target_link_libraries(${TEST_NAME} pthread)
endif()

# コンパイルオプション
set_target_properties(${TEST_NAME}
PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)

add_test(
NAME fft
COMMAND $<TARGET_FILE:${TEST_NAME}>
)

# run with: ctest -L lib
set_property(
TEST fft
PROPERTY LABELS lib fft
)
Loading

0 comments on commit ffdb8fc

Please sign in to comment.