Skip to content

Instantly share code, notes, and snippets.

View andres-fr's full-sized avatar

Andres Fernandez andres-fr

View GitHub Profile
@andres-fr
andres-fr / overlap_save_convolver.cpp
Last active August 2, 2021 11:03
C++ spectral convolution of 1D signals (OpenMP+FFTW)
// OverlapSaveConvolver: A small C++11 single-file program that performs
// efficient 1D convolution and cross-correlation of two float arrays.
// Copyright (C) 2017 Andres Fernandez (https://github.com/andres-fr)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
@andres-fr
andres-fr / hsv_histogram.py
Created October 18, 2021 01:49
Python script to plot a 3-dimensional HSV histogram from a color image.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
HSV image histogram script.
"""
import os
@andres-fr
andres-fr / wiener_deconv.py
Last active January 12, 2022 20:02
Wiener deconvolution study
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Wiener deconvolution study.
Copyright (C) 2021 aferro (ORCID: 0000-0003-3830-3595)
This program is free software: you can redistribute it and/or modify
@andres-fr
andres-fr / plot_complex.py
Created February 1, 2022 22:47
Interactive 3D plot of complex signals for visual inspection
#!/usr/env/bin python
# -*- coding:utf-8 -*-
"""
Interactive plot for visual inspection:
Complex vectors are plotted as lines on a 3D space, such that 2 dimensions are
the real and imaginary components, and the third dimension goes through the
vector values (could be e.g. time or frequency).
@andres-fr
andres-fr / jax_inv_sampling.py
Created February 23, 2022 00:28
Inverse regular sampling from a black-box function using JAX+SGD with momentum
import jax.numpy as jnp
from jax import jit, value_and_grad
from jax.config import config
config.update("jax_debug_nans", True)
class RegularInv1dSampler:
"""
This regular inverse sampler deals with the following problem: given a
smooth function ``y=f(x)`` for ``x`` scalar and ``y`` n-dimensional,
retrieve ``N`` monotonically increasing values of ``x``, such that the
@andres-fr
andres-fr / wav_to_mel.py
Created May 13, 2022 13:04
Flexible and efficient conversion from mono WAV to log-mel spectrogram
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
"""
import librosa
import numpy as np
@andres-fr
andres-fr / incremental_hdf5.py
Last active May 13, 2022 15:02
Incrementally concatenate matrices of same height into a HDF5 database efficiently.
#!/usr/bin python
# -*- coding:utf-8 -*-
"""
"""
import numpy as np
import h5py
@andres-fr
andres-fr / salsa_features.py
Created February 17, 2022 00:36
On-the-fly CPU computations of the SALSA and SALSA-Lite features for multi-microphone audio source localization.
#!/usr/env/bin python
# -*- coding:utf-8 -*-
"""
This module extracts salsa-related features on-the-fly (CPU).
Inspired by the original SALSA implementation:
github.com/thomeou/SALSA/blob/master/dataset/salsa_lite_feature_extraction.py
(MIT License)
@andres-fr
andres-fr / bfs.py
Created June 12, 2022 19:30
Pixel-wise breadth-first search that not only traverses pixels but also returns the corresponding tree. Includes convenience functions.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Most existing breadth-first search implementations provide a solution to
*traverse* a tree, but they don't *return* that specific tree. This module
provides a tree datastructure and BFS implementation to obtain the BFS tree.
"""
@andres-fr
andres-fr / bash_default_named_params.sh
Last active June 17, 2022 23:07
Example of a bash function with named parameters+defaults
interactive_gpu()
{
# needed by getopt: https://stackoverflow.com/a/5048356
local OPTIND
# default parameter values
seconds=300
partition="large"
# parse flags to optionally override param defaults