I've written a simple python program, in a git er done brute force and ignorance manner, which indicates where frequency collisions occur in a cabinet given the width, height, and depth (in millimeters). I'll post below. The idea is that each dimension has harmonic frequencies, when one or both of the other dimensions have similar harmonic frequencies then that frequency is prone to nulls (or possibly boost). The program identifies these collisions and there is a very simple optimizer that looks at changing dimensions to reduce the number of collisions.
Example exec: py ./main.py 208 968 363
208 is width in mm, 968 height, 363 depth
Looking for feedback on logic/calculation errors. Thanks.
import sys
# Copyright 2023,2024 Aaron Loyd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
def dimensionHarmonics(dimension):
harmonics = []
# speed of sound in mms 342900
hfirst = round(((342900 / int(dimension)) / 2))
harmonics.append(hfirst)
for harmonic in range(2, 10):
harmonics.append(hfirst * harmonic)
# for value in wharmonics:
# print(value)
return (harmonics)
def swcalc(wharmonics, hharmonics, dharmonics):
whcollisions = []
wdcollisions = []
hdcollisions = []
for windex in range(9):
# diffval = 0.05 * wharmonics[windex]
diffval = 50
for hindex in range(9):
if ((abs(int(wharmonics[windex]) - int(hharmonics[hindex]))) < diffval):
whcollisions.append(str(wharmonics[windex]) + " with " + str(hharmonics[hindex]))
if ((abs(int(wharmonics[windex]) - int(dharmonics[hindex]))) < diffval):
wdcollisions.append(str(wharmonics[windex]) + " with " + str(dharmonics[hindex]))
for hindex in range(9):
# diffval = 0.05 * int(hharmonics[hindex])
diffval = 50
for dindex in range(9):
if ((abs(int(hharmonics[hindex]) - int(dharmonics[dindex]))) < diffval):
hdcollisions.append(str(hharmonics[hindex]) + " with " + str(dharmonics[dindex]))
return whcollisions, wdcollisions, hdcollisions
def printCollisions(whcollisions, wdcollisions, hdcollisions):
print("----------------------------------------------------------------------\n\n")
print("Width Collisions with Height")
if (len(whcollisions) <= 0):
print("none")
else:
for whc in whcollisions:
print(whc)
print("----------------------------------------------------------------------")
print("Width Collisions with Depth")
if (len(wdcollisions) <= 0):
print("none")
else:
for wdc in wdcollisions:
print(wdc)
print("----------------------------------------------------------------------")
print("Height Collisions with Depth")
if (len(hdcollisions) <= 0):
print("none")
else:
for hdc in hdcollisions:
print(hdc)
print("----------------------------------------------------------------------\n\n")
def checkCollisions(owidth, oheight, odepth, totalCollisionCount):
owharmonics = dimensionHarmonics(owidth)
ohharmonics = dimensionHarmonics(oheight)
odharmonics = dimensionHarmonics(odepth)
owhcollisions, owdcollisions, ohdcollisions = swcalc(owharmonics, ohharmonics, odharmonics)
collisionCount = len(owhcollisions) + len(owdcollisions) + len(ohdcollisions)
if (collisionCount < totalCollisionCount):
print("\nusing width of " + (str(owidth)))
print("using height of " + (str(oheight)))
print("using depth of " + (str(odepth)))
print("collision count is " + str(collisionCount) + " instead of " + str(totalCollisionCount))
print("\n")
printCollisions(owdcollisions, owdcollisions, ohdcollisions)
def optimize(width, height, depth, totalCollisionCount) :
print("----------------------------------")
print("optimizing")
origvolume = width * height * depth
maxvolume = origvolume * 1.02
minvolume = origvolume * 0.98
# width check
print("\nexpand width")
volume = origvolume
owidth = width
oheight = height
odepth = depth
while (volume < maxvolume):
print(".", end='')
owidth += 1.0
volume = owidth * oheight * odepth
checkCollisions(owidth, oheight, odepth, totalCollisionCount)
print("\nshrink width")
volume = origvolume
owidth = width
oheight = height
odepth = depth
while (volume > minvolume):
print(".", end='')
owidth -= 1.0
volume = owidth * oheight * odepth
checkCollisions(owidth, oheight, odepth, totalCollisionCount)
# height check
print("\nexpand height")
volume = origvolume
owidth = width
oheight = height
odepth = depth
while (volume < maxvolume):
print(".", end='')
oheight += 1.0
volume = owidth * oheight * odepth
checkCollisions(owidth, oheight, odepth, totalCollisionCount)
print("\nshrink height")
volume = origvolume
owidth = width
oheight = height
odepth = depth
while (volume > minvolume):
print(".", end='')
oheight -= 1.0
volume = owidth * oheight * odepth
checkCollisions(owidth, oheight, odepth, totalCollisionCount)
# depth check
print("\nexpand depth")
volume = origvolume
owidth = width
oheight = height
odepth = depth
while (volume < maxvolume):
print(".", end='')
odepth += 1.0
volume = owidth * oheight * odepth
checkCollisions(owidth, oheight, odepth, totalCollisionCount)
print("\nshrink depth")
volume = origvolume
owidth = width
oheight = height
odepth = depth
while (volume > minvolume):
print(".", end='')
odepth -= 1.0
volume = owidth * oheight * odepth
checkCollisions(owidth, oheight, odepth, totalCollisionCount)
print("\noptimizing finished.")
if
name == '
main':
print("Collisions can occur at the following frequencies:")
print("Width\t\t\tHeight\t\t\t\tDepth")
# dimensions in millimeters
width = float(sys.argv[1])
height = float(sys.argv[2])
depth = float(sys.argv[3])
wharmonics = dimensionHarmonics(width)
hharmonics = dimensionHarmonics(height)
dharmonics = dimensionHarmonics(depth)
for index in range(9):
print(str(wharmonics[index]) + "\t\t\t\t" + str(hharmonics[index]) + "\t\t\t\t" + str(dharmonics[index]))
whcollisions, wdcollisions, hdcollisions = swcalc(wharmonics, hharmonics, dharmonics)
printCollisions(whcollisions, wdcollisions, hdcollisions)
totalCollisionCount = len(whcollisions) + len(wdcollisions) + len(hdcollisions)
print("total collisions = " + str(totalCollisionCount))
print("----------------------------------")
totalWidthCollision = len(whcollisions) + len(wdcollisions)
print("total width collisions = " + str(totalWidthCollision))
totalHeightCollision = len(whcollisions) + len(hdcollisions)
print("total height collisions = " + str(totalHeightCollision))
totalDepthCollision = len(wdcollisions) + len(hdcollisions)
print("total depth collisions = " + str(totalDepthCollision))
if (totalCollisionCount > 0):
optimize(width, height, depth, totalCollisionCount)