Skip to content

kooBH/STFT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STFT

STFT(Short Time Fourier Transform), ISTFT(Inverse - Short Time Fourier Transform) for wav,mic input

provides 25%,50% overlap STFT process.
Using DFT, iDFT when n_fft(frame_size) is not power of 2.

NOTE

git clone --recursive https://github.com/kooBH/STFT.git

To build test code you need to clone --recursive to use submodule koobh/WAV.git If you already cloned, then,

git submoudle init
git submodule update

to use submodule.

About FFT

I'm currently using FFT of Ooura.
Since, it is fastest FFT in a single header file.
But, sometimes (usually not), there are errors between MATLAB FFT output and Ooura FFT output.
If you need to perfectly same output as MATLAB, you have to use other FFT library.

CMake

...
set(SRC)
set(INCL)

# it will append sources and paths to SRC and INCL
include(${PATH_TO_STFT}/STFT/cpp/STFT_cpp.cmake )  

...

add_executable(${PROJECT_NAME} ${SRC})
target_include_directories(${PROJECT_NAME}    PRIVATE    ${INCL}  )

EXAMPLE

  • Directly from buffer
#include "cpp/STFT.h"

...

// frame/shift must be 4 or 2
STFT process(channels,frame_size,shift_size);
WAV input;
WAV output(channels,sample_rate);
input.OpenFile('input.wav');

short* buf_in; //[channels * shift_size]
double **data; //[channels][frame_size]
short* buf_out; //[channels * shift_size]

while(!input.IsEOF()){
    length = input.ReadUnit(buf_in,shift*channels);
    process.stft(buf_in,length,data);
    process.istft(data,buf_out);
    output.Append(buf_out,shift*channels);
  }
  • From 2D array
#include "cpp/STFT.h"

...

// frame/shift must be 4 or 2
STFT process(channels,frame_size,shift_size);
WAV input;
WAV output(channels,sample_rate);
input.OpenFile('input.wav');

double **raw; //[channels][shift_size]
double **data; //[channels][frame_size]
short* buf_out; //[channels * shift_size]

while(!input.IsEOF()){
    input.Convert2Array(raw);
    process.stft(raw,data);
    process.istft(data,buf_out);
    output.Append(buf_out,shift*channels);
  }

STATUS

C : only STFT is implemented, iSTFT is not implemented yet
C++ : verified (same output as MATLAB routine)