I am working on real time Room Impulse Response estimation using sine sweep.
- $x(n)$ is my sine sweep signal.
- $f(n)$ is its amplitude modulated inverse.
- $beep$ consists of 3 sine sweeps with a delay of $1000ms$.
My concern is that when I simultaneously play and record three beeps with a time delay of 1000ms each, it should capture all three beeps in the recording and then it should show three corresponding peaks in the impulse response of that recording as well.
What I'm getting is that it is only capturing the first beep clearly in $myrecording$ variable and only one peak corresponding to that is prominent in the impulse response as well.
- Why are the other two beeps not captured properly?
- Why are they not showing up in the impulse response?
I've attached the code and corresponding graph as well.
import threading
import time
from math import pi as pi
from scipy.signal import max_len_seq
import numpy as np
import matplotlib.pyplot as plt
import simpleaudio as sa
import sounddevice as sd
import scipy.signal as sig
from scipy.signal import chirp
from scipy.io.wavfile import write
from numpy import log as log
from numpy import exp as exp
from numpy import sin as sin
from concurrent.futures.thread import ThreadPoolExecutor
# ESS parameters
f1 = 200
f2 = 20000
T = 0.02
fs = 48000
t = np.arange(0, T * fs) / fs
R = np.log(f2 / f1)
# ESS generation
x = np.sin((2 * np.pi * f1 * T / R) * (np.exp(t * R / T) - 1)).astype(np.float32)
# BEEP VARIABLES
DELAY = 500
number_of_copies = 4
delay_between_the_beeps = np.zeros(48*DELAY)
# Making copies of beep with delay
one_delay_with_one_beep = np.concatenate((delay_between_the_beeps, x), axis=0)
b = np.tile(one_delay_with_one_beep,number_of_copies)
beep = np.concatenate((b,delay_between_the_beeps), axis=0)
#inverse filter of beep
k = np.exp(t * R / T)
f = x[::-1] / k
def play():
sd.play(beep, 48000, blocking=False)
def record():
global myrecording
myrecording = sd.rec(int(7 * 48000), samplerate=48000, channels=1
, dtype=np.float32).squeeze()
print(myrecording.dtype)
sd.wait()
if __name__ == '__main__':
tasks =[]
with ThreadPoolExecutor(max_workers=3) as executor:
tasks.append(executor.submit(record))
tasks.append(executor.submit(play))
concurrent.futures.wait(tasks)
impulse_response= sig.fftconvolve(f, myrecording, mode='full')
peak_delay = np.argmax(np.abs(impulse_response)) / 48
print(peak_delay)