Git Product home page Git Product logo

stft's Introduction

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)

stft's People

Contributors

koobh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

stft's Issues

Is possible to generate same result of pytorch stft

Thanks for great work. I want to use this library to mimic pytorch STFT, so that given same signal( wav data ), generate same output. I used test.cpp with same wave file: data/male_1.wav. The output is so different( which I think expected, because parameters even different, like window length and shift length).

For pytorch STFT, code and parameters as following
stft = torch.stft(
x,
self.n_fft,
self.hop_length,
self.win_length,
self.window.to(x.device),
self.center,
self.pad_mode,
self.normalized_stft,
self.onesided,
return_complex=False,
)
n_fft = 400
win_length = 400
hop_length = 160
window function: torch.hamming_window
center: True
pad_mode : "constant"
normalized_stft: False
onesided: True

How hard if I want change this library to make it produce same result as pytorch STFT?

There might be bug in single channel process

    length = input->ReadUnit(buf_in, shift_size * channels);
    stft->stft(buf_in, length, data);

worked.

    input->Convert2Array(raw);
    stft->stft(raw, data);

did not worked.

and output of

    stft->istft(data[0], buf_out);
    output->Append(buf_out, shift_size);

didn't seem right

image

definitely wrong

Bug with frame size that is not power of 2

I was wondering if you could help me to debug the following issue: if I set the frame size that is not a power of 2 I get a segmentation fault on the following line:

w[0] = 1;

For example, if I set the frame size to 320, and the shift size to 160 I get a segmentation fault. Please, could you help me to fix this issue? Any help will be greatly appreciated.

override for stft,istft

need to add

 /* Single-Channel    
      in : 1 x shift
      out : 1 x frame_size + 2 (half FFT with complex)
    */
    inline void stft(short* in, double* out);

for now.

but for more flexible usage need to add more overrides for more types of parameters

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.