Ultra sound problem
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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 2 / 33
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.
04/20/23.ENCM515 – Ultrasound ProblemCopyright [email protected] 3 / 33
Picture looks like this
Note that the display loses all direction information Can I help them to output the maximum frequency?
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 4 / 33
My response
No -- it can’t be done
But
I am willing to negotiate that answer – we might get a rough answer
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 5 / 33
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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 6 / 33
Understand the MathObject 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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 7 / 33
Doppler numbersfrequency * wavelength = velocitySound BecomesapparentFrequency * 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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 8 / 33
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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 9 / 22
Doppler numbersfrequency * wavelength = velocitySound BecomesapparentFrequency * 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)
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 10 / 33
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 >> VobjVobj = - FrequencyChange * velocitySound / frequency
Are the body measurements consistent with the theory? Assume – ultrasound is 20 Mz and change in frequency maximum = 6 kHzVobj = - 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/sCar = 50 km / hour = 50,000 / 3600 m / s = 15 m / s Blood cells moving around 2 km / hour – is that correct?
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 11 / 33
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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 12 / 33
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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 13 / 33
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?
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 14 / 33
Captured audio signal
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 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?
Max frequency – definition 1 Frequency
below which X% of the frequencies fall
Noisy signal for large thresholds
> 80%
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 16 / 33
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?
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 17 / 33
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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 18 / 33
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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 19 / 33
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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 20 / 33
Assignment 1, Labs 1, 2 and 3
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 21 / 33
Slightly faster version
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 22 / 33
New C++ optimization approach
#pragma always_inlineinline void ProcessOnePoint(void) {
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 23 / 33
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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 24 / 33
Need to process “One Block”
This form of the program does not generate blocks – samples the same point
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 25 / 33
Version 2 Captures a
block But outputs
all points very quickly into Left_Out
Hear one point then silence
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 26 / 33
Version 3CaptureProcessOutput
CaptureProcessOutput
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 27 / 33
Version 3 – Curate’s Egg Famous 1820 joke Works well occasionally
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 28 / 33
CAPTURE N * deltaT
PROCESS How long does it take?
OUTPUT N * deltaT
CAPTURE N * deltaT
PROCESS How long does it take?
OUTPUT N * deltaT
Version 3 – Look at efficiency
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 29 / 33
CAPTURE WASTED CPU TIME
SILENCE
LOST DATA PROCESS SILENCE
LOST DATA WASTED CPU TIME
OUTPUT
CAPTURE WASTED CPU TIME
SILENCE
LOST DATA PROCESS SILENCE
LOST DATA WASTED CPU TIME
OUTPUTCAPTURE1
CAPTURE2 PROCESS1
CAPTURE3 PROCESS2 OUTPUT1
CAPTURE4 PROCESS3 OUTPUT2
CAPTURE5 PROCESS4 OUTPUT3
CAPTURE6 PROCESS5 OUTPUT4
This code only works if
Time for ProcessOneBlock
< deltaT (1 / 41000 s)
Unnecessary Race problem
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 30 / 33
ProcessBlockDONEOUTSIDEINTERRUPT
AVOIDS RACE
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 31 / 33
Problems to watch for#pragma always_inlineinline 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 bufferthen need N – 1 points from previous blocks
}
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 32 / 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
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 33 / 33
Ready to solve the ultrasound problem
04/20/23ENCM515 – Ultrasound ProblemCopyright [email protected] 34 / 33
Top Related