Naive solution to solve the frequency discontinuity between two concatenated signals.
%matplotlib inline
import matplotlib.pyplot as plt
from IPython.display import Audio
import numpy as np
from _utils import *
fs = 44100
t = np.linspace(-1, 1, 2*fs)
xo = np.sin(2*np.pi*110*t + np.pi*0.5)
xi = np.sin(2*np.pi*215*t)
audiovis(xo, time=t, tlim=[-0.1, 0.1], text='Signal 110 Hz')
audiovis(xi, time=t, tlim=[-0.1, 0.1], text='Signal 210 Hz')
audio mono
audio mono
# heaviside step transition
b = t >= 0
x = (1 - b)*xo + b*xi
audiovis(x, time=t, tlim=[-0.1, 0.1], text='Signal discontinuity | "Heaviside step" transition')
audio mono
Audio(x, rate=fs) # we can hear a 'tic' sound on transition
spectrogram(x, flim=[0, 1000], text='Discontinuity signal spectrogram')
audio mono
Logistic function results in a sigmoidal curve, represented by equation in functions of t: $$ \large f(t)=\frac{L}{1+e^{-k(t - t_0)}} $$
where:
The sigmoid curve will be used as a parameter for a linear interpolation. This process is given by:
$$ \large y=(1 - s)x_o + s x_i $$where s is the sigmoid transition and $\large x_o, x_i$ are the two signal to have the transition.
# logistic function transition
def logisticFunction(t, t0, k, L=1):
return L/(1 + np.exp(-k*(t - t0)))
t0 = 0
k = 256
s = logisticFunction(t, t0, k)
x = (1 - s)*xo + s*xi
audiovis(s, time=t, tlim=[-0.1, 0.1], text='Logistic function | t0 = {0}, k = {1}'.format(t0, k))
audiovis(x, time=t, tlim=[-0.1, 0.1], text='Signal with less discontinuity | transition by logistic function')
audio mono
audio mono
Audio(x, rate=fs) # no 'tic'
spectrogram(x, flim=[0, 1000], text='Less descontinuity spectrogram')
audio mono