Skip to content

Instantly share code, notes, and snippets.

View eielsen's full-sized avatar

Arnfinn eielsen

View GitHub Profile
@eielsen
eielsen / thiran_approx.py
Last active September 11, 2025 08:16
Thiran allpass interpolator.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Thiran allpass interpolator.
https://ccrma.stanford.edu/~jos/pasp/Thiran_Allpass_Interpolators.html
@author: Arnfinn Eielsen
@date: 11.09.2025
@license: BSD 3-Clause
@eielsen
eielsen / balreal.py
Last active September 11, 2025 08:15
Balanced realisaton of a stable LTI state-space system.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Balanced realisaton of a stable LTI state-space system.
@author: Arnfinn Eielsen
@date: 06.03.2024
@license: BSD 3-Clause
"""
from scipy import linalg
@eielsen
eielsen / welch_psd.py
Last active June 28, 2024 10:28
Welch power spectral density estimation
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 16 11:30:34 2024
Power spectral density (PSD) estimation using a simplified version of the
Welch method.
@author: Arnfinn Eielsen
@license: BSD 3-Clause
@eielsen
eielsen / fit_sinusoid.py
Last active June 28, 2024 10:28
Method to that attempts to generate rough esimtates of sinusoidal wave parameters before passing them on to the standard curve fitting method in NumPy.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Sinusoidal fitting method with inital value guessing
Created on Tue Feb 6 10:16:47 2024
Method to that attempts to generate rough esimtates of sinusoidal wave
parameters before passing them on to the standard curve fitting method in
NumPy. Initial values have to be reasonably accurate to ensure convergence.
This implements the sinusoidal fitting described in IEEE Std 1658-2011
@eielsen
eielsen / db_to_mag.m
Created May 25, 2017 03:22
Convert from decibels to unscaled real valued magnitude in MATLAB.
function y = db_to_mag(x,type)
% convert from decibels to unscaled real valued magnitude
switch type
case 'pow' % if the input expresses power
y = 10.^(x/10);
case 'mag' % if the input expresses magnitude
y = 10.^(x/20);
otherwise
y = x;
@eielsen
eielsen / sig_fig_str.m
Last active May 25, 2017 01:47
Generate string with specified number of significant figures, and correctly format number string to include trailing zeros in MATLAB.
function num_str = sig_fig_str(num,d)
% Generate string with specified number of significant figures, and
% correctly format number string to include trailing zeros.
m = mod(round(num,d,'significant'),round(num));
num_str = num2str(num,d);
if m == 0 % integer, add dot and trailing zeros
if length(num_str) < d
num_str = [num_str '.'];