ØVELSE 5

i 31610

2009-03-30

Rasmus Berg Palm s062241

Mads Andersen s062237

Jacob Bjerring Olesen s062248

# Indholdsfortegnelse

# exercise 1

As per the instructions in the assignment 4 signals are created:

- A 2 period 5Mhz sine signal, sig1
- A 20 microsecond white noise signal, sig2
- The signal resulting from the convolution of the above, sig3
- And finally a 0.4 microsecond delayed (zero-prepended) version of number 3, sig3d

The following code was used to accomplish this:

```
%% Ex 1
fs = 100e6; %Mhz
f0 = 5e6; %Mhz
T1 = 2/f0;
t1 = 0:1/fs:(T1-1/fs); %Time axis for sine signal
T2 = 20e-6;
t2 = 0:1/fs:(T2-1/fs); %Time axis for randn signal
sig1 = sin(2*pi*f0*t1);
sig2 = rand(size(t2));
sig3 = conv(sig1,sig2); %The convoluted signal
t3 = 0:1/fs:(length(sig3)-1)/fs;
sig3d = [zeros(1,0.4e-6*fs) sig3]; %The delayed signal
t3d = 0:1/fs:(length(sig3d)-1)/fs;
figure
plot(t1,sig1);
xlabel('Time [s]');
ylabel('Amplitude [V]');
title('2 period 5Mhz sine, sig1');
figure
plot(t2,sig2);
xlabel('Time [s]');
ylabel('Amplitude [V]');
title('20 microseconds of white noise, sig2');
figure
plot(t3,sig3);
xlabel('Time [s]');
ylabel('Amplitude [V]');
title('The convolution of sig1 and sig2: noise polluted 5 Mhz sine, sig3');
figure
plot(t3d,sig3d);
xlabel('Time [s]');
ylabel('Amplitude [V]');
title('0.4 microseconds delayed sig3');
figure
[delay, tlags, corramp] = finddelay(sig3,sig3d,fs,1);
```

which gives the following signals:

The assignment calls for the creation of 2 functions, one that can calculate the delay between two signals And one to 'calculate the cross-correlation function between two signals, and plot the cross-correlation function with the correct axis'. We've chosen to do both in one function.

Below is the code for this function, finddelay()

```
function [delay, tlags, corramp] = finddelay(sig1, sig2, fs, doplot)
%[delay, tlags, corramp] = finddelay(sig1, sig2, fs)
[corramp, lags] = xcorr(sig2,sig1); %Find the correlation
corramp = abs(corramp)./max(corramp); %Normalize the correlation amplitude
tlags = lags/fs; %Create lag axis in seconds
[y,delay] = max(corramp); %Find the maximum correlation
delay = tlags(delay); %Return maximum correlation in seconds (delay)
if(nargin==4 && doplot) %If doplot
figure
plot(tlags, corramp); %Plot the correlation.
xlabel('Lag [s]')
ylabel('Correlation []')
end
```

And when put to the test with the created signals sig3 and sig3d

[delay, tlags, corramp] = finddelay(sig3,sig3d,fs,1);

returns the following result, since doplot=1:

And returned to the matlab workspace is the correct delay equal to 0.4 microseconds, also evident on the above figure.

# exercise 2

Blood velocity ($v_z$) can be found with medical diagnostic ultrasound, by sending out the same pulse again and again, and detecting the time-differences in the received signals. If the time between to pulses sent out is $T_{prf}$, the blood particle that reflects the pulses have moved the distance $d_b=v_zT_{prf}$ in the time between the reflection of the first, and the second pulse. The sound is moving with speed c, and have to move towards the particle, and back. Therefore, If the blood is moving away from the transducer, the received signal from the second pulse is delayed by

(1)compared to the received signal from the first pulse. Hence, if the delay between the two received signals can be determined, the blood velocity can easily be found as

(2)The two received signals are almost identical expect for the timeshift difference. Therefore the delay between the two received sigals can be detemined at the lag corresponding to the maximum in the cross-correlation function of the two signals. In the function findbloodvel, the maximum is found using findelay.m made earlier, and afterwards the bloodvelocity is found from this delay (t_s), time between emission of pulses (Tprf), and the speed of sound in the media:

```
function [v] = findblodvel(sig1, sig2, fs, Tprf, c)
%[v] = findblodvel(sig1, sig2, fs, Tprf, c)
%Finds blood velocity using two recieved ultrasound signals. sig1 and sig2 are the
%received ultrasound signals, originating from the same type of emitted pulse. The time
%between the emissions is Tprf, the sampling frequency is fs, and c is the speed of
%sound in the media.
ts = finddelay(sig1,sig2,fs); %the delay of sig2 compared to sig1
v = (ts*c)/(2*Tprf);% the blood velocity
```

# exercise 3

We were given a dataset, corresponding to 10 pulse-echo signals measured with a sampling frequency at 100MHz, a velocity at 1540 m/s and finally a 200 μsec time spacing in between each measurement. As in part two, cross correlation enable us to calculate the time delay ts and thereby finding the blood velocity.

To determine this, we have modified the function from the previous assignment, so it now calculates the cross correlation of the first and second signal, and afterward of the second and the third and so forth. At last we found the average of all correlations and thereby the duration of the delay, which lead us too a velocity of 0.3080 m/s

```
%% Ex 3
load plug_flow.mat;
&Defining values
Tprf = 200e-6; % Unit: s
c = 1540; % Unit: m/s
v = findmeanvel(data, fs, Tprf, c)
function v = findmeanvel(data, fs, Tprf, c)
%v = findmeanvel(data, fs, Tprf, c)
n = length(data(1,:))-1;
for i=1:n
[delay, tlags, corramp] = finddelay(data(:,i),data(:,i+1),fs);
%Correlates the first signal with the second and the second with the third
and so forth
corrampvec(i,:) = corramp; %Creates a singel colon vector with the
correlated values
end
corrampmean = mean(corrampvec); %Detemine the avarage of the correlations
[y,delay] = max(corrampmean); %Finding the max correlation
ts = tlags(delay); %Converts the lag-axis into units of seconds
v = (ts*c)/(2*Tprf); %Calculates the blood velocity
```

# exercise 4

Exercise 4 examines the velocity found when the RF signal from excersise 3 is divided into 2 microsecond segment.

In exercise3 we loaded plug_flow.mat, probably data simulating plug flow, a model in which the velocity of fluid in a pipe is constant across any cross section.

Drawing on the theory in exercise 5 we relate the segments of RF data to the depth of the recording.

The following code was used to segment the RF data and plot the velocity profile.

```
%% Ex 4
segs = 1:((2e-6)*fs):length(data);
for i=1:length(segs)-1
v(i) = findmeanvel(data(segs(i):segs(i+1),:), fs, Tprf, c);
end
figure
plot((segs(1:length(v))/fs*c)/2,v)
xlabel('depth [m]')
ylabel('velocity [m/s]')
```

which gives the following figure:

In which it seems there is an error. Obviously the 2nd measurement should have been the same as the others, assuming plug flow.

Closer inspection of the averaged cross correlation using this segment reveals:

Two distinct peaks on either side of zero are observed. Their amplitudes are almost equal, but the negative is slightly bigger. The 8 other measurements have their max at the positive peak which results in the velocity of 0.308 m/s.

# exercise 5

The same routine as in exercise 4 is used to find the velocity as a function of depth. The data is divided into segments of 2 microseconds, in which mean velocities are calculated. First a time-, and an indices-vector are made with elements corresponding to the edges of the intervals or segments. Afterwards the meanvelocities in each interval are calculated in a for-loop using findmeanvel.m. The depth corresponding to the time vector is made using the relation $d=tc/2$. The d-vector therefore consists of depths relating to the edges of the intervals from which the mean velocities are calculated. To plot the mean velocities as function of depth, each velocity must relate to a specific depth. We have defined each velocity to relate to the left edge in the interval from which it is calculated.

The matlabscript and the plot made, can be seen beneath:

```
%% Ex 5
load carotis.mat;
%time vector lasting as long as data, with elements spaced 2e-6 s:
t = 1/fs:2e-6:length(data)/fs
%sampling numbers in data corresponding to the time-vector elements:
segs = fs*t;
%finds meanvelocity in 2e-6 s intervals:
for i=1:length(segs)-1
v(i) = findmeanvel(data(segs(i):segs(i+1),:), fs, Tprf, c);
end
%depth vector:
d = t*c/2;
% v(i) to correspond to d(i) - the first point in the interval from which
% v(i) is calculated from:
plot(d(1:length(v)),v)
xlabel('depth [m]')
ylabel('velocity [m/s]')
```

The plot shows that the blood velocity is much faster around the depth 0.02m, this is highly probable because the blood vessel is narrow their, what could be patological, but we let the doctors make the diagnose…