ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

demod.glsl (1356B)


      1 /* See LICENSE for license details. */
      2 layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in;
      3 
      4 layout(std430, binding = 1) readonly restrict buffer buffer_1 {
      5 	vec2 in_data[];
      6 };
      7 
      8 layout(std430, binding = 2) writeonly restrict buffer buffer_2 {
      9 	vec2 out_data[];
     10 };
     11 
     12 layout(std430, binding = 3) readonly restrict buffer buffer_3 {
     13 	float filter_coefficients[];
     14 };
     15 
     16 layout(location = 0) uniform uint u_filter_order = 0;
     17 
     18 void main()
     19 {
     20 	uint time_sample = gl_GlobalInvocationID.x;
     21 	uint channel     = gl_GlobalInvocationID.y;
     22 	uint acq         = gl_GlobalInvocationID.z;
     23 
     24 	/* NOTE: offsets for storing the results in the output data */
     25 	uint stride = dec_data_dim.x * dec_data_dim.y;
     26 	uint off    = dec_data_dim.x * channel + stride * acq + time_sample;
     27 
     28 	/* NOTE: for calculating full-band I-Q data; needs to be stepped in loop */
     29 	float arg       = radians(360) * center_frequency * time_sample / sampling_frequency;
     30 	float arg_delta = radians(360) * center_frequency / sampling_frequency;
     31 
     32 	vec2 sum = vec2(0);
     33 	for (int i = 0; i <= u_filter_order; i++) {
     34 		vec2 data;
     35 		/* NOTE: make sure data samples come from the same acquisition */
     36 		if (time_sample >= i) data = in_data[off - i].xx * vec2(cos(arg), sin(arg));
     37 		else                  data = vec2(0);
     38 		sum += filter_coefficients[i] * data;
     39 		arg -= arg_delta;
     40 	}
     41 	out_data[off] = sum;
     42 }