forked from Mrahman17/mmWave-Radar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatToImage_Anchortech_mat.m
121 lines (107 loc) · 3.81 KB
/
datToImage_Anchortech_mat.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function [ ] = datToImage_Anchortech_mat( fNameIn, fNameOut )
fileID = load(fNameIn);
% dataArray = textscan(fileID, '%f');
% fclose(fileID);
radarData =fileID.DATA;
fc = fileID.CENTERFREQUENCY; % Center frequency
Tsweep = fileID.SWEEPTIME; % Sweep time in ms
Tsweep=Tsweep/1000; %then in sec
NTS = fileID.samplenumberpersweep; % Number of time samples per sweep
Bw =fileID.BANDWIDTH; % FMCW Bandwidth. For FSK, it is frequency step;
% For CW, it is 0.
Data = radarData; % raw data in I+j*Q format
fs=NTS/Tsweep; % sampling frequency ADC
record_length=length(Data)/NTS*Tsweep; % length of recording in s
nc=record_length/Tsweep; % number of chirps
%% Reshape data into chirps and do range FFT (1st FFT)
Data_time=reshape(Data, [NTS nc]);
%Part taken from Ancortek code for FFT and IIR filtering
tmp = fftshift(fft(Data_time),1);
Data_range(1:NTS/2,:) = tmp(NTS/2+1:NTS,:);
% Data_range = tmp;
% IIR Notch filter
ns = oddnumber(size(Data_range,2))-1;
Data_range_MTI = zeros(size(Data_range,1),ns+1);
[b,a] = butter(4, 0.01, 'high');
% [h, f1] = freqz(b, a, ns);
for k=1:size(Data_range,1)
Data_range_MTI(k,:) = filter(b,a,Data_range(k,:));
end
%% Spectrogram processing for 2nd FFT to get Doppler
% This selects the range bins where we want to calculate the spectrogram
bin_indl = 3;
bin_indu = 60;
%Parameters for spectrograms
MD.PRF=1/Tsweep;
MD.TimeWindowLength = 200;
MD.OverlapFactor = 0.95;
MD.OverlapLength = round(MD.TimeWindowLength*MD.OverlapFactor);
MD.Pad_Factor = 4;
MD.FFTPoints = MD.Pad_Factor*MD.TimeWindowLength;
MD.DopplerBin=MD.PRF/(MD.FFTPoints);
MD.DopplerAxis=-MD.PRF/2:MD.DopplerBin:MD.PRF/2-MD.DopplerBin;
MD.WholeDuration=size(Data_range_MTI,2)/MD.PRF;
MD.NumSegments=floor((size(Data_range_MTI,2)-MD.TimeWindowLength)/floor(MD.TimeWindowLength*(1-MD.OverlapFactor)));
nfft = 2^12;window = 128;noverlap = 100;shift = window - noverlap;
sx = myspecgramnew(sum(Data_range_MTI(18:21,:)),window,nfft,shift); % best bin 19-20 for asl
sx1 = flipud(fftshift(sx,1));
sx_scaled = sx1(1408:3688,:);
sx2 = abs(sx1);
MD.TimeAxis=linspace(0,MD.WholeDuration,size(Data_range_MTI,2));
%% Denoising
% Part 1: Isodata thresholding
% sx2 = rescale(sx2,0,255);
% ctr = 0;
% t = 4;%mean(sx2(:)); % initial threshold
% epst = 100;
% while (1)
% low_idx = find(sx2(:)<t);
% high_idx = find(sx2(:)>t);
% mH = mean(sx2(high_idx));
% mL = mean(sx2(low_idx));
% prev_t = t;
% % t = (mH+mL)/2;
% t = (mH+prev_t)/2;
% if abs(t-prev_t) < epst % mH-t
% break
% end
% ctr = ctr+1;
% end
% sx2(low_idx) = 0;
% med = median(median(nonzeros(sx2)));
% sx2(sx2 <= med/2) = 0;
% clear t prev_t
% num_parts = 20; % 20
% mean_energy = Energy(sx2)/num_parts;
% parts_energy = zeros(1,num_parts);
% stepsize = floor(size(sx2,1)/num_parts);
% for i=1:num_parts
% part = sx2((i-1)*stepsize+1:i*stepsize,:);
% parts_energy(i) = Energy(part);
% if parts_energy(i) < mean_energy/10
% sx2((i-1)*stepsize+1:i*stepsize,:) = 0;
% end
% end
%%
% fig= figure('visible','on','units','normalized','outerposition',[0 0 .5 .5]);
fig= figure('visible','on','units','normalized');
% imagesc(MD.TimeAxis,MD.DopplerAxis.*3e8/2/5.8e9,20*log10(abs(Data_spec_MTI2))); colormap('jet'); axis xy
colormap(jet(256)); %xlim([1 9])
imagesc(MD.TimeAxis,MD.DopplerAxis,20*log10(abs(sx2./max(max(sx2))))); % normalization = /max(max(abs(Data_spec_MTI2)))
axis xy
ylim([-12/(3e8/2/5.8e9) 12/(3e8/2/5.8e9)]);
%ylim([-6 6]);
%ylabel('Frequency(Hz)', 'FontSize',9);
clim = get(gca,'CLim');
set(gca, 'CLim', clim(2)+[-40,0]);
% set(gca,'xtick',[],'FontSize',9)
%xlabel('Time(s)', 'FontSize',9);
% ylabel('Velocity [m/s]','FontSize',9)
saveas(fig,[fNameOut(1:end-4) '.fig']);
set(gca,'xtick',[],'ytick',[])
frame = frame2im(getframe(gca));
%save(strcat(fNameOut(1:end-4),'.mat'),'sx_scaled');
imwrite(frame,strcat(fNameOut(1:end-4),'.png'));
fclose('all');
close all
end