xref: /openwifi/user_space/side_ch_ctl_src/test_iq_file_display.m (revision e556af35c696ecef552192823e107caf37eb6af9)
1% Xianjun Jiao. [email protected]; [email protected]
2
3% clear all;
4% close all;
5
6function timestamp = test_iq_file_display(iq_len, iq_cap_filename, idx_to_check)
7close all;
8
9if exist('iq_len', 'var')==0 || isempty(iq_len)
10    iq_len = 8187;
11end
12
13if exist('iq_cap_filename', 'var')==0 || isempty(iq_cap_filename)
14    iq_cap_filename = 'iq.txt';
15end
16
17if exist('idx_to_check', 'var')==0 || isempty(idx_to_check)
18    idx_to_check = 1;
19end
20
21a = load(iq_cap_filename);
22len_a = floor(length(a)/4)*4;
23a = a(1:len_a);
24
25b = reshape(a, [4, length(a)/4])';
26num_data_in_each_iq_capture = 1 + iq_len;
27num_iq_capture = floor(size(b,1)/num_data_in_each_iq_capture);
28
29iq_capture =   zeros(iq_len, num_iq_capture);
30timestamp =    zeros(1, num_iq_capture);
31agc_gain =     zeros(iq_len, num_iq_capture);
32rssi_half_db = zeros(iq_len, num_iq_capture);
33
34b = uint16(b);
35for i=1:num_iq_capture
36    sp = (i-1)*num_data_in_each_iq_capture + 1;
37    ep = i*num_data_in_each_iq_capture;
38    timestamp(i) = double(b(sp,1)) + (2^16)*double(b(sp,2)) + (2^32)*double(b(sp,3)) + (2^48)*double(b(sp,4));
39    iq_capture(:,i) = double(typecast(b((sp+1):ep,1),'int16')) + 1i.*double(typecast(b((sp+1):ep,2),'int16'));
40    agc_gain(:,i) = double(b((sp+1):ep,3));
41    rssi_half_db(:,i) = double(b((sp+1):ep,4));
42end
43save(['iq_' num2str(iq_len) '.mat'], 'iq_capture');
44
45agc_gain_lock = zeros(iq_len*num_iq_capture,1);
46agc_gain_lock(agc_gain(:)>127) = 1;
47
48agc_gain_value = agc_gain(:);
49agc_gain_value(agc_gain_value>127) = agc_gain_value(agc_gain_value>127) - 128;
50
51figure; plot(timestamp,'b+-'); title('time stamp (TSF value)'); ylabel('us'); xlabel('packet');  grid on;
52figure; plot(rssi_half_db(:)); title('RSSI half dB (uncalibrated)'); xlabel('sample'); ylabel('dB'); grid on;
53
54figure;
55plot(real(iq_capture(:))); hold on; plot(imag(iq_capture(:)),'r'); title('I (blue) Q (red) sample'); xlabel('sample'); ylabel('I/Q'); grid on;
56
57figure;
58subplot(2,1,1); plot(agc_gain_lock); title('AGC lock status from AD9361'); xlabel('sample'); ylabel('status'); grid on;
59subplot(2,1,2); plot(agc_gain_value); title('AGC gain from AD9361'); xlabel('sample'); ylabel('gain'); grid on;
60
61figure;
62agc_gain_value = reshape(agc_gain_value, [iq_len, num_iq_capture]);
63agc_gain_lock  = reshape(agc_gain_lock, [iq_len, num_iq_capture]);
64subplot(4,1,1); plot(real(iq_capture(:,idx_to_check))); hold on; plot(imag(iq_capture(:,idx_to_check)),'r'); title(['Capture idx ' num2str(idx_to_check) ' timestamp ' num2str(timestamp(idx_to_check))]); xlabel('sample'); ylabel('amplitude'); legend('I', 'Q'); grid on;
65subplot(4,1,2); plot(rssi_half_db(:,idx_to_check)); title('RSSI half dB (uncalibrated)'); xlabel('sample'); ylabel('dB'); grid on;
66subplot(4,1,3); plot(agc_gain_lock(:,idx_to_check)); title('AGC lock status from AD9361'); xlabel('sample'); ylabel('status'); grid on;
67subplot(4,1,4); plot(agc_gain_value(:,idx_to_check)); title('AGC gain from AD9361'); xlabel('sample'); ylabel('gain'); grid on;
68