Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ultra sound problem. Tackle today – ideas for Assignment 2 Describe the ultrasound problem XPI lifecycle Stage 1 – Discuss with research team (customer)

Similar presentations


Presentation on theme: "Ultra sound problem. Tackle today – ideas for Assignment 2 Describe the ultrasound problem XPI lifecycle Stage 1 – Discuss with research team (customer)"— Presentation transcript:

1 Ultra sound problem

2 Tackle today – ideas for Assignment 2 Describe the ultrasound problem XPI lifecycle Stage 1 – Discuss with research team (customer) Proposed solution XPI lifecycle Stage 2 – Work out algorithm in Matlab XPI lifecycle Stage 3 – Move to C++ code XPI lifecycle Stage 4 – Move to optimized C++ code (and learn how to use all C++ pragmas properly) NEW XPI lifecycle Stage 5 – Move code to custom DSP accelerator 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 2 / 33

3 Research Team discussion Ultra-sound probe (20 MHz) that sends out signals into body that reflect off moving blood cells in (Artery? Vein?) Ultra-sound frequency received is Doppler shifted compared to transmitted frequency Same as sound when ambulance goes by. Higher if approaching, lower if receding They get the positive frequencies (towards) on the left audio channel and negative frequencies (away) on the right audio channel. 11/1/2015.ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 3 / 33

4 Picture looks like this Note that the display loses all direction information Can I help them to output the maximum frequency? 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 4 / 33

5 My response No -- it can’t be done But I am willing to negotiate that answer – we might get a rough answer 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 5 / 33

6 Doppler Effect – Understand the Math Sound frequency we hear is governed by frequency * wavelength = velocity of sound Not velocity in air, but in human body – which means it might be changing as it passes through different body parts. Also get noise from sound reflections from body part boundaries W. A. I. L. – assume constant velocity 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 6 / 33

7 Understand the Math Object moving away from us Object stationary Sound pressure waves are bouncing off object Maximum in sound pressure waves are a distance of wavelength apart Object moving away from us at speed Vobj First sound pressure maximum bounces off object Second sound pressure maximum has to catch up with moving object which has moved a distance Xobj in the time between maximums Apparent wavelength = wavelength + Xobj 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 7 / 33

8 Doppler numbers frequency * wavelength = velocitySound Becomes apparentFrequency * apparentWavelenth = velocitySound apparentFrequency = velocitySound / apparentWavelength = velocitySound / (wavelength + Xobj) wavelength = velocitySound / frequency Xobj = velocityObject * (time for sound wave to catch up) Time to catch up = Xobj / velocitySound Xobj = velocityObject * Xobj / velocitySound 1 = velocityObject / velocitySound -- OOPS Something wrong 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 8 / 33

9 Try again If object was not moving – next sound pressure maximum arrives in time deltaT = 1 / freq (s) Object has moved a distance Vobj * deltaT in that time Therefore when the pressure maximum bounces off the object, the distance between pressure maximum has increased to wavelength + Vobj * deltaT WAIT-A-MO – By the time the pressure maximum has gone that distance object has moved again! True – this means that the changed wavelength is longer than wavelength + Vobj * deltaT. In fact if the object is moving fast enough – no sound waves will bounce off the object Assume that Vobj is much slower than Vsound. Expect this to be valid in body – but might not be – not domain expert 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 9 / 22

10 Doppler numbers frequency * wavelength = velocitySound Becomes apparentFrequency * apparentWavelenth = velocitySound apparentFrequency = velocitySound / apparentWavelength = velocitySound / (wavelength + Xobj) wavelength = velocitySound / frequency Xobj = Vobj * deltaT = Vobj / frequency apparentFrequency = velocitySound / apparentWavelength = velocitySound / (velocitySound / frequency + Vobj / frequency) = frequency * velocitySound / (velocitySound + Vobj) 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 10 / 33

11 Physiological B of E calculation apparentFrequency = frequency * velocitySound / (velocitySound + Vobj) FrequencyChange = apparentFrequency – frequency = frequency * (velocitySound / (velocitySound + Vobj) – 1) = frequency * (-Vobj / (velocitySound + Vobj) = frequency * (-Vobj / velocitySound); velocitySound >> Vobj Vobj = - FrequencyChange * velocitySound / frequency Are the body measurements consistent with the theory? Assume – ultrasound is 20 Mz and change in frequency maximum = 6 kHz Vobj = - 6 * 10^3 * velocitySound / 20 * 10^ 6 = 0.3 * 10 ^-3 * velocitySound Assume –velocitySound = 5 * velocitySoundAir = 1500 m / s Vobj = 0.3 * 1.5 m / s = 0.5 m/s Car = 50 km / hour = 50,000 / 3600 m / s = 15 m / s Blood cells moving around 2 km / hour – is that correct? 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 11 / 33

12 Look at customer picture We said (B of E calculation) Max velocity = 0.5 m / s = 50 cm / s Actual maximum around 150 cm / s velocitySound = 15 * velocitySoundAir = 4500 m / s 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 12 / 33

13 XPI-Inspired Life cycle Stage 1 Further talks with customer Positive frequencies (towards) on the left audio channel and negative frequencies (away) on the right audio channel GUESS WHATS HAPPENING – Model correct, details ??? Signal is 20 MHz + 4 kHz and 20 MHz – 5 kHz from two blood cells Filter signal 20 MHz  20 MHz + 4 * MaxFrequency. Down shift to 0 Hz, and output on Left Channel Filter signal 20 MHz  20 MHz - 4 * MaxFrequency. Down shift to 0 Hz, and output on Right Channel Guess why – audio interpretation of blood flow 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 13 / 33

14 XPI-Inspired Life cycle Stage 2 Move to Matlab Many built-in “trusted” algorithms (have found some wrong) Easy to visualize via plots Have not found a good automated testing framework Algorithm pseudo code Gather blocks of audio data – size N – left and right NO hassle – 6 kHz will be easily handled by SHARC A/D Perform DFT on both channels (discrete Fourier transform) Engineering problem 1 – Complex math (a + jb) on SHARC! Find maximum frequency left and right from DFT Engineering Problem 2 – Define maximum frequency zillions of blood cells – therefore distribution of frequencies If (max Forward > max Reverse) return Forward else return –Reverse Send DC representation of frequency to 1 of 16 channels of (OLD?) analogue digital chart recorder to record along side other physiological signals Engineering Problem 3 – SHARC D/A can’t handle DC signal Engineering Problem 4 – Can SHARC handle all this in real-time? 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 14 / 33

15 Captured audio signal 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 15 / 33 More Engineering Problems Problem 5 – Is different amplitudes common? Problem 6 – Why are funny dead spots not lining up in left and right channels? Real or artifact? Guess – channels not recorded at same time for this prototype Problem 7 – How to remove dead-spots?

16 Max frequency – definition 1 Frequency below which X% of the frequencies fall Noisy signal for large thresholds > 80% 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 16 / 33

17 Max frequency – definition 2 Frequency containing most cells – with a certain band of frequencies There was multiple bands of near similar frequency max Useful info? 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 17 / 33

18 Special tricks employed Fourier interpolation to improve frequency resolution Modulate DC signal on top of 2 kHz audio signal Output from SHARC Amplify using home audio system Now rectify and smooth and send to channel recorder 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 18 / 33

19 After XPI Stage 2 Have a working algorithm concept Engineering problem 1 – Complex math (a + jb) on SHARC! Engineering Problem 2 – Define maximum frequency zillions of blood cells – therefore distribution of frequencies Workable prototype – discuss more with customer Engineering Problem 3 – SHARC D/A can’t handle DC signal Workable prototype – discuss more with customer Engineering Problem 4 – Can SHARC handle all this in real-time? Problem 5 – Is different amplitudes common? Discuss more with customer Problem 6 – Why are funny dead spots not lining up in left and right channels? Real or artifact? Guess – channels not recorded at same time for this prototype Discuss more with customer – Get second set of samples Problem 7 – How to remove dead-spots? – Discuss more with customer 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 19 / 33

20 XPI Stage 3 – Move to C++ Good starting point – working MatLab code Start with known signals -- TestVectorIn Pass through Matlab to get known results TestVectorOut Generate tests that the C++ code must satisfy OFF-LINE Can TEST with TestVectorIn and TestVectorOut hard-coded in C++ memory ON-LINE – Biggest worry, need block of data and process it 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 20 / 33

21 Assignment 1, Labs 1, 2 and 3 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 21 / 33

22 Slightly faster version 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 22 / 33

23 New C++ optimization approach #pragma always_inline inline void ProcessOnePoint(void) { 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 23 / 33

24 This works PROVIDES deltaT = 1 / 41000 s Time to do one point Operating system Time to do a task Time to input Time to process Time to output 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 24 / 33

25 Need to process “One Block” This form of the program does not generate blocks – samples the same point 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 25 / 33

26 Version 2 Captures a block But outputs all points very quickly into Left_Out Hear one point then silence 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 26 / 33

27 Version 3 Capture Process Output Capture Process Output 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 27 / 33

28 Version 3 – Curate’s Egg Famous 1820 joke Works well occasionally 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 28 / 33 CAPTUREN * deltaT PROCESSHow long does it take? OUTPUTN * deltaT CAPTUREN * deltaT PROCESSHow long does it take? OUTPUTN * deltaT

29 Version 3 – Look at efficiency 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 29 / 33 CAPTUREWASTED CPU TIME SILENCE LOST DATAPROCESSSILENCE LOST DATAWASTED CPU TIME OUTPUT CAPTUREWASTED CPU TIME SILENCE LOST DATAPROCESSSILENCE LOST DATAWASTED CPU TIME OUTPUT CAPTURE1 CAPTURE2PROCESS1 CAPTURE3PROCESS2OUTPUT1 CAPTURE4PROCESS3OUTPUT2 CAPTURE5PROCESS4OUTPUT3 CAPTURE6PROCESS5OUTPUT4

30 This code only works if Time for ProcessOneBlock < deltaT (1 / 41000 s) Unnecessary Race problem 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 30 / 33

31 ProcessBlock DONE OUTSIDE INTERRUPT AVOIDS RACE 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 31 / 33

32 Problems to watch for #pragma always_inline inline void ProcessOneBlock(float *inBuffer, float *outBuffer) { for (int count = 0; count < PROCESS_BUFFER_LENGTH; count++) { outBuffer[count] = inBuffer[count]; } inline void ProcessFIROneBlock(float *inBuffer, float *outBuffer) { When doing N point FIR on data block Processing first point in buffer then need N – 1 points from previous blocks } 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 32 / 33

33 Speed issues when processing block Suppose N points and M tap FIR then time taken Order (N * M) where N = 256 and FIR order = 256 -> k * 256 * 256 Can do filtering in frequency domain Do FFT – takes time Order(N log N) Do Multiplication in frequency domain Order (N) Do Inverse FFT – takes time Order(N log N) Time roughly Order(2N log N + N) K’ * (2 * 256 * log(256) + 256) = K’ * 256 * (16 + 1)) Time domain calculation is slower 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 33 / 33

34 Ready to solve the ultrasound problem 11/1/2015 ENCM515 – Ultrasound Problem Copyright smithmr@ucalgary.ca 34 / 33


Download ppt "Ultra sound problem. Tackle today – ideas for Assignment 2 Describe the ultrasound problem XPI lifecycle Stage 1 – Discuss with research team (customer)"

Similar presentations


Ads by Google