Hi, I'm also trying to write ultrasound simulation with heterogenous attentuation. At the moment, it is having a ball of muscle inside water medium
From the ultrasound example, the time gain compensation step seems to work only with medium.alpha_coeff as a number, not varying at the bsxfun function (matlab complains to me about dimensions when I made it heterogeneous).
% -----------------------------
% Time Gain Compensation
% -----------------------------
% create radius variable assuming that t0 corresponds to the middle of the
% input signal
t0 = length(input_signal) * kgrid.dt / 2;
r = c0 * ( (1:length(kgrid.t_array)) * kgrid.dt - t0 ) / 2; % [m]
% define absorption value and convert to correct units
tgc_alpha_db_cm = medium.alpha_coeff * (tone_burst_freq * 1e-6)^medium.alpha_power;
tgc_alpha_np_m = tgc_alpha_db_cm / 8.686 * 100;
% create time gain compensation function based on attenuation value and
% round trip distance
tgc = exp(tgc_alpha_np_m * 2 * r);
% apply the time gain compensation to each of the scan lines
scan_lines = bsxfun(@times, tgc, scan_lines);
If I have medium.alpha_coeff spatially varying (such as coeff for muscle where ball is and rest have coeff of water), does that mean I have to change the tgc_alpha_db_cm calculation to just use the default coeff of water so that the bsxfun function will work?