-
Notifications
You must be signed in to change notification settings - Fork 9
/
decode_focused_beams.m
66 lines (58 loc) · 2.4 KB
/
decode_focused_beams.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function [rf_fsa] = decode_focused_beams(rf,transmit_delays,method)
%DECODE_FOCUSED_BEAMS - Decode RF channel data from a set of focused
% transmit beams into the complete data set using the applied focal timings
%
% rf_fsa = decode_focused_beams(rf,transmit_delays);
% rf_fsa = decode_focused_beams(rf,transmit_delays, METHOD);
%
% Decoding can be performed in either the time or frequency domains. The
% two methods produce the same result, but frequency is faster.
%
% Parameters:
% rf - RF data (time sample x receive channel x transmit event)
% transmit_delays - Transmit focal delays in samples (transmit event x transmit element)
% method - 'frequency' or 'time' (default: frequency)
%
% Returns:
% rf_fsa - Decoded complete data set (time sample x receive channel x transmit element)
%
% Author: Nick Bottenus
% Contact: [email protected]
% Check inputs
if(~exist('method','var'))
method='frequency';
else
assert(strcmp(method,'frequency')||strcmp(method,'time'),'Method must be ''frequency'' or ''time''')
end
[n_samples, n_receives, n_transmits]=size(rf);
n_elements=size(transmit_delays,2);
assert(size(transmit_delays,1)==n_transmits,'Transmit event dimensions inconsistent between rf and transmit_timings')
switch method
% ======================================Frequency domain implementation
case 'frequency'
% 1-D FFT to convert time to frequency
RF=fft(single(rf));
RF=permute(RF,[2 3 1]); % (receive channel x transmit event x time sample)
frequency=(0:n_samples-1)/n_samples;
% Apply decoding matrix at each frequency
RF_adj=zeros(n_samples,n_receives,n_elements,'single');
for i=1:ceil(n_samples/2) % only compute half, assume symmetry
omega=2*pi*frequency(i);
Hinv=exp(1j*omega*transmit_delays);
RF_adj(i,:,:)=RF(:,:,i)*Hinv;
end
% Inverse FFT for real signal
rf_fsa=ifft(RF_adj,'symmetric');
% ===========================================Time domain implementation
case 'time'
rf_fsa=zeros(n_samples,n_receives,n_elements,'single');
samples=1:n_samples;
% Interpolate the data for each transmit event with delays
% corresponding to each recovered transmit element
for j=1:n_transmits
rf_fsa=rf_fsa+interp1(samples,single(rf(:,:,j)),...
repmat(samples(:),1,n_elements)+repmat(transmit_delays(j,:),n_samples,1),...
'linear');
end
rf_fsa(isnan(rf_fsa))=0;
end