2022-05-11 14:13:32 +02:00
|
|
|
# `STFT.jl` - Short-Time Fourier Transform
|
2022-04-27 09:43:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://docs.zymon.org/STFT.jl/)
|
|
|
|
|
2022-05-11 14:13:32 +02:00
|
|
|
`STFT.jl` is a small Julia package implementing just Short-Time Fourier Transform (STFT) routines.
|
|
|
|
It provides the following core functionality:
|
|
|
|
- **_signal analysis_**; transform time-domain signal to STFT-domain signal.
|
|
|
|
- **_signal synthesis_**; transform STFT-domain signal to time-domain signal.
|
2022-04-27 09:43:47 +02:00
|
|
|
|
2022-05-11 14:13:32 +02:00
|
|
|
Check the [documentation](https://docs.zymon.org/STFT.jl/) for more insights.
|
2022-04-27 09:43:47 +02:00
|
|
|
|
2022-05-11 14:13:32 +02:00
|
|
|
## Installation
|
2022-04-27 09:43:47 +02:00
|
|
|
|
2022-06-25 11:31:58 +02:00
|
|
|
The package is currently available in General, the default Julia package registry.
|
|
|
|
To install this package from General registry, use the following command in Julia REPL:
|
|
|
|
```julia
|
|
|
|
] add STFT
|
|
|
|
```
|
|
|
|
Alternatively, directly via repository:
|
2022-04-27 09:43:47 +02:00
|
|
|
```julia
|
2022-05-11 14:13:32 +02:00
|
|
|
pkg> add https://github.com/s-zymon/STFT.jl
|
|
|
|
```
|
2022-04-27 09:43:47 +02:00
|
|
|
|
2022-06-25 11:31:58 +02:00
|
|
|
|
2022-05-11 14:13:32 +02:00
|
|
|
## Examples
|
2022-04-27 09:43:47 +02:00
|
|
|
|
2022-06-25 11:31:58 +02:00
|
|
|
Below you can find a few standalone examples with basic usage of the package.
|
2022-05-11 14:13:32 +02:00
|
|
|
|
|
|
|
### Show spectrogram
|
|
|
|
|
|
|
|
```julia
|
|
|
|
using STFT
|
|
|
|
using Plots
|
|
|
|
|
|
|
|
x = randn(10000) # Generate mock signal
|
|
|
|
W = 64 # Window length
|
|
|
|
w = ones(W) # Rectangular analysis window
|
|
|
|
H = 10 # Hop
|
|
|
|
L = W - H # Overlap
|
|
|
|
|
|
|
|
X = stft(x, w, L) # Analysis
|
|
|
|
s = abs2.(X) # Compute spectrogram
|
|
|
|
heatmap(10log10.(s)) # Display spectrogram
|
|
|
|
```
|
2022-04-27 09:43:47 +02:00
|
|
|
|
2022-05-11 14:13:32 +02:00
|
|
|
### Analyse signal, modify, and synthesise
|
|
|
|
```julia
|
|
|
|
using STFT
|
|
|
|
|
|
|
|
x = randn(10000) # Generate mock signal
|
|
|
|
W = 64 # Window length
|
|
|
|
w = ones(W) # Rectangular analysis window
|
|
|
|
H = 10 # Hop
|
|
|
|
L = W - H # Overlap
|
|
|
|
|
|
|
|
X = stft(x, w, L) # Analysis
|
|
|
|
X = f(X) # Modify STFT-domain signal
|
|
|
|
y = istft(X, w, L) # Synthesis
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively, instead of `using STFT`, you can `import STFT`,
|
|
|
|
and use an alternative API, i.e., `analysis` and `synthesis`.
|
2022-04-27 09:43:47 +02:00
|
|
|
|
2022-05-11 14:13:32 +02:00
|
|
|
```julia
|
|
|
|
import STFT
|
|
|
|
|
|
|
|
x = randm(10000) # Generate mock signal
|
|
|
|
W = 64 # Window length
|
|
|
|
w = ones(W) # Rectangular analysis window
|
|
|
|
H = 10 # Hop
|
|
|
|
L = W - H # Overlap
|
2022-04-27 09:43:47 +02:00
|
|
|
|
2022-05-11 14:13:32 +02:00
|
|
|
X = STFT.analysis(x, w, L) # Analysis
|
|
|
|
X = f(X) # Modify STFT-domain signal
|
|
|
|
y = STFT.synthesis(X, w, L) # Synthesis
|
2022-04-27 09:43:47 +02:00
|
|
|
```
|
2022-05-11 14:13:32 +02:00
|
|
|
|