Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source directivity and various extensions to gpuRIR #27

Open
wants to merge 121 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
b3fcc79
Add our custom helper scripts.
Sep 14, 2021
2035749
Create air absorption script.
Sep 14, 2021
878d01e
Create script for generation IR file with air
Sep 14, 2021
c215558
Continue on the bandpass route. Doesn't work too
Sep 15, 2021
ccc0feb
Fixing a small mistake
Sep 15, 2021
626c93e
Successfully implemented air absorption through
Sep 16, 2021
eef7f34
Change default filter order settings.
Sep 16, 2021
d1a141d
Expanded scripts for more versatile utilization
Sep 22, 2021
98f2727
Implement STFT air absorption
Sep 22, 2021
f81c4e0
Not working yet.
Sep 24, 2021
19a87ea
Not working yet
Sep 24, 2021
0764650
Implemented strategy pattern for filters.
Sep 28, 2021
ae02c2b
Slight improvements, everything works
Sep 28, 2021
2a9beac
Calculate difference
Sep 28, 2021
0583eca
Finalize work on air absorption
Sep 29, 2021
6878b19
Adjust standard parameters to ease repeated
Sep 29, 2021
f324eab
Merge pull request #1 from corrooli/dev-air-absorption-improve
fuerbringer Sep 29, 2021
9900179
Update gitignore.
Sep 29, 2021
0708617
Attempt to multithread bandpass filter.
Sep 30, 2021
79c865a
Improve bandpass performance drastically.
Oct 4, 2021
61093a9
Further optimizations
Oct 4, 2021
d12f18f
Merge pull request #2 from corrooli/dev-band-mt
fuerbringer Oct 4, 2021
9e851a6
Make preparations. Not working yet.
Oct 4, 2021
2548d1c
Small cleanup, add possibility for forwards
Oct 4, 2021
4446d08
Conducted experiments with linear filters
Oct 5, 2021
2a69889
Implement linear filter using strategy pattern.
Oct 5, 2021
f151245
Cleaned up code, improved project structure
Oct 5, 2021
61444b3
Further small improvements and cleanup
Oct 5, 2021
811a716
Implement characteristic filtering via STFT.
Oct 6, 2021
9f8930b
Change file name, small cleanup
Oct 6, 2021
2b70788
Merge branch 'dev-freqdep-src-rcv' into develop
Oct 6, 2021
3ad38d4
Change file name
Oct 6, 2021
0fb32dd
Implement source characteristic.
Oct 6, 2021
f8fd1bc
Finished frequency dependent sender and receiver
Oct 6, 2021
0e9dfbf
Improve spectrogram.
Oct 7, 2021
00e8ec4
Add colorbar for dB Legend to spectro.
fuerbringer Oct 12, 2021
5faaa78
Consolidate generate_IR script.
Oct 13, 2021
9ba2741
Merge pull request #4 from corrooli/dev-ir-consolidate
corrooli Oct 13, 2021
94e01be
Implement speaker directivity.
Oct 17, 2021
66821e6
Did the heckin' removerino ;)
Oct 17, 2021
b3d0abb
Fix db colorbar scale and add db cap.
fuerbringer Oct 17, 2021
6eb7941
Fixing logical errors in source directivity.
Oct 18, 2021
94bbb6b
Merge branch 'dev-spectrogram-improve' into develop
Oct 19, 2021
b1671a1
Merge pull request #5 from corrooli/dev-spectrogram-improve
corrooli Oct 19, 2021
48a9528
Improved spectrogram, working perfectly now
Oct 19, 2021
7e6186b
Merge branch 'develop' of https://github.com/corrooli/gpuRIR into dev…
Oct 19, 2021
01df162
Make font size bigger, relabel Hz to KHz
Oct 20, 2021
814e655
Squashed a bug in source directivity.
Oct 20, 2021
3484028
Added parameters, updated python binding
Oct 20, 2021
820fec7
Create automated directivity test script.
Oct 20, 2021
2471542
Fixed comments.
Oct 20, 2021
75efac4
Create polar pattern plot script.
Oct 22, 2021
d074c98
Small code cleanup
Oct 22, 2021
dc8ce83
Set mic/speaker interpolation to interp1d
Oct 24, 2021
3a6e1ac
Merge branch 'develop' into dev-directivity
corrooli Oct 24, 2021
7ab1574
Merge pull request #6 from corrooli/dev-directivity
corrooli Oct 24, 2021
6c2955a
Corrected errors in polar plot
Oct 24, 2021
9e425dd
New polar pattern using plotly library
Oct 27, 2021
e5d3f4a
Consolidated everythign around directivity testing
Oct 27, 2021
eaa0d1a
Delete old polar plot scripts.
Oct 27, 2021
6e4f172
Add material list
Oct 29, 2021
4c1dfd9
Work in progress
Oct 29, 2021
b16ab2a
Make frequency dependant wall absorption
Oct 29, 2021
d9ace43
Consolidate frequency dependent
Nov 1, 2021
630abac
Make multiple receivers work.
Nov 1, 2021
ff02988
Consolidate further, frequency dependent wall
Nov 1, 2021
5458653
Finish implementation, everything works
Nov 2, 2021
11f591d
Corrected a wrong value in concrete_coarse
Nov 4, 2021
3007e23
Change interpolation
Nov 4, 2021
7d9fefc
Expand comment
Nov 4, 2021
7e339ac
Concentrated band division on actual frequency
Nov 4, 2021
f38fa48
Implement logarithmic distribution of bands.
Nov 5, 2021
93ec50c
Fixed verbose printouts.
Nov 5, 2021
b9213c6
Change materials to accomodate a more reputable source.
Nov 8, 2021
7d48509
Merge pull request #7 from corrooli/dev-walls
fuerbringer Nov 8, 2021
136cc80
Update README.md
corrooli Nov 8, 2021
683600c
Create README.md
corrooli Nov 8, 2021
b60ac33
Made a sketch for LR filtering.
Nov 17, 2021
e128284
Improve bandpassing
Nov 17, 2021
ef21203
Improve bandpassing in air absorption
Nov 17, 2021
6ebe13d
Cleanup
Nov 17, 2021
f6951de
Merge pull request #8 from corrooli/dev-walls
corrooli Nov 21, 2021
a23e0ad
Implement HRTF.
Nov 22, 2021
290380e
Made HRTF work.
Nov 22, 2021
5bb2fb1
Add 3D plot for visualizing hrtf
Nov 22, 2021
ad12335
Fixed an error concering rotation of head
Nov 22, 2021
96140ed
Fix some issues with hrft, verify results
Nov 24, 2021
bdd52e5
Corrected ear offset
Nov 29, 2021
ce9be9a
Update README.md
corrooli Nov 29, 2021
6c7bd72
Update README.md
corrooli Nov 29, 2021
313516a
Update README.md
corrooli Nov 29, 2021
21af51e
Cleanup
Nov 29, 2021
6c3a677
Merge pull request #9 from corrooli/dev-hrtf
corrooli Nov 29, 2021
d87ac66
Fixed Azimuth
Nov 30, 2021
1d82d49
Fix elevation, not done yet
Dec 2, 2021
9159f6d
Write HRTF calculation tests to verify results.
Dec 6, 2021
fb402af
Begin refactoring
Dec 6, 2021
926bd75
Massive refactoring.
Dec 7, 2021
3651d40
Merge pull request #10 from corrooli/dev-folder-reorg
fuerbringer Dec 7, 2021
f607e38
Changed butterworth filters to sos.
Dec 8, 2021
8e1a0d2
Make butterworth helper class
Dec 8, 2021
d66caf2
Fix elevation, complete test cases
Dec 8, 2021
b60d9d3
Write tests for binaural receiver
Dec 9, 2021
10923d4
Comments and cleanup
Dec 11, 2021
9beb93c
Refactoring polar_plot.py
Dec 11, 2021
b5693a5
Update readme
Dec 11, 2021
6299a61
Additions to documentation / comments
Dec 11, 2021
9af573b
More comments, renamed variables for consistency
Dec 13, 2021
d8e8b47
Fixed bug with spectrogram generation
Dec 13, 2021
a5a08fc
Fixed bug with spectrogram generation
Dec 14, 2021
286423e
Added further comments
Dec 14, 2021
2498d32
Merge pull request #11 from corrooli/dev-doc
fuerbringer Dec 14, 2021
5f1f0f9
Added bandpass/hi-low-pass switch
Dec 15, 2021
d04d0d8
Update readme.
fuerbringer Dec 15, 2021
f05556a
Small corrections
Dec 15, 2021
3f5e8ee
Reverted stereo_filters.py to standard settings.
Dec 15, 2021
1115379
Merge branch 'master' into develop
fuerbringer Dec 17, 2021
9da8255
Merge branch 'master' into corrooli/gpuRIR
DavidDiazGuerra Jan 20, 2022
a4169f4
Remove weird characters and unneeded imports
DavidDiazGuerra Jan 28, 2022
ba50a70
Move extensions examples
DavidDiazGuerra Jan 28, 2022
5e9ce1b
Add information about 'extensions' to the documentation
DavidDiazGuerra Mar 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [`beta_SabineEstimation`](#beta_sabineestimation)
* [`att2t_SabineEstimator`](#att2t_sabineestimator)
* [`t2n`](#t2n)
* [`extensions`](#t2n)
- [References](#references)


Expand Down Expand Up @@ -177,6 +178,13 @@ Estimation of the number of images needed for a correct RIR simulation.
*3 elements list of integers.*
The number of images sources to compute in each dimension.

### `extensions`


[@corrooli](https://github.com/corrooli) and [@fuerbringer](https://github.com/fuerbringer) made an awesome job implementing some interesting extra features for gpuRIR in python, such as simulating air absorption or frequency dependant wall absorption coefficients.

I would like to better integrate these features with the rest of the library, but sadly I have no time to do this now. You can find more information about how to use these functions in the [documentation of the subpackage](gpuRIR/extensions), in their [pull request](https://github.com/DavidDiazGuerra/gpuRIR/pull/27), or their [examples](examples/extensions). I am including this as they developed it and I cannot offer support for it.


## References

Expand Down
102 changes: 102 additions & 0 deletions examples/extensions/mono_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import numpy as np

import gpuRIR.extensions.room_parameters as rp
import gpuRIR.extensions.generate_RIR as gRIR
import gpuRIR.extensions.filtering as filtering

from gpuRIR.extensions.wall_absorption.materials import Materials as mat
import gpuRIR.extensions.wall_absorption.freq_dep_abs_coeff as fdac

from gpuRIR.extensions.filters.air_absorption_bandpass import AirAbsBandpass
from gpuRIR.extensions.filters.air_absorption_stft import AirAbsSTFT
from gpuRIR.extensions.filters.characteristic_filter import CharacteristicFilter
from gpuRIR.extensions.filters import characteristic_models as model
from gpuRIR.extensions.filters.linear_filter import LinearFilter

''' Example script for applying various gpuRIR extensions on an RIR generated by gpuRIR.
Optionally writes a mono impulse response (IR) wave file for convolving signals yourself, or convolves a sound file you provide.

Usable extensions in this context are:

* Frequency dependent absorption coefficients (virtual room materials) -> freq_dep_abs_coeff and wall_materials
* Air absorption (via Bandpassing or STFT) -> AirAbsSTFT() or AirAbsBandpass()
* Source and receiver characteristics (virtual mic / speaker models -> CharacteristicFilter() and LinearFilter()
* Benchmarking -> verbose

See comments in code for usage examples
'''
# Write impulse response (IR) wave file for convolving signals yourself
write_IR_file = False

# Enables adaptive gain. Raises volume without clipping. If disabled, the IR wave file amplitude may be too small to be audible.
enable_adaptive_gain = False

# Visualizes waveform and spectrogram of each generated IR file. Depending on filter, additional graphs are drawn.
visualize = False

# Prints calculation times and parameter/processing info onto the terminal if True. Needed for benchmarking, debugging and further info.
verbose = False

# If True, apply frequency dependent wall absorption coefficients to simulate realistic wall/ceiling/floor materials.
# Caution: Needs more resources!
freq_dep_abs_coeff = False

# Wall, floor and ceiling materials the room is consisting of
# Structure: Array of six materials (use 'mat.xxx') corresponding to:
# Left wall | Right wall | Front wall | Back wall | Floor | Ceiling
wall_materials = 4 * [mat.wallpaper_on_lime_cement_plaster] + \
[mat.parquet_glued] + [mat.concrete]

# Define room parameters
params = rp.RoomParameters(
room_sz=[5, 4, 3], # Size of the room [m]
pos_src=[[3, 3, 1.8]], # Positions of the sources [m]
pos_rcv=[[1.5, 1.5, 1.6]], # Positions of the receivers [m]
orV_src=[0, -1, 0], # Steering vector of source(s)
orV_rcv=[0.1, 1, 0], # Steering vector of receiver(s)
spkr_pattern="omni", # Source polar pattern
mic_pattern="card", # Receiver polar pattern
T60=1.0, # Time for the RIR to reach 60dB of attenuation [s]
# Attenuation when start using the diffuse reverberation model [dB]
att_diff=15.0,
att_max=60.0, # Attenuation at the end of the simulation [dB]
fs=44100, # Sampling frequency [Hz]
# Bit depth of WAV file. Either np.int8 for 8 bit, np.int16 for 16 bit or np.int32 for 32 bit
bit_depth=np.int32,
# Absorption coefficient of walls, ceiling and floor.
wall_materials=wall_materials
)

# Generate room impulse response (RIR) with given parameters
if freq_dep_abs_coeff:
receiver_channels = fdac.generate_RIR_freq_dep_walls(
params, LR=False, order=10, band_width=100, factor=1.1, use_bandpass_on_borders=False, visualize=visualize, verbose=verbose)
filename_appendix = "freqdep"
else:
receiver_channels = gRIR.generate_RIR(params)
filename_appendix = ""

for i in range(len(params.pos_rcv)):
# All listed filters wil be applied in that order.
# Leave filters array empty if no filters should be applied.

filters = [
# Speaker simulation.
# Comment either one out
# CharacteristicFilter(model.tiny_speaker, params.fs, visualize=visualize),
# LinearFilter(101, (0, 100, 150, 7000, 7001, params.fs/2), (0, 0, 1, 1, 0, 0), params.fs),

# Air absorption simulation.
# Comment either one out
# AirAbsBandpass(divisions=50, max_frequency=params.fs/2, LR=True, order=10, use_bandpass_on_borders=True, verbose=verbose, visualize=visualize),
# AirAbsSTFT(),

# Mic simulation.
# Comment either one out
# CharacteristicFilter(model.sm57, params.fs, visualize=visualize),
# LinearFilter(101, (0, 100, 150, 7000, 7001, params.fs/2), (0, 0, 1, 1, 0, 0), params.fs, visualize=visualize)
]

# The filters above are applied on the RIR generated by gpuRIR and returned into filtered_IR
filtered_IR = filtering.filter_mono_IR(
receiver_channels[i], filters, params.bit_depth, params.fs, filename_appendix=filename_appendix, write_wave=write_IR_file, enable_adaptive_gain=enable_adaptive_gain, visualize=visualize, verbose=verbose)
170 changes: 170 additions & 0 deletions examples/extensions/stereo_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import numpy as np

import gpuRIR.extensions.room_parameters as rp
import gpuRIR.extensions.generate_RIR as gRIR
import gpuRIR.extensions.filtering as filtering

from gpuRIR.extensions.wall_absorption.materials import Materials as mat
import gpuRIR.extensions.wall_absorption.freq_dep_abs_coeff as fdac

from gpuRIR.extensions.filters.air_absorption_bandpass import AirAbsBandpass
from gpuRIR.extensions.filters.air_absorption_stft import AirAbsSTFT
from gpuRIR.extensions.filters.characteristic_filter import CharacteristicFilter
from gpuRIR.extensions.filters import characteristic_models as model
from gpuRIR.extensions.filters.linear_filter import LinearFilter
from gpuRIR.extensions.filters.hrtf_filter import HRTF_Filter

from gpuRIR.extensions.hrtf.hrtf_binaural_receiver import BinauralReceiver

''' Example script for applying various gpuRIR extensions on an RIR generated by gpuRIR.
Optionally writes a stereo impulse response (IR) wave file for convolving signals yourself, or convolves a sound file you provide.

Please note:
* Number of receivers is restricted to 2 for each ear due to HRTF.

Extensions are:
* Head-related transfer function (HRTF, simulated human hearing)
* Frequency dependent absorption coefficients (virtual room materials) -> freq_dep_abs_coeff and wall_materials
* Air absorption (via Bandpassing or STFT) -> AirAbsSTFT() or AirAbsBandpass()
* Source and receiver characteristics (virtual mic / speaker models -> CharacteristicFilter()
* Binaural receiver (two receivers in room) -> BinauralReceiver()
* Head-related transfer function (simulated human hearing) -> use_hrtf
* Benchmarking -> verbose

See comments in code for usage examples.
'''

# Write impulse response (IR) wave file for convolving signals yourself
write_IR_file = False

# Enables adaptive gain. Raises volume without clipping. If disabled, the IR wave file amplitude may be too small to be audible.
enable_adaptive_gain = False

# Visualizes waveform and spectrogram of each generated IR file. Depending on filter, additional graphs are drawn.
visualize = False

# Prints calculation times and parameter/processing info onto the terminal if True. Needed for benchmarking, debugging and further info.
verbose = False

# If True, apply frequency dependent wall absorption coefficients (virtual room materials) to simulate realistic wall/ceiling/floor materials.
# Caution: Needs more resources!
freq_dep_abs_coeff = False

# Uses binaural (HRTF) processing to enable realistic sound in 3D spaces. Use of headphones recommended.
use_hrtf = False

# Wall, floor and ceiling materials the room is consisting of
# Structure: Array of six materials (use 'mat.xxx') corresponding to:
# Left wall | Right wall | Front wall | Back wall | Floor | Ceiling
wall_materials = 4 * [mat.wallpaper_on_lime_cement_plaster] + \
[mat.parquet_glued] + [mat.concrete]

# Setup of binaural receiver with head position [m] and head direction [m].
head = BinauralReceiver(
head_position=[1.5, 1.5, 1.6], head_direction=[0, -1, 0], verbose=verbose)


# Common gpuRIR parameters (applied to both channels)
room_sz = [5, 4, 3] # Size of the room [m]
pos_src = [[1.5, 1.8, 1.8]] # Positions of the sources [m]
orV_src = [0, -1, 0] # Steering vector of source(s)
spkr_pattern = "omni" # Source polar pattern
mic_pattern = "homni" # Receiver polar patterny
T60 = 1.0 # Time for the RIR to reach 60dB of attenuation [s]
# Attenuation when start using the diffuse reverberation model [dB]
att_diff = 15.0
att_max = 60.0 # Attenuation at the end of the simulation [dB]
fs = 44100 # Sampling frequency [Hz]
# Bit depth of WAV file. Either np.int8 for 8 bit, np.int16 for 16 bit or np.int32 for 32 bit
bit_depth = np.int32

if visualize:
head.visualize(room_sz, pos_src, orV_src)

# Define room parameters
params_left = rp.RoomParameters(
room_sz=room_sz,
pos_src=pos_src,
orV_src=orV_src,
spkr_pattern=spkr_pattern,
mic_pattern=mic_pattern,
T60=T60,
att_diff=att_diff,
att_max=att_max,
fs=fs,
bit_depth=bit_depth,
wall_materials=wall_materials,

# Positions of the receivers [m]
pos_rcv=[head.ear_position_l], # Position of left ear
orV_rcv=head.ear_direction_l, # Steering vector of left ear
head_direction=head.direction,
head_position=head.position
)

params_right = rp.RoomParameters(
room_sz=room_sz,
pos_src=pos_src,
orV_src=orV_src,
spkr_pattern=spkr_pattern,
mic_pattern=mic_pattern,
T60=T60,
att_diff=att_diff,
att_max=att_max,
fs=fs,
bit_depth=bit_depth,
wall_materials=wall_materials,

# Positions of the receivers [m]
pos_rcv=[head.ear_position_r], # Position of right ear
orV_rcv=head.ear_direction_r, # Steering vector of right ear
head_direction=head.direction,
head_position=head.position
)

# Generate two room impulse responses (RIR) with given parameters for each ear
if freq_dep_abs_coeff:
receiver_channel_r = fdac.generate_RIR_freq_dep_walls(
params_right, LR=False, order=10, band_width=100, factor=1.1, use_bandpass_on_borders=False, visualize=visualize, verbose=verbose)
receiver_channel_l = fdac.generate_RIR_freq_dep_walls(
params_left, LR=False, order=10, band_width=100, factor=1.1, use_bandpass_on_borders=False, visualize=visualize, verbose=verbose
)
filename_appendix = "freqdep"

else:
receiver_channel_r = gRIR.generate_RIR(params_right)
receiver_channel_l = gRIR.generate_RIR(params_left)
filename_appendix = ""

# Common filters, applied to both channels.
# All listed filters wil be applied in that order.
# Leave filters array empty if no filters should be applied.
filters_both = [
# Speaker simulation.
# Comment either one out
# CharacteristicFilter(model.tiny_speaker, fs, visualize=visualize),
# LinearFilter(101, (0, 100, 150, 7000, 7001, fs/2), (0, 0, 1, 1, 0, 0), fs),

# Air absorption simulation.
# Comment either one out
# AirAbsBandpass(divisions=50, max_frequency=fs/2, LR=True, order=10, use_bandpass_on_borders=False, verbose=verbose, visualize=visualize),
# AirAbsSTFT(),

# Mic simulation.
# Comment either one out
# CharacteristicFilter(model.sm57, fs, visualize=visualize),
# LinearFilter(101, (0, 100, 150, 7000, 7001, fs/2), (0, 0, 1, 1, 0, 0), fs, visualize=visualize)
]

if use_hrtf:
filters_r = filters_both + \
[HRTF_Filter('r', params_right, verbose=verbose)]
filters_l = filters_both + [HRTF_Filter('l', params_left, verbose=verbose)]
else:
filters_r = filters_both
filters_l = filters_both

# The filters above are applied on the RIR generated by gpuRIR and returned into filtered_IR_right and filtered_IR_left for both stereo channels
filtered_IR_right, filtered_IR_left = filtering.filter_stereo_IR(receiver_channel_r[0], receiver_channel_l[0], filters_r, filters_l,
bit_depth, fs, filename_appendix=filename_appendix, write_wave=write_IR_file,
enable_adaptive_gain=enable_adaptive_gain, verbose=verbose, visualize=visualize)
57 changes: 31 additions & 26 deletions examples/polar_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
import plotly.graph_objects as go
from plotly.subplots import make_subplots

import gpuRIR.extensions.filters.air_absorption_calculation as aa
import gpuRIR.extensions.room_parameters as rp
import gpuRIR.extensions.generate_RIR as gRIR

"""
Visualizes polar patterns of the source by rotating source by 360, repeatedly calling gpuRIR.
Warning: Takes up to 2-3 minutes depending on your hardware!
Warning: Takes up to 2-3 minutes depending on your hardware!
"""

# Feel free to change these parameters
# Resolution of polar plot (amount to divide 360 degrees into)
PARTITIONS = 360

# gpuRIR parameters
# gpuRIR parameters
gpuRIR.activateMixedPrecision(False)
gpuRIR.activateLUT(False)

Expand All @@ -31,7 +35,7 @@
def normalize_amps(amps):
'''
Normalizing amplitude. Change all amplitude such that loudest sample has the amplitude of 1.
:param amps Array of samples.
:param amps Array of samples.
'''
amps_normalized = np.copy(amps)
max_value = np.max(amps_normalized)
Expand All @@ -48,7 +52,7 @@ def create_polar_plot(fig, i, amps, name):
'''
Creates single polar plot.

:param fig Plot figure.
:param fig Plot figure.
:param i Index of plot
:param name Name of polar pattern
'''
Expand All @@ -67,7 +71,7 @@ def create_polar_plots(title=""):
'''
Creates compilation of polar plots using plotly.

:param title Title of plot.
:param title Title of plot.
'''
fig_polar = make_subplots(rows=2, cols=3, specs=[[{'type': 'polar'}]*3]*2)
for i in range(6):
Expand Down Expand Up @@ -120,29 +124,30 @@ def create_polar_plots(title=""):
rad = degree*np.pi/180

# RIR parameters
room_sz=[16, 8, 3] # Size of the room [m]
pos_src=np.array([[4, 4, 1.7]]) # Positions of the sources [m]
pos_rcv=np.array([[10, 4, 2]]) # Positions of the receivers [m]
# Steering vector of source(s)
orV_src=np.matlib.repmat(np.array([np.cos(rad), np.sin(rad), 0]), 1, 1)
# Steering vector of receiver(s)
orV_rcv=np.matlib.repmat(np.array([1, 0, 0]), 1, 1)
spkr_pattern=POLAR_PATTERNS[p] # Source polar pattern
mic_pattern="omni" # Receiver polar pattern
T60=0.21 # Time for the RIR to reach 60dB of attenuation [s]
# Attenuation when start using the diffuse reverberation model [dB]
att_diff=15.0
att_max=60.0 # Attenuation at the end of the simulation [dB]
fs=44100 # Sampling frequency [Hz]
# Bit depth of WAV file. Either np.int8 for 8 bit, np.int16 for 16 bit or np.int32 for 32 bit
bit_depth=np.int32
beta=6*[0.1] # Reflection coefficients
Tdiff= gpuRIR.att2t_SabineEstimator(att_diff, T60) # Time to start the diffuse reverberation model [s]
Tmax = gpuRIR.att2t_SabineEstimator(att_max, T60) # Time to stop the simulation [s]
nb_img = gpuRIR.t2n( Tdiff, room_sz ) # Number of image sources in each dimension
params = rp.RoomParameters(
room_sz=[16, 8, 3], # Size of the room [m]
pos_src=[[4, 4, 1.7]], # Positions of the sources [m]
pos_rcv=[[10, 4, 2]], # Positions of the receivers [m]
# Steering vector of source(s)
orV_src=np.matlib.repmat(
np.array([np.cos(rad), np.sin(rad), 0]), 1, 1),
# Steering vector of receiver(s)
orV_rcv=np.matlib.repmat(np.array([1, 0, 0]), 1, 1),
spkr_pattern=POLAR_PATTERNS[p], # Source polar pattern
mic_pattern="omni", # Receiver polar pattern
T60=0.21, # Time for the RIR to reach 60dB of attenuation [s]
# Attenuation when start using the diffuse reverberation model [dB]
att_diff=15.0,
att_max=60.0, # Attenuation at the end of the simulation [dB]
fs=44100, # Sampling frequency [Hz]
# Bit depth of WAV file. Either np.int8 for 8 bit, np.int16 for 16 bit or np.int32 for 32 bit
bit_depth=np.int32,
beta=6*[0.1]
)

# Prepare sound data arrays.
receiver_channels = gpuRIR.simulateRIR(room_sz, beta, pos_src, pos_rcv, nb_img, Tmax, fs, Tdiff=Tdiff, orV_rcv=orV_rcv, mic_pattern=mic_pattern, orV_src=orV_src, spkr_pattern=spkr_pattern)
receiver_channels = gRIR.generate_RIR(params)


# Stack array vertically
impulseResponseArray = np.vstack(receiver_channels[0])
Expand Down
Loading