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

Help me understand energy scaling #352

Open
Kanafani80 opened this issue May 31, 2024 · 4 comments
Open

Help me understand energy scaling #352

Kanafani80 opened this issue May 31, 2024 · 4 comments

Comments

@Kanafani80
Copy link

Hi there! Thank you for this great repo.

I am having trouble understanding the following energy scaling that I see in a couple of places, for example in room.cpp when scattered energy is computed:

double r_sq = double(travel_dist_at_mic) * travel_dist_at_mic;
auto p_hit = (1 - sqrt(1 - mic_radius_sq / std::max(mic_radius_sq, r_sq)));
Eigen::ArrayXf energy = scat_trans / (r_sq * p_hit) ;

This seems different from the lambert cosine formula (which is indeed applied earlier). In the code above, r_sq will generally be much larger than the mic radius squared, so it seems p_hit will be tiny, which will make energy blow up.

What is the physical explanation of this? I can’t find the equivalent formula in either the wayverb or Schroeder dissertation.

thanks!

@fakufaku
Copy link
Collaborator

fakufaku commented Jun 3, 2024

Hi @Kanafani80 , you are doing a pretty deep dive into the code! 🤿

This is an excellent question. As is, p_hit is hard to understand and it would deserve to have some comment in the code explaining it. I had to dig myself to recall why it is like this... 🙈

This term is necessary to match the scales of the image source model and the ray tracing, as explained in Dirk Schroeder's thesis, Section 5.4 (in particular, page 75, equation 5.54). It is not called p_hit, but the value is the same, i.e. r ** 2 * (1 - cos(gamma)). The cos(gamma) can be computed as sqrt(1 - mic_dist **2 / r ** 2) (definition of cosine + pythagoras, see fig 5.20 for definition of gamma and r).

@fakufaku
Copy link
Collaborator

fakufaku commented Jun 3, 2024

Added some comments in the code here and here.

@Kanafani80
Copy link
Author

Thanks for the reply! I had not read that far into the dissertation ;)

The scale matching idea makes sense to me. However, it seems that your calculation is using the cumulative distance travelled by the ray up to this point:
double r_sq = double(travel_dist_at_mic) * travel_dist_at_mic;
If we go by geometry and Pythagoras, shouldn't the distance between the secondary source and the receiver be used instead (so, hop_dist instead of travel_dist_at_mic)?

Thanks again!

@fakufaku
Copy link
Collaborator

fakufaku commented Jun 4, 2024

In my understanding, the quantity relates the total energy of the source, to the fraction that impacts the receiver.
Thus, it should be computed according to the total distance traveled, not just from the last reflection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants