Skip to content

Impulse Measurement Tools for Julia

License

Notifications You must be signed in to change notification settings

ssfrr/MeasureIR.jl

Repository files navigation

Simulated Impulse Response Plot

MeasureIR

Build Status Coverage Status codecov.io

MeasureIR is a Julia library for measuring and analyzing impulse responses (IRs). Impulse responses are generally captured by playing some kind of test signal through the system under test, and then analyzing the response to extract the IR.

The simplest test signal is an actual impulse, like a gunshot, balloon pop, or hand clap. In this case there is no analysis necessary, because the recorded response is a direct impulse response. The downside to this simple approach is that the total energy in the impulse often can't be very large without overdriving the measurement equipment and causing nonlinearities.

For this reason it is more common to use other signals like pseudo-random noise or sine sweeps to characterize a system, as they can spread the energy over a longer time frame, which increases the signal-to-noise ratio of the measurement.

Measuring an impulse response takes place in the following steps:

  1. Create a measurement. The library currently supports golay, expsweep, impulse, mls (maximum-length sequence), and rpms (random phase multisine).
  2. Generate a test signal for the measurement using stimulus(m), where m is a measurement. This signal is a single-channel time-domain signal that could be played directly through a speaker/transducer, or saved to a file for later measurement.
  3. Convolve the test signal with your system. This could be by playing the signal through a speaker into a room you're measuring, or using Julia's built-in conv function for testing. The result of this step should be a (possibly multichannel) response signal.
  4. Analyze the system response to generate the impulse response. The form of this is analyze(m, response) where m is your measurement object and response is the measured output of your system in response to the stimuli.

Example

using Plots: plot
using MeasureIR: golay, stimulus, analyze

meas = golay(4096)

# generate the test stimuli suitable for playback
stim = stimulus(meas)

# create a synthetic impulse response and simulate the system. This
# is where you'd normally play the stimuli through your system and
# record the response
irsim = 1./exp.(0:0.1:9.9) .* (rand(100) .- 0.5)
output = conv(stim, irsim)

# analyze to reconstruct the impulse response
ir = analyze(meas, output)

plot([irsim[1:100], ir[1:100]], labels=["Convolved IR", "Measured IR"])

Live Capture with PortAudio.jl

Rather than using an external program to play back the stimulus and record the response, you can perform the test from within Julia using the PortAudio.jl package.

This code snippet will play the stimulus stim through your sound card's default output (be careful, the golay stimulus not fun to listen to), and in parallel record through your default input.

using MeasureIR: golay, stimulus, analyze
using PortAudio: PortAudioStream

meas = golay(4*48000)
stim = stimulus(meas)

# run this block of code together, rather than each line individually
sleep(1) # sleep so we don't record the keystroke launching this code
str = PortAudioStream(synced=true)
@async write(str, stim*0.2)
resp = read(str, length(stim))
close(str)

ir = analyze(meas, resp)

About

Impulse Measurement Tools for Julia

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages