<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>k-Wave User Forum &#187; Topic: Creating a waveform with custom time offsets</title>
		<link>http://www.k-wave.org/forum/topic/creating-a-waveform-with-custom-time-offsets</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Wed, 13 May 2026 00:15:42 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.k-wave.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.k-wave.org/forum/rss/topic/creating-a-waveform-with-custom-time-offsets" rel="self" type="application/rss+xml" />

		<item>
			<title>robou on "Creating a waveform with custom time offsets"</title>
			<link>http://www.k-wave.org/forum/topic/creating-a-waveform-with-custom-time-offsets#post-8121</link>
			<pubDate>Fri, 16 Apr 2021 00:46:27 +0000</pubDate>
			<dc:creator>robou</dc:creator>
			<guid isPermaLink="false">8121@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hello, I am... blocked... is the term. I am sure that it´s a simple error that i do not catch.&#60;br /&#62;
 I trying to create a multiring trandsucer, It´s seems that geomotry is correct.Then I create signals and calculate needed delays for each rings.&#60;br /&#62;
 I understand that if there are 4 rings, we must have 4 differents toneburst vectors,&#60;br /&#62;
isn't it?&#60;br /&#62;
When I do not use offset everything is working, but that's not the case for multirings. Rings value index go from 1 to 4. &#60;/p&#62;
&#60;p&#62;Code is more explicit, or not:).  Thank you Romain&#60;/p&#62;
&#60;p&#62;%% Creation of transducer geometry&#60;/p&#62;
&#60;p&#62;    source.p_mask = zeros(Nz,Ny,Nx);    % source mask&#60;/p&#62;
&#60;p&#62;% if plane transducer&#60;br /&#62;
    if(type == 0)                                   &#60;/p&#62;
&#60;p&#62;        radius = round(aperture*1e-3/2/ds);         % radius of aperture [grid points]&#60;br /&#62;
        cy      = round(Ny/2);                      % Y-axis center of the disk&#60;br /&#62;
        cx      = round(Nx/2);                      % X-axis center of the disk&#60;/p&#62;
&#60;p&#62;        geom    = makeDisc(Nx,Ny,cx,cy,radius);     % disk geometry&#60;br /&#62;
        % add the geometry to the source domain&#60;br /&#62;
        source.p_mask(Nz_trans_pos+PML_size, 1:Ny, 1:Nx) = geom;         &#60;/p&#62;
&#60;p&#62;% if curved transducer&#60;br /&#62;
    elseif(type == 1)&#60;br /&#62;
        Nfd = round(fd/ds);&#60;br /&#62;
        Nap = round(aperture*1e-3/ds);&#60;/p&#62;
&#60;p&#62;        % Redefine aperture to make it an odd number for makeBowl to work&#60;br /&#62;
        if rem(Nap,2) == 0&#60;br /&#62;
           Nap = Nap + 1;&#60;br /&#62;
        end&#60;/p&#62;
&#60;p&#62;        trans_pos = [PML_size+Nz_trans_pos, round(Ny/2), round(Nx/2)];&#60;br /&#62;
        focus_pos = [PML_size+Nz_trans_pos+Nfd, round(Ny/2), round(Nx/2)] ;&#60;/p&#62;
&#60;p&#62;        %           makeBowl(grid_size, origin bowl_pos, radius curvature, aperture diameter, location of focus_pos, 'Plot', true,'RemoveOverlap',true);&#60;br /&#62;
        geom      = makeBowl(size(source.p_mask), trans_pos, Nfd+1, Nap, focus_pos, 'Plot', false,'RemoveOverlap',true);&#60;/p&#62;
&#60;p&#62;        %----------------------- Version Romain ------------------------%&#60;br /&#62;
        % Multirings configuration with identification&#60;br /&#62;
            % 2D rings creation&#60;br /&#62;
            NradioInnerDisc     = round((1e-3 * ri)/ds - ds);    % in grid number&#60;br /&#62;
            NradioOuterDisc     = round((1e-3 * ro)/ds);&#60;br /&#62;
            innerDisc           = zeros (Ny,Nx);                 % in grid number&#60;br /&#62;
            outerDisc           = zeros (Ny,Nx);&#60;br /&#62;
            multiRings2D        = zeros (Ny,Nx);&#60;/p&#62;
&#60;p&#62;            for i=1:length(ri)&#60;br /&#62;
               innerDisc     = makeDisc(Ny,Nx,round(Ny/2),round(Nx/2),NradioInnerDisc(i));&#60;br /&#62;
               outerDisc     = makeDisc(Ny,Nx,round(Ny/2),round(Nx/2),NradioOuterDisc(i));&#60;br /&#62;
               ring2D        = outerDisc - innerDisc;&#60;br /&#62;
               multiRings2D  = multiRings2D + i.* ring2D;  % index identification grow with radius&#60;br /&#62;
               figure; imagesc(multiRings2D); axis image;&#60;br /&#62;
            end&#60;/p&#62;
&#60;p&#62;            % 3D Projection&#60;br /&#62;
            multiRings3D        = repmat(multiRings2D,1,1,Nz);&#60;br /&#62;
            multiRings3D        = permute(multiRings3D,[3,2,1]);&#60;/p&#62;
&#60;p&#62;            % Apply rings to 3D bowl&#60;br /&#62;
            geomMultiRings3D    = geom.*multiRings3D;&#60;/p&#62;
&#60;p&#62;            % Add the geometry to the source domain&#60;br /&#62;
            source.p_mask = geomMultiRings3D; &#60;/p&#62;
&#60;p&#62;            % Verification&#60;br /&#62;
            transductor         = squeeze(sum(geomMultiRings3D,1));&#60;br /&#62;
            figure; imagesc(squeeze(transductor)); axis image;&#60;br /&#62;
            %flyThrough(geomMultiRings3D(1:50,:,:),1,50,1);&#60;br /&#62;
%             figure&#60;br /&#62;
%             for i=1:floor(Ny/2)&#60;br /&#62;
%                 subplot(3,1,1)&#60;br /&#62;
%                     imagesc(squeeze(geomMultiRings3D(i,:,:)));axis image&#60;br /&#62;
%                 subplot(3,1,2)&#60;br /&#62;
%                     imagesc(squeeze(geomMultiRings3D(:,round(Ny/2)+i,:)));axis image&#60;br /&#62;
%                 subplot(3,1,3)&#60;br /&#62;
%                     imagesc(squeeze(geomMultiRings3D(:,:,round(Nx/2)+i)));axis image&#60;br /&#62;
%                 drawnow; pause;&#60;br /&#62;
%             end&#60;/p&#62;
&#60;p&#62;%% Create time array and emitted signal signal&#60;br /&#62;
% Function 'makeTime' automatically specifies Nt, dt, and t_array based on the&#60;br /&#62;
% Courant-Friedrichs-Lewy (CFL) number and the grid size.&#60;br /&#62;
% Default CFL=0.3, where dt = cfl * dx / sound_speed.&#60;/p&#62;
&#60;p&#62;    c_max   = max(medium.sound_speed(:));    % maximum sound speed needed for &#34;makeTime&#34; function [m/s]&#60;br /&#62;
    c_min   = min(medium.sound_speed(:));    % minimum sound speed needed for calculation of &#34;t_end&#34; [m/s]&#60;br /&#62;
    cfl     = 0.3;                          % Courant-Friedrich-Lewy stability number&#60;br /&#62;
    tone_burst_cycles   = 10;                % number of emitted cycles working at &#34;source_freq&#34;&#60;br /&#62;
    t_end   = 3*aperture*1e-3/c_min+tone_burst_cycles/source_freq;	% total time of wave propagation [s]&#60;br /&#62;
    kgrid.t_array  = makeTime(kgrid, c_max, cfl, t_end);            % calculate time steps&#60;/p&#62;
&#60;p&#62;    input_signal   = p0 * toneBurst(1/kgrid.dt, source_freq, tone_burst_cycles,'Envelope',[1 1],'SignalLength',150);   % obtain the emitted burst signal waveform [Pa]&#60;/p&#62;
&#60;p&#62;%% Beamforming: Calculation of delays&#60;/p&#62;
&#60;p&#62;%-------------------- Version Romain --------------------------&#60;/p&#62;
&#60;p&#62;    % Set the configuration if no beanforming used&#60;br /&#62;
    if strcmp(beamforming, 'no')&#60;br /&#62;
        %Set same identification to all rings&#60;br /&#62;
        source.p_mask( source.p_mask &#38;gt; 0 ) = 1;&#60;br /&#62;
        %Set same signal for all transducer elements&#60;br /&#62;
        source.p = input_signal;&#60;/p&#62;
&#60;p&#62;    else&#60;br /&#62;
    % Create CenterRings for delays calculation&#60;br /&#62;
        % rc is the radius that cuts a ring into two subrings of equal surface area&#60;br /&#62;
        % rc, distance from the center of the rings to Z axis knowed from datasheet&#60;br /&#62;
        CenterLines       = zeros(Nz,Ny);&#60;br /&#62;
        rc                = [18.6; 22.98; 26.59; 29.67];&#60;br /&#62;
        radioCenterCircle = (1e-3 *rc)/ds - ds;    % in grid number&#60;/p&#62;
&#60;p&#62;        for i=1:length(apertureIn)&#60;br /&#62;
            CenterLines     = CenterLines + ...&#60;br /&#62;
                              makeLine( Nz,Ny,...&#60;br /&#62;
                                        [1 , round(Ny/2 + radioCenterCircle(i))],...&#60;br /&#62;
                                        [Nz, round(Ny/2 + radioCenterCircle(i))]...&#60;br /&#62;
                                       );&#60;br /&#62;
        end&#60;br /&#62;
        figure;imagesc(CenterLines); axis image;&#60;/p&#62;
&#60;p&#62;    % Delays calculation&#60;br /&#62;
        % Create a ZY axial plane of geom&#60;br /&#62;
        geom_ZYplane    = geom(:,:,round(Nx/2));&#60;/p&#62;
&#60;p&#62;        % Find index where CenterLines intercept geometry source ZY plane&#60;br /&#62;
        [intercept_z,intercept_y] = find((geom_ZYplane==CenterLines).*(geom_ZYplane&#38;gt;0));&#60;br /&#62;
        intercept_x         = intercept_y&#60;br /&#62;
        NcenterRings        = cat(2,intercept_z,intercept_y,intercept_x)&#60;/p&#62;
&#60;p&#62;        % Calculate propagation times and delays for each rings&#60;br /&#62;
        Nzf                     = round(zf/ds)                  % Desired Z axis focus distance&#60;br /&#62;
        Nfocal                  = [PML_size+Nz_trans_pos+Nzf, round(Ny/2), round(Nx/2)] ;&#60;br /&#62;
        Nfocal                  = repmat(Nfocal,length(ri),1)&#60;br /&#62;
        NcenterRings2focus      = Nfocal - NcenterRings&#60;br /&#62;
        centerRings2focus       = abs(NcenterRings2focus) * ds   % convert to distancee&#60;br /&#62;
        centerRings2focus_distance      = sqrt(centerRings2focus(:,1).^2 + centerRings2focus(:,2).^2)&#60;br /&#62;
        centerRings2focus_propaTime     = centerRings2focus_distance ./ c0(1)&#60;br /&#62;
        centerRings2focus_delays        = max(centerRings2focus_propaTime) - centerRings2focus_propaTime   &#60;/p&#62;
&#60;p&#62;        % Convert delays in (s) to number of samples&#60;br /&#62;
        tone_burst_offset     = round(centerRings2focus_delays ./ kgrid.dt);  % transpose to obtain a row vector&#60;/p&#62;
&#60;p&#62;        % Create signals&#60;br /&#62;
        input_signals   = p0*toneBurst(1/kgrid.dt, source_freq, tone_burst_cycles,...&#60;br /&#62;
                         'Envelope',[1 , 1],'SignalLength',150, 'SignalOffset', tone_burst_offset);&#60;br /&#62;
        % Plot signals&#60;br /&#62;
        figure;&#60;br /&#62;
        t_axis = (1:size(input_signals, 2)) * kgrid.dt;&#60;br /&#62;
        stackedPlot(1e6 * t_axis, input_signals);&#60;br /&#62;
        xlabel('Time [\mus]');&#60;br /&#62;
        ylabel('Signal Number');&#60;/p&#62;
&#60;p&#62;        % Set signals for all transducer elements&#60;br /&#62;
        source.p = input_signals;&#60;/p&#62;
&#60;p&#62;unning k-Wave simulation...&#60;br /&#62;
  start time: 16-Apr-2021 01:13:06&#60;br /&#62;
  reference sound speed: 1482.4595m/s&#60;br /&#62;
  dt: 86.3636ns, t_end: 134.6409us, time steps: 1560&#60;br /&#62;
  input grid size: 224 by 225 by 225 grid points (95.5962 by 96.0229 by 96.0229mm)&#60;br /&#62;
  maximum supported frequency: 1.7368MHz by 1.7291MHz by 1.7291MHz&#60;br /&#62;
  precomputation completed in 0.62563s&#60;br /&#62;
  saving input files to disk...&#60;br /&#62;
  completed in 0.62381s&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
&#124;                   kspaceFirstOrder-OMP v1.3                   &#124;&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
&#124; Reading simulation configuration:                        Done &#124;&#60;br /&#62;
&#124; Number of CPU threads:                                     40 &#124;&#60;br /&#62;
&#124; Processor name:     Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz &#124;&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
&#124;                      Simulation details                       &#124;&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
&#124; Domain dimensions:                            224 x 225 x 225 &#124;&#60;br /&#62;
&#124; Medium type:                                               3D &#124;&#60;br /&#62;
&#124; Simulation time steps:                                   1560 &#124;&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
&#124;                        Initialization                         &#124;&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
&#124; Memory allocation:                                       Done &#124;&#60;br /&#62;
&#124; Data loading:                                          Failed &#124;&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
&#124;            !!! K-Wave experienced a fatal error !!!           &#124;&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
&#124; Error: Dataset p_source_input has wrong dimension sizes.:     &#124;&#60;br /&#62;
&#124;        iostream stream error                                  &#124;&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
&#124;                      Execution terminated                     &#124;&#60;br /&#62;
+---------------------------------------------------------------+&#60;br /&#62;
Error using h5readc&#60;br /&#62;
Unable to open file. Filename may be corrupt or have unsupported characters.&#60;/p&#62;
&#60;p&#62;Error in h5read (line 58)&#60;br /&#62;
[data,var_class] = h5readc(Filename,Dataset,start,count,stride);&#60;/p&#62;
&#60;p&#62;Error in kspaceFirstOrder3DC (line 569)&#60;br /&#62;
Nx = h5read(output_filename, '/Nx');&#60;/p&#62;
&#60;p&#62;Error in eye_acoustic_sim_Ta_multiRings (line 552)&#60;br /&#62;
sensor_data = kspaceFirstOrder3DC(kgrid, medium, source, sensor, input_args{:},&#60;br /&#62;
'DataPath',tempPath);    % simulation
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bradley Treeby on "Creating a waveform with custom time offsets"</title>
			<link>http://www.k-wave.org/forum/topic/creating-a-waveform-with-custom-time-offsets#post-5965</link>
			<pubDate>Mon, 29 May 2017 08:58:55 +0000</pubDate>
			<dc:creator>Bradley Treeby</dc:creator>
			<guid isPermaLink="false">5965@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;The &#60;code&#62;&#38;#39;SignalOffset&#38;#39;&#60;/code&#62; input for the &#60;code&#62;toneBurst&#60;/code&#62; function is given in units of time samples, i.e., actual time divided by dt. There should be details in the help for &#60;code&#62;toneBurst&#60;/code&#62;. The 40 is used to add a constant offset to prevent negative values. This number just delays the source (try changing it to 20 and running the example).
&#60;/p&#62;</description>
		</item>
		<item>
			<title>kcox on "Creating a waveform with custom time offsets"</title>
			<link>http://www.k-wave.org/forum/topic/creating-a-waveform-with-custom-time-offsets#post-5962</link>
			<pubDate>Fri, 26 May 2017 18:24:05 +0000</pubDate>
			<dc:creator>kcox</dc:creator>
			<guid isPermaLink="false">5962@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Also, where does the '40' in the following equation for the tone_burst_offset come from?&#60;/p&#62;
&#60;p&#62;tone_burst_offset = 40 + element_spacing*element_index*sin(steering_angle*pi/180)/(medium.sound_speed*dt)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>kcox on "Creating a waveform with custom time offsets"</title>
			<link>http://www.k-wave.org/forum/topic/creating-a-waveform-with-custom-time-offsets#post-5961</link>
			<pubDate>Fri, 26 May 2017 18:14:14 +0000</pubDate>
			<dc:creator>kcox</dc:creator>
			<guid isPermaLink="false">5961@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hey there,&#60;/p&#62;
&#60;p&#62;I modified the steering the linear array example to have all elements fire at the appropriate times in order to meet at some desired focus. However, to get it to work, I had to apply a mock signal for a set amount of time, as I was not using the toneBurst function. I was wondering what units the tone_burst_offset is, so that I can't apply a similar concept to my function and get waveforms representative of actual acoustic sources. My code is shown below:&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% SIMULATION&#60;br /&#62;
% =========================================================================&#60;br /&#62;
clear all&#60;br /&#62;
close all&#60;/p&#62;
&#60;p&#62;% create the computational grid&#60;br /&#62;
Nx = 216;           % number of grid points in the x (row) direction&#60;br /&#62;
Ny = Nx;            % number of grid points in the y (column) direction&#60;br /&#62;
dx = 50e-3/Nx;    	% grid point spacing in the x direction [m]&#60;br /&#62;
dy = dx;            % grid point spacing in the y direction [m]&#60;br /&#62;
kgrid = makeGrid(Nx, dx, Ny, dy);&#60;/p&#62;
&#60;p&#62;% define the properties of the propagation medium&#60;br /&#62;
medium.sound_speed = 1500;  % [m/s]&#60;br /&#62;
medium.alpha_power = 1.5;   % [dB/(MHz^y cm)]&#60;br /&#62;
medium.alpha_coeff = 0.75;  % [dB/(MHz^y cm)]&#60;br /&#62;
medium.density = 1;&#60;/p&#62;
&#60;p&#62;% create the time array&#60;br /&#62;
[kgrid.t_array, dt] = makeTime(kgrid, medium.sound_speed);&#60;br /&#62;
kgrid.t_array = 0:dt:1000*dt;&#60;/p&#62;
&#60;p&#62;% define sensor for entire grid&#60;br /&#62;
sensor.mask = zeros(Nx, Ny);&#60;br /&#62;
sensor.mask = ones(size(sensor.mask));&#60;/p&#62;
&#60;p&#62;% define source mask for a linear transducer&#60;br /&#62;
num_elements = 216; % [grid points]&#60;br /&#62;
x_offset = 10; % [grid points]&#60;br /&#62;
source.p_mask = zeros(Nx, Ny);&#60;br /&#62;
start_index = Ny/2 - round(num_elements/2) + 1;&#60;br /&#62;
source.p_mask(x_offset, start_index:start_index + num_elements - 1) = 1;&#60;/p&#62;
&#60;p&#62;% define the properties of the tone burst used to drive the transducer&#60;br /&#62;
sampling_freq = 1/dt; % [Hz]&#60;br /&#62;
steering_angle = 0; % [deg]&#60;br /&#62;
element_spacing = dx; % [m]&#60;br /&#62;
tone_burst_freq = 12e6; % [Hz]&#60;br /&#62;
tone_burst_cycles = 10;&#60;/p&#62;
&#60;p&#62;% finds x and y positions of the elements&#60;br /&#62;
[x_pos,y_pos] = ind2sub([Nx,Ny],find(source.p_mask == 1));&#60;/p&#62;
&#60;p&#62;% define x and y position of the desired focus location&#60;br /&#62;
x_focus = 120;&#60;br /&#62;
y_focus = Nx/2;&#60;/p&#62;
&#60;p&#62;% calculate distances between elements and focus location&#60;br /&#62;
dists = sqrt((x_focus - x_pos).^2 + (y_focus - y_pos).^2);&#60;/p&#62;
&#60;p&#62;% calculate number of actual steps&#60;br /&#62;
steps = dists.*kgrid.dx;&#60;/p&#62;
&#60;p&#62;% calculate the times&#60;br /&#62;
times = steps./medium.sound_speed;&#60;/p&#62;
&#60;p&#62;% calculate the actual time steps&#60;br /&#62;
timesteps = round(times./kgrid.dt);&#60;/p&#62;
&#60;p&#62;% calculate time delays&#60;br /&#62;
istarts = round(max(timesteps)+1-timesteps);&#60;/p&#62;
&#60;p&#62;% signal = toneBurstCopy(sampling_freq, tone_burst_freq, tone_burst_cycles);&#60;/p&#62;
&#60;p&#62;for ii = 1:num_elements&#60;br /&#62;
    source.p(ii,istarts(ii):istarts(ii)+3) = 5*sin(2*pi*tone_burst_freq*dt);&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;input_args = {'DisplayMask', source.p_mask};&#60;/p&#62;
&#60;p&#62;% run the simulation&#60;br /&#62;
sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% VISUALISATION&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% plot the input time series&#60;br /&#62;
figure;&#60;br /&#62;
num_source_time_points = length(source.p(1,:));&#60;br /&#62;
[t_sc, scale, prefix] = scaleSI(kgrid.t_array(num_source_time_points));&#60;br /&#62;
stackedPlot(kgrid.t_array(1:num_source_time_points)*scale, source.p);&#60;br /&#62;
xlabel(['Time [' prefix 's]']);&#60;br /&#62;
ylabel('Input Signals');&#60;/p&#62;
&#60;p&#62;% reshaping of sensor_data to show acoustic field and focus point&#60;br /&#62;
size_sensor_data = size(sensor_data);&#60;br /&#62;
dimx = sqrt(size_sensor_data(1));&#60;br /&#62;
dimy = dimx;&#60;br /&#62;
dimz = size_sensor_data(2);&#60;/p&#62;
&#60;p&#62;tmp = reshape(sensor_data,dimx,dimy,dimz);&#60;br /&#62;
tmp2 = max(tmp,[],3);&#60;/p&#62;
&#60;p&#62;figure&#60;br /&#62;
imagesc(tmp2)
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
