Clear Filters
Clear Filters

Plotting the inverse square law (of sound) on a slicegrid as a "heatmap"

4 views (last 30 days)
I'm new I've tinkered with this for half a day. I have an annoying neighbour who keeps getting ppl evicted over a subjective matter I'd like to approach the situation with the right accuracy.
Im trying to create a meshgrid and then "model" the inverse square law of sound pressure on the grid as a heatmap, can someone help me?
Either as a dirty solution with precalculated brunt values from a dataset or rather a more abstract sophisticated solutions. I'd like advice on the latter too if possible.
Example grid
x = -16:2:16;
y = -16:2:16;
z = -6:1:3;
[x,y,z] = meshgrid(x,y,z);
v = z.*exp(-x.^2-y.^2-z.^2);
xslice = [0,4,0]; % location of y-z planes
yslice = 0; % location of x-z plane
zslice = [0,3,-3]; % location of x-y planes
slice(x,y,z,v,xslice,yslice,zslice)
xlabel('x')
ylabel('y')
zlabel('z')
Question1:
How to display as color/heatmap the rough dirty value of 82db on origin point of x,y,z decreasing (6db per double the distance etc..) over a distance on the below grid "walls" on all directions.
I guess vectors would be suitable to plot this as well, maybe a transparent sphere with decreasing opacity?
Question2:
Ultimately I'd like to learn to model and plot the effect of a density x mass (a wall of concrete xxcm) also, which requires attenuation corrections etc, if any ideas on this too.. thanks!
Sorry thanks sorry
  1 Comment
Juho Peltola
Juho Peltola on 8 Jan 2022
Edited: Juho Peltola on 8 Jan 2022
I ended up creating my own dataset outside matlab (x,y,z's 21x21x21 and db 21x21x21) with manual sound propagation estimates per distance traveled based on test measurements and filling the grid with inverse square law.
Attenuation of walls with estimates on the different ranges based on charted values (https://www.engineeringtoolbox.com/sound-transmission-massive-walls-d_1409.html) and test measurements, then importing it to matlab then use below slice to display volumetric data and the walls, with 2 close by slices to display the attenuation of concrete walls.
Im fairly certain someone knows how to do this with a few lines of code. Especially creating the dataset was slow and I think interpolation or such could be used to do it faster automatically.
To display results I just used:
load dbcalc x y z db % load data
xslice = [0,4,4.04,0]; % attenuation layer (2 sides of wall): slice @ 4 and @4.04
yslice = [0,0,04]; % location of x-z plane
zslice = [0,2.98,3,3.03,-3]; % location of x-y planes
slice(x, y, z, db, xslice, yslice, zslice) % display the slices
cb = colorbar; % create and label the colorbar
cb.Label.String = 'db';

Sign in to comment.

Answers (1)

Neelanshu
Neelanshu on 30 Jan 2024
Hi Joha,
I understand from your query that you are interested in modeling the inverse square law of sound pressure and the effect of concrete walls on sound pressure.
Here's a conceptual overview of how you might create a MATLAB script to model this scenario:
% Parameters
origin_dB = 82; % Sound pressure level at the origin (in dB)
room_size = [10, 10, 10]; % Size of the room (in meters)
num_rooms = 3; % Number of rooms
wall_thickness = 0.08; % Thickness of the walls (in meters)
concrete_density = 1361; % desnity of concrete blocks
concrete_mass = concrete_density * wall_thickness;
%Mass & attenuation relation
piecewiseLogFunc = @(x) (x < 200) .* (13.45*log10(x) + 11.54) + ...
(x >= 200) .* (20.74*log10(x) - 5.23);
attenuation_wall = piecewiseLogFunc(concrete_mass); % Attenuation due to walls
% Create a grid of points within the rooms
[x, y, z] = meshgrid(linspace(0, room_size(1)*num_rooms, 100*num_rooms), ...
linspace(0, room_size(2), 100), ...
linspace(0, room_size(3), 100));
% Calculate the distance from the point source at the origin
distance = sqrt(x.^2 + y.^2 + z.^2);
% Apply the inverse square law (sound pressure level decreases by 6 dB with each doubling of distance)
sound_pressure_level = origin_dB - 20*log10(distance);
% Apply wall attenuation (assuming the sound has to pass through walls to reach other rooms)
for i = 2:num_rooms
sound_pressure_level(x > (i-1)*room_size(1)) = sound_pressure_level(x > (i-1)*room_size(1)) - attenuation_wall;
end
% Set a minimum threshold for the sound pressure level (e.g., below human hearing threshold)
sound_pressure_level(sound_pressure_level < 0) = 0;
% Plot the heatmap of the sound pressure level
slice(x, y, z, sound_pressure_level, [0, room_size(1), room_size(1)*2], room_size(2)/2, room_size(3)/2);
shading interp; % Interpolate colors smoothly
colorbar; % Show the color scale
title('Sound Pressure Level Heatmap');
xlabel('X (m)');
ylabel('Y (m)');
zlabel('Z (m)');
% Adjust the colormap to represent sound pressure levels visually
colormap(jet);
caxis([0 origin_dB]); % Set the color axis limits
This script assumes that the sound source of 82 dB is located at the origin and that the rooms are aligned with the coordinate axes. The attenuation due to concrete walls is approximated as a piecewise function. The walls of 3 rooms are aligned parallel to the yz-plane in the x-axis direction. The "slice" function is used to create a 3D heatmap of the sound pressure level within each room. The "caxis" function sets the color scale limits for the heatmap, which you can adjust based on the expected SPL range within the room.
Please note that this is a simplified model and does not account for all the complexities of sound propagation in an indoor environment, such as reflections, diffraction, or frequency-dependent attenuation. It's intended as a starting point for your modeling efforts.
Hope this helps.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!