xref: /openwifi/user_space/side_ch_ctl_src/test_iq_2ant_file_display.m (revision e556af35c696ecef552192823e107caf37eb6af9)
1% Xianjun Jiao. [email protected]; [email protected]
2
3% clear all;
4% close all;
5function timestamp = test_iq_2ant_file_display(iq_len, iq_cap_filename, idx_to_check)
6close all;
7
8if exist('iq_len', 'var')==0 || isempty(iq_len)
9    iq_len = 8187; % default for big fpga
10    % iq_len = 4095; % for small fpga
11end
12
13if exist('iq_cap_filename', 'var')==0 || isempty(iq_cap_filename)
14    iq_cap_filename = 'iq_2ant.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
29iq0_capture =   zeros(iq_len, num_iq_capture);
30iq1_capture =   zeros(iq_len, num_iq_capture);
31timestamp   =   zeros(1, num_iq_capture);
32
33b = uint16(b);
34for i=1:num_iq_capture
35    sp = (i-1)*num_data_in_each_iq_capture + 1;
36    ep = i*num_data_in_each_iq_capture;
37    timestamp(i) = double(b(sp,1)) + (2^16)*double(b(sp,2)) + (2^32)*double(b(sp,3)) + (2^48)*double(b(sp,4));
38    iq0_capture(:,i) = double(typecast(b((sp+1):ep,1),'int16')) + 1i.*double(typecast(b((sp+1):ep,2),'int16'));
39    iq1_capture(:,i) = double(typecast(b((sp+1):ep,3),'int16')) + 1i.*double(typecast(b((sp+1):ep,4),'int16'));
40end
41
42mat_filename = [iq_cap_filename(1:end-4) '_' num2str(iq_len) '.mat'];
43save(mat_filename, 'iq0_capture', 'iq1_capture');
44
45figure; plot(timestamp,'b+-'); title('time stamp (TSF value)'); ylabel('us'); xlabel('packet');  grid on;
46
47figure;
48subplot(2,1,1);
49plot(real(iq0_capture(:))); hold on; plot(imag(iq0_capture(:)),'r'); title('rx0 I (blue) Q (red) sample'); xlabel('sample'); ylabel('I/Q'); grid on;
50subplot(2,1,2);
51plot(real(iq1_capture(:))); hold on; plot(imag(iq1_capture(:)),'r'); title('rx1 I (blue) Q (red) sample'); xlabel('sample'); ylabel('I/Q'); grid on;
52
53figure;
54a = abs(iq0_capture(:));
55b = abs(iq1_capture(:));
56% a(a==0) = max(b);
57plot(a); hold on;
58plot(b,'r'); title('rx0 and rx1 abs'); xlabel('sample'); ylabel('abs'); grid on;
59legend('rx0','rx1');
60
61save_iq_complex_to_txt(iq0_capture(:), [mat_filename(1:end-4) '_iq0.txt']);
62save_iq_complex_to_txt(iq1_capture(:), [mat_filename(1:end-4) '_iq1.txt']);
63
64figure;
65subplot(2,1,1);
66plot(real(iq0_capture(:,idx_to_check))); hold on; plot(imag(iq0_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;
67subplot(2,1,2);
68plot(real(iq1_capture(:,idx_to_check))); hold on; plot(imag(iq1_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;
69
70function save_iq_complex_to_txt(iq, filename)
71fid = fopen(filename,'w');
72if fid == -1
73    disp('fopen failed');
74    return;
75end
76
77for i=1:length(iq)
78    fprintf(fid, '%d %d\n', round(real(iq(i))), round(imag(iq(i))));
79end
80
81fclose(fid);
82