pyroomacoustics icon indicating copy to clipboard operation
pyroomacoustics copied to clipboard

Beamforming real signal data, setting up beamformer and setting speed of sound

Open nnelshas opened this issue 2 years ago • 8 comments

Hi,

In the same vein as issue #132 I'm trying to extract a signal beamformed channel from a set 10 channels of real world data in the form of SoundSource objects in PRA. I know the mic and source locations, however, am having trouble getting the rake_delay_and_sum_weights function to work as issue #132 shows it done.

I'd really appreciate someone posting an example of how this should be written, currently I have this:

source1 = pra.SoundSource(mic_loc[0], signal = sig1) source2 = pra.SoundSource(mic_loc[1], signal = sig2) source3 = pra.SoundSource(mic_loc[2], signal = sig3) . . .

mics = pra.Beamformer(mic_locs, fs, N = 256) mics.rake_delay_and_sum_weights(source1, source2, source3, source4, . . .)

output = mics.process()

rake_delay_and_sum_weights does not seem to accept an array of sources and from issue #132 it seems like this is how you input multiple sources? Reading the source for the function though it seems like you can only feed it a single source, is there a way you can feed it multiple SoundSource objects?

Thank you!

nnelshas avatar Jul 13 '22 23:07 nnelshas

Hi, the delay and sum (DS) beamformer only makes sense for a single source. If you want to do DS beamforming towards multiple sources, you should do it one at a time.

bf_signals = []
for source in my_sources
    mics.rake_delay_and_sum_weights(signal)
    bf_signals.append(mics.process())

I see some other problems with your code

  1. Why place sources at the microphone locations ?
  2. The argument of R of Beamformer containing the microphones locations (mic_locs in your code) should be a dimension x number of mic array. This means that the location of the first mic is R[:, 0], second mic R[:, 1], etc. In your code you have both mic_loc and mic_locs, so it is a bit confusing.

fakufaku avatar Jul 14 '22 06:07 fakufaku

Hi,

Thank you so much for the quick response! I seem to have been very confused when typing out this code and question yesterday, upon rereading what I wrote I see every problem you mentioned. Let me clarify my question and situation, I have one source of sound and 10 microphone pickups, and would like to beamform their measurements to a one channel output using pyroomacoustics. I'm having trouble applying the included examples to my situation. How would one write a script beamforming 10 channels of real data knowing the actual source and microphone locations? Is that possible with this package?

Thanks again for the help.

nnelshas avatar Jul 14 '22 14:07 nnelshas

I see, so you have some recorded data already ? Or do you want to do simulation too ?

Have you checked the beamforming example scripts ?

fakufaku avatar Jul 19 '22 03:07 fakufaku

I have 10 channels of recorded data and have taken a look at the examples. I understand how to output a single beamformed channel through the simulation workflow, but don't see an example for how to do it using one's own recorded data, for example with 10 wav files.

nnelshas avatar Jul 19 '22 03:07 nnelshas

I see. It is true there is no good explanation on how to do that. Let mics be your pra.Beamformer object. Then, after the simulation, the multichannel signal is stored in mics.signals as a n_channels x n_samples array. You can just set this attribute directly. Here is some pseudo-code to do it.

import pyroomacoustics as pra
from scipy.io import wavfile

fs, my_signals = wavfile.read("path/to/my_recording.wav")
# my_signals.shape == (n_samples, n_channels)

mics = pra.Beamformer(R, fs, ...)  # set the beamformer object as you like
mics.rake_delay_and_sum_weights(source)
mics.signals = my_signals.T
output = mics.process()

fakufaku avatar Jul 19 '22 06:07 fakufaku

Thank you so much for the help, that works! Where would one set the speed of sound in this example since no virtual "room" is being setup? My data is collected in an argon environment so the speed of sound is a bit slower.

Thanks again!

nnelshas avatar Jul 20 '22 15:07 nnelshas

For air there are formula. I don't know about Argon. But it looks like you can find it online: https://www.betamachinery.com/knowledge-center/speed-of-sound-in-gases-list

fakufaku avatar Jul 20 '22 16:07 fakufaku

I know the speed of sound through argon is 323 m/s, however, the way you set it up in the beamformer is ambiguous to me.

When beamforming using simulated data you can use the room.set_sound_speed(323) function, however, there is no room when using real data so where would one set it in your example above?

Thank you for your time. `

nnelshas avatar Jul 20 '22 17:07 nnelshas