Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 108 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
108
Dung lượng
2,92 MB
Nội dung
The University of Leeds School of Electronic & Electrical Engineering Declaration of Academic Integrity Student Name: BAO QUOC BUI University ID Number: 200508603 Modules: ELEC 5880 & 5881 Module Leader: Dr Chris Trayner Plagiarism in University Assessments and the Presentation of Fraudulent or Fabricated Coursework Plagiarism is defined as presenting someone else’s work as your own Work means any intellectual output, and typically includes text, data, images, sound or performance [1] Fraudulent or fabricated coursework is defined as work, particularly reports of laboratory or practical work that is untrue and/or made up, submitted to satisfy the requirements of a University Assessment in whole or in part [1] Declaration: • I have read the University Regulations on Cheating and Plagiarism[2] and state that the work in this report is my own and does not contain any unacknowledged work from other sources • I confirm that any mitigating circumstances or other matters which might have affected my performance and which I wish to bring to the attention of the examiners/markers have been submitted to the Secretary of the Director of Learning & Teaching [Jennifer Finnigan, School of Electronic & Electrical Engineering] Signed Date [1] http://www.leeds.ac.uk/AAandR/cpff.htm [2] http://www.leeds.ac.uk/studenthandbook/ BAO QUOC BUI UARP-System Integrated ACKNOWLEDGEMENT In the first place I would like to record my gratitude to Dr Steven Freear for his supervision, advice and guidance from the early stage of this project He provided me encouragement and support in various ways I also gratefully acknowledge Dr David Cowell, Mr Benjamin Raiton and Mr Peter Smith for the continuous support they provided during the project I am grateful to CHAU VO and THINH PHAM for their great help and collaboration At the end, I would like to thank my family and friends for their love, support and encouragement throughout my entire life BAO QUOC BUI UARP-System Integrated Contents Declaration of Academic Integrity Contents List of Figure List of Listing List of Table ABSTRACT 10 Introduction 11 1.1 UARP project: 11 1.2 The contribution of this project in the UARP project: 12 1.3 Organization of the thesis: 13 USB interface implementation 14 2.2 Data transaction in UARP system: 14 2.2 Universal Serial Bus: 14 2.2 Implement the USB interface: 15 2.3.1 Libusb-win32: 15 2.3.2 USB communication in MATLAB: 16 2.3.3 Implementing the DE3_dll library: 17 2.3.4 Communication with UARP hardware using DE3_dll: 24 ULTRASOUND IMAGING WITH UARP SYSTEM 26 3.1 Ultrasound imaging 26 3.1.1 Introduction 26 3.1.2 Beam forming: 27 3.1.3 Linear array and phased array: 29 3.1.4 Absorption and time gain control (TGC) 30 3.1.5 Data processing 31 3.2 Ultrasound imaging with Matlab and UARP system 34 3.2.1 Simulating with MATLAB: 34 3.2.1.1 Delay calculation: 34 3.2.1.2 Beam former using MATLAB: 35 3.2.1.3 Envelope detection using MATLAB: 36 3.2.1.4 Scan conversion and compression for linear array transducer: 37 3.2.1.5 Simulating the imaging system: 37 3.2.2 Generating image with data from UARP hardware 38 BAO QUOC BUI UARP-System Integrated 3.2.2.1 Generating image with ramp function from ADC: 38 3.2.2.2 Generating image with data from transducer: 40 GPU PROGRAMMING 46 4.1 GPU programming 46 4.1.1 Introduction 46 4.1.2 Programming model 47 4.1.2.1 Data partitioning: 47 4.1.2.2 Memory hierarchy: 48 4.1.2.3 Host and device: 48 4.1.3 CUDA programming 49 4.1.3.1 Vector add example: 49 4.1.3.2 Optimization: 51 4.1.4 Interfacing between CUDA and MATLAB 51 4.1.4.1 MATLAB mex file: 51 4.1.4.2 CUDA-enabled MEX files: 53 4.1.5 Ultrasound imaging with CUDA and MATLAB 54 4.1.5.1 Beamformer using CUDA: 54 4.1.5.2 Simulation result: 56 4.2 JACKET 57 4.2.1 JACKET and MATLAB 57 4.2.2 JACKET custom mex file 58 4.2.3 Implementation of custom JACKET mexfile for beamforming: 58 4.2.3.1 Simulation result with JACKET beamformer function: 59 Benchmarking 61 5.1 Benchmark of USB_dll: 61 5.2 Benchmark of beamforming functions: 62 Conclusion: 63 Future work: 64 7.1 Ultrasound imaging with phased array transducer: 64 7.2 Fractional delay filters implementation: 64 Reference 65 Appendix A- Source code for the USB library 67 USB_dll.h 67 USB_dll.c 68 BAO QUOC BUI UARP-System Integrated Makefile to compile the dll 76 Appendix B- MATLAB source code 77 MATLAB simulation code 77 MATLAB simulation code using CUDA beamformer function 79 MATLAB simulation code using JACKET 81 MATLAB function convfft: 83 MATLAB function UARP_focus_delay: 84 MATLAB function UARP_DelayTime2Samples: 85 MATLAB function UARP_envelop_detector: 86 MATLAB simulation code for function UARP_envelop_detector: 87 MATLAB source for generating image from ramp signal: 88 10 MATLAB source for generating image from transducer, one element in a sub-array: 90 11 MATLAB source for generating image from transducer, elements in a sub-array: 93 12 MATLAB source for exciting a elements in transducer 96 13 MATLAB source for exciting a sub-array of elements in transducer 97 Appendix C- Source code for GPU computing 98 Source code for CUDA beamformer 98 Source code for JACKET beamformer 102 Appendix D- Software installation 106 LibUSB driver 106 1.1 Compilation: 106 1.2 Driver installation: 106 Dll development environment 107 Setup cuda_mex compiler for CUDA mex file: 107 BAO QUOC BUI UARP-System Integrated List of Figure Figure 1: The contribution of this project in UARP Project 12 Figure 2: System Overview 13 Figure 3:USB communication stack 17 Figure 4: Synchronous read process 21 Figure 5: Asynchronous read process 22 Figure 6:Non-blocking read functions 23 Figure 7: Block diagram of an ultrasound system 26 Figure 8: Sound wave focusing [14] 26 Figure 9: Pregnancy Ultrasound Picture [15] 27 Figure 10: Interference waves [16] 28 Figure 11: Beam Focusing [17] 28 Figure 12: Beam steering [17] 28 Figure 13: Receive beamforming [18] 29 Figure 14: Linear vs phased array imaging [14] 30 Figure 15: Reflected ultrasound wave along a scan line 31 Figure 16: Data processing 31 Figure 17: Back-end processing for image display [21] 33 Figure 18: Scan conversion [14] 33 Figure 19: Delay calculation 34 Figure 20: Simulate result for envelope detection function 37 Figure 21: Linear Array simulation image 38 Figure 22: Generating image with ramp data from ADC module 39 Figure 23: Image created from ramp function 39 Figure 24: Integrated system 40 Figure 25: Reflected wave along a scan line 41 Figure 26: Reflected signal after filtering 41 Figure 27: Envelope signal 42 Figure 28: Scanned object diagram 43 Figure 29: Result image for imaging system with sub-array aperture of 43 Figure 30: Result image of system with sub-array aperture of 44 Figure 31: Result image of system with sub-array aperture of 44 Figure 32: Result image of system with sub-array aperture of 16 45 BAO QUOC BUI UARP-System Integrated Figure 33: GPU program model: CPU and GPU together [25] 46 Figure 34: Data partition in CUDA program [26] 47 Figure 35: Memory hierarchy [26] 48 Figure 36: Heterogeneous programming 49 Figure 37: Result image when simulating with CUDA beamformer 57 BAO QUOC BUI UARP-System Integrated List of Listing Listing 1: Vector summation program 50 Listing 2: Structure of mex file 52 Listing 3: Code of mex_add.c source file 52 Listing 4: Code of CUDA-enabled mexfile mex_CUDA_add.cu 54 Listing 5: Basic structure of a custom JACKET mex file 58 BAO QUOC BUI UARP-System Integrated List of Table Table 1: Ultrasound imaging simulation time with beamformer using MATLAB code 38 Table 2: Ultrasound imaging simulation time with beamformer using CUDA code 57 Table 3: Ultrasound simulation time using JACKET code 59 Table 4: Speed of read_dev and read_channels command 61 Table 5: Speed of non-blocking read command 62 Table 6: Execution time for beamforming function 62 BAO QUOC BUI UARP-System Integrated 11 MATLAB source for generating image from transducer, elements in a sub-array: clear all %close all DEPTH = 8*1024; data = zeros(DEPTH/2,8); outdata = zeros(DEPTH/2,8); loaddll % TX boards US_Send_Command( 0, 2, 0, ) % Disable all pulsers US_Set_TX_Boards % disble all TX channels (from cyclon) % RX boards calllib('USB_dll', 'set_channel_capacity',DEPTH); depth = calllib('USB_dll', 'read_channel_capacity') US_Set_Config US_Set_rxChannel_Enable('00FFFFFF','00FFFFFF','00000000','00000000') US_Send_Command( 0, 3, 0, ); % Enable all pulsers chip % carrier frequency (MHz) f0=5; % sound velocity (mm/us) c=5.92; % ultrasound wavelength (mm) lambda=c/f0; d=0.3; % element spacing (mm) % number of elements M=48; Ns = ; %number of transducer in sub array fs=40; % RF sampling frequency (Ms/sec) N = 1024 *4; % number of points in each RF signal Rf = 20; length = 100; %depth of image = 75 mm %number of interest samples in one scan line num_samples = round ((2*length / c)*fs); %the delay time to focus the beam to focal length delay = (UARP_Focus_Delay( c,f0, Rf,Ns )'); Rf DelayInSamples= (UARP_DelayTime2Samples( delay, fs ))'; %convert delay time to delay in number of samples % the weight parameter follow gaussian window law weighted = gausswin(Ns); weighted = (weighted'); weight = weighted(ones(1,N),:); linear_image = (zeros(num_samples,M-Ns+1)); %pre-allocated the image %pre-allocated the image compress_image = (zeros(num_samples,M-Ns+1)); delayed_samples = (zeros(num_samples,Ns)); Outbeam = zeros(num_samples,1); %sampling interval (us) dt = 1/fs; %vector of time (us) t = [1:N]'*dt; z = t*c/2; %collumn vector of distance (mm)(convert from t) % TGC_unit = 0.5; %dB/cm/Mhz % dB_loss = TGC_unit*f0*z/10; %loss in dB % TGC = 10.^(dB_loss); %because attenuation unit in metal is very small, TGC value = TGC = TGC(:,ones(1,Ns)); filter_order = 54; 93 BAO QUOC BUI UARP-System Integrated filter = fir1(filter_order,1/4,gausswin(filter_order +1)); bandpass = fir1(filter_order,[1/5 1/3],gausswin(filter_order +1));%bandpass filter for the fundamental frequency beamformed_data_demod = zeros(num_samples,1); beamformed_data_conv = zeros(filter_order+1+num_samples,1); RF_evelop = zeros(num_samples,1); comlex_down = 2*exp(-j*2*pi*f0*t); beamdata = (zeros(N,Ns)); tmp_data = zeros(N,1); % Initialize the first windows % Pulse %transmit_window(0); %calllib('USB_dll','read_asyn_init',hex2dec('AA000A00'),1,8); %a= calllib('USB_dll','read_asyn_finish',dptr); for counter = 1:1000 for s = [1: 40] %a= calllib('USB_dll','read_asyn_finish',dptr); transmit_window(s-1); %calllib('USB_dll','read_asyn_init',hex2dec('AA000A00'),s+1,8); a= calllib('USB_dll','read_channels',dptr,hex2dec('AA000A00'),s,8) %Calculate data beamdata = double(reshape( typecast(dptr.value(1:8*DEPTH),'int16'), DEPTH/2, )); %beamdata = double(beamdata); %beamdata =( fake_readADC( US_data,s,s+Ns-1 )); %take data from the RF_data file outdata = dummy_filter(beamdata,8,DEPTH/2); %beamdata = (outdata).*weight; beamdata = (beamdata.*weight).*TGC; for i = 1:Ns tmp_data = beamdata(:,i); beamdata(:,i) = [tmp_data((DelayInSamples(i)+1):N ) ;zeros(DelayInSamples(i),1)]; end Outbeam = sum(beamdata,2); data_filter = conv(Outbeam,bandpass); Outbeam = data_filter(1:DEPTH/2); %beamformed_data_conv = conv(beamformed_data_demod,filter)*dt; %beamformed_data_demod =comlex_down.*Outbeam; %RF_evelop=beamformed_data_conv(low:high); % retain sample points from %low:high beamformed_data_conv = abs(hilbert(data_filter)); %perform envelope detect % first index of retained sample low=ceil(filter_order/2); % last index of retained sample high=low+num_samples-1; RF_evelop=beamformed_data_conv(1:num_samples); linear_image(:,s) = abs(RF_evelop); end %change the image to log scale maximage = max(max(abs(linear_image))); compress_image = -20*log10(abs(linear_image)/maximage); % colormap(gray); figure(1); 94 BAO QUOC BUI UARP-System Integrated imagesc(compress_image); end %a= calllib('USB_dll','read_asyn_finish',dptr); unloaddll 95 BAO QUOC BUI UARP-System Integrated 12 MATLAB source for exciting a elements in transducer function transmit_1channel(start_element) %count from %bitmask1 = ['11111111' '11111110' '11111100' '11111000' '11110000' '11100000' '11000000' '10000000' ]; %bitmask2 = ['00000000' '00000001' '00000011' '00000111' '00001111' '00011111' '00111111' '01111111']; board1 = floor((start_element )/8) + if (board1 > 1) board2 = board1 - 1; else board2 = 6; end mask1 = 2^(mod(start_element,8)); mask2 = 0; if (board1 < 7) US_Send_Command( board1, 15, 0, mask1 ) ; %enable transducer in board1 end if (board2 < 7) US_Send_Command( board2, 15, 0, mask2 ); %enable transducer in board2 end US_Send_Command( 0, 1, 0, ); % Pulse all boards from DE3 end 96 BAO QUOC BUI UARP-System Integrated 13 MATLAB source for exciting a sub-array of elements in transducer function transmit_window(start_element) %count from %bitmask1 = ['11111111' '11111110' '11111100' '11111000' '11110000' '11100000' '11000000' '10000000' ]; %bitmask2 = ['00000000' '00000001' '00000011' '00000111' '00001111' %'00011111' '00111111' '01111111']; bitmask1 = [255 254 252 248 240 224 192 128 ]; bitmask2 = [0 15 31 63 127]; board1 = round((start_element )/8) + board2 = board1 + mask1 = bitmask1(mod(start_element,8)+1) mask2 = bitmask2(mod(start_element,8)+1) if (board1 == 1) US_Send_Command( 6, 15, 0, ) ; %disable previous board else US_Send_Command( (board1 - 1), 15, 0, ) ; %disable previous board end if (board1 < 7) US_Send_Command( board1, 15, 0, mask1 ) ; %enable transducer in board1 end if (board2 < 7) US_Send_Command( board2, 15, 0, mask2 ); %enable transducer in board2 end US_Send_Command( 0, 1, 0, ); % Pulse all boards from DE3 end 97 BAO QUOC BUI UARP-System Integrated Appendix C- Source code for GPU computing Source code for CUDA beamformer #include #include #include #include #include "mex.h" //multiply kernel global void multiply(float *out, float *in1, float *in2, float *in3, unsigned int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx