Update side_ch scripts for this discussion:

https://github.com/open-sdr/openwifi/discussions/344
This commit is contained in:
Xianjun Jiao 2023-09-26 16:22:02 +02:00
parent b7201e76e3
commit e556af35c6
6 changed files with 78 additions and 47 deletions

View File

@ -55,7 +55,7 @@ def parse_iq(iq, iq_len):
iq = iq.reshape([num_trans, num_int16_per_trans])
timestamp = iq[:,0] + pow(2,16)*iq[:,1] + pow(2,32)*iq[:,2] + pow(2,48)*iq[:,3]
iq_capture = iq[:,4::4] + iq[:,5::4]*1j
iq_capture = np.int16(iq[:,4::4]) + np.int16(iq[:,5::4])*1j
agc_gain = iq[:,6::4]
rssi_half_db = iq[:,7::4]
# print(num_trans, iq_len, iq_capture.shape, agc_gain.shape, rssi_half_db.shape)
@ -106,7 +106,7 @@ while True:
if (test_residual != 0):
print("Abnormal length")
iq = np.frombuffer(data, dtype='int16')
iq = np.frombuffer(data, dtype='uint16')
np.savetxt(iq_fd, iq)
timestamp, iq_capture, agc_gain, rssi_half_db = parse_iq(iq, iq_len)

View File

@ -38,8 +38,8 @@ def parse_iq(iq, iq_len):
iq = iq.reshape([num_trans, num_int16_per_trans])
timestamp = iq[:,0] + pow(2,16)*iq[:,1] + pow(2,32)*iq[:,2] + pow(2,48)*iq[:,3]
iq0_capture = iq[:,4::4] + iq[:,5::4]*1j
iq1_capture = iq[:,6::4] + iq[:,7::4]*1j
iq0_capture = np.int16(iq[:,4::4]) + np.int16(iq[:,5::4])*1j
iq1_capture = np.int16(iq[:,6::4]) + np.int16(iq[:,7::4])*1j
# print(num_trans, iq_len, iq0_capture.shape, iq1_capture.shape)
iq0_capture = iq0_capture.reshape([num_trans*iq_len,])
@ -87,7 +87,7 @@ while True:
if (test_residual != 0):
print("Abnormal length")
iq = np.frombuffer(data, dtype='int16')
iq = np.frombuffer(data, dtype='uint16')
np.savetxt(iq_fd, iq)
timestamp, iq0_capture, iq1_capture = parse_iq(iq, iq_len)

View File

@ -112,7 +112,7 @@ def parse_side_info(side_info, num_eq, CSI_LEN, EQUALIZER_LEN, HEADER_LEN):
timestamp = side_info[:,0] + pow(2,16)*side_info[:,1] + pow(2,32)*side_info[:,2] + pow(2,48)*side_info[:,3]
freq_offset = (20e6*side_info[:,4]/512)/(2*3.14159265358979323846)
freq_offset = (20e6*np.int16(side_info[:,4])/512)/(2*3.14159265358979323846)
csi = np.zeros((num_trans, CSI_LEN), dtype='int16')
csi = csi + csi*1j
@ -123,8 +123,8 @@ def parse_side_info(side_info, num_eq, CSI_LEN, EQUALIZER_LEN, HEADER_LEN):
equalizer = equalizer + equalizer*1j
for i in range(num_trans):
tmp_vec_i = side_info[i,8:(num_int16_per_trans-1):4]
tmp_vec_q = side_info[i,9:(num_int16_per_trans-1):4]
tmp_vec_i = np.int16(side_info[i,8:(num_int16_per_trans-1):4])
tmp_vec_q = np.int16(side_info[i,9:(num_int16_per_trans-1):4])
tmp_vec = tmp_vec_i + tmp_vec_q*1j
# csi[i,:] = tmp_vec[0:CSI_LEN]
csi[i,:CSI_LEN_HALF] = tmp_vec[CSI_LEN_HALF:CSI_LEN]
@ -180,7 +180,7 @@ while True:
if (test_residual != 0):
print("Abnormal length")
side_info = np.frombuffer(data, dtype='int16')
side_info = np.frombuffer(data, dtype='uint16')
np.savetxt(side_info_fd, side_info)
timestamp, freq_offset, csi, equalizer = parse_side_info(side_info, num_eq, CSI_LEN, EQUALIZER_LEN, HEADER_LEN)

View File

@ -2,7 +2,8 @@
% clear all;
% close all;
function test_iq_2ant_file_display(iq_len, iq_cap_filename)
function timestamp = test_iq_2ant_file_display(iq_len, iq_cap_filename, idx_to_check)
close all;
if exist('iq_len', 'var')==0 || isempty(iq_len)
iq_len = 8187; % default for big fpga
@ -13,6 +14,10 @@ if exist('iq_cap_filename', 'var')==0 || isempty(iq_cap_filename)
iq_cap_filename = 'iq_2ant.txt';
end
if exist('idx_to_check', 'var')==0 || isempty(idx_to_check)
idx_to_check = 1;
end
a = load(iq_cap_filename);
len_a = floor(length(a)/4)*4;
a = a(1:len_a);
@ -25,38 +30,42 @@ iq0_capture = zeros(iq_len, num_iq_capture);
iq1_capture = zeros(iq_len, num_iq_capture);
timestamp = zeros(1, num_iq_capture);
b = uint16(b);
for i=1:num_iq_capture
sp = (i-1)*num_data_in_each_iq_capture + 1;
ep = i*num_data_in_each_iq_capture;
timestamp(i) = b(sp,1) + (2^16)*b(sp,2) + (2^32)*b(sp,3) + (2^48)*b(sp,4);
iq0_capture(:,i) = b((sp+1):ep,1) + 1i.*b((sp+1):ep,2);
iq1_capture(:,i) = b((sp+1):ep,3) + 1i.*b((sp+1):ep,4);
timestamp(i) = double(b(sp,1)) + (2^16)*double(b(sp,2)) + (2^32)*double(b(sp,3)) + (2^48)*double(b(sp,4));
iq0_capture(:,i) = double(typecast(b((sp+1):ep,1),'int16')) + 1i.*double(typecast(b((sp+1):ep,2),'int16'));
iq1_capture(:,i) = double(typecast(b((sp+1):ep,3),'int16')) + 1i.*double(typecast(b((sp+1):ep,4),'int16'));
end
mat_filename = [iq_cap_filename(1:end-4) '_' num2str(iq_len) '.mat'];
save(mat_filename, 'iq0_capture', 'iq1_capture');
iq0_capture = iq0_capture(:);
iq1_capture = iq1_capture(:);
figure; plot(timestamp); title('time stamp (TSF value)'); ylabel('us'); xlabel('packet'); grid on;
figure; plot(timestamp,'b+-'); title('time stamp (TSF value)'); ylabel('us'); xlabel('packet'); grid on;
figure;
subplot(2,1,1);
plot(real(iq0_capture)); hold on; plot(imag(iq0_capture),'r'); title('rx0 I (blue) Q (red) sample'); xlabel('sample'); ylabel('I/Q'); grid on;
plot(real(iq0_capture(:))); hold on; plot(imag(iq0_capture(:)),'r'); title('rx0 I (blue) Q (red) sample'); xlabel('sample'); ylabel('I/Q'); grid on;
subplot(2,1,2);
plot(real(iq1_capture)); hold on; plot(imag(iq1_capture),'r'); title('rx1 I (blue) Q (red) sample'); xlabel('sample'); ylabel('I/Q'); grid on;
plot(real(iq1_capture(:))); hold on; plot(imag(iq1_capture(:)),'r'); title('rx1 I (blue) Q (red) sample'); xlabel('sample'); ylabel('I/Q'); grid on;
figure;
a = abs(iq0_capture);
b = abs(iq1_capture);
a = abs(iq0_capture(:));
b = abs(iq1_capture(:));
% a(a==0) = max(b);
plot(a); hold on;
plot(b,'r'); title('rx0 and rx1 abs'); xlabel('sample'); ylabel('abs'); grid on;
legend('rx0','rx1');
save_iq_complex_to_txt(iq0_capture, [mat_filename(1:end-4) '_iq0.txt']);
save_iq_complex_to_txt(iq1_capture, [mat_filename(1:end-4) '_iq1.txt']);
save_iq_complex_to_txt(iq0_capture(:), [mat_filename(1:end-4) '_iq0.txt']);
save_iq_complex_to_txt(iq1_capture(:), [mat_filename(1:end-4) '_iq1.txt']);
figure;
subplot(2,1,1);
plot(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;
subplot(2,1,2);
plot(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;
function save_iq_complex_to_txt(iq, filename)
fid = fopen(filename,'w');

View File

@ -3,15 +3,22 @@
% clear all;
% close all;
function test_iq_file_display(varargin)
function timestamp = test_iq_file_display(iq_len, iq_cap_filename, idx_to_check)
close all;
if nargin == 0
if exist('iq_len', 'var')==0 || isempty(iq_len)
iq_len = 8187;
else
iq_len = varargin{1};
end
a = load('iq.txt');
if exist('iq_cap_filename', 'var')==0 || isempty(iq_cap_filename)
iq_cap_filename = 'iq.txt';
end
if exist('idx_to_check', 'var')==0 || isempty(idx_to_check)
idx_to_check = 1;
end
a = load(iq_cap_filename);
len_a = floor(length(a)/4)*4;
a = a(1:len_a);
@ -24,32 +31,37 @@ timestamp = zeros(1, num_iq_capture);
agc_gain = zeros(iq_len, num_iq_capture);
rssi_half_db = zeros(iq_len, num_iq_capture);
b = uint16(b);
for i=1:num_iq_capture
sp = (i-1)*num_data_in_each_iq_capture + 1;
ep = i*num_data_in_each_iq_capture;
timestamp(i) = b(sp,1) + (2^16)*b(sp,2) + (2^32)*b(sp,3) + (2^48)*b(sp,4);
iq_capture(:,i) = b((sp+1):ep,1) + 1i.*b((sp+1):ep,2);
agc_gain(:,i) = b((sp+1):ep,3);
rssi_half_db(:,i) = b((sp+1):ep,4);
timestamp(i) = double(b(sp,1)) + (2^16)*double(b(sp,2)) + (2^32)*double(b(sp,3)) + (2^48)*double(b(sp,4));
iq_capture(:,i) = double(typecast(b((sp+1):ep,1),'int16')) + 1i.*double(typecast(b((sp+1):ep,2),'int16'));
agc_gain(:,i) = double(b((sp+1):ep,3));
rssi_half_db(:,i) = double(b((sp+1):ep,4));
end
save(['iq_' num2str(iq_len) '.mat'], 'iq_capture');
iq_capture = iq_capture(:);
agc_gain = agc_gain(:);
rssi_half_db = rssi_half_db(:);
agc_gain_lock = zeros(iq_len*num_iq_capture,1);
agc_gain_lock(agc_gain>127) = 1;
agc_gain_lock(agc_gain(:)>127) = 1;
agc_gain_value = agc_gain;
agc_gain_value = agc_gain(:);
agc_gain_value(agc_gain_value>127) = agc_gain_value(agc_gain_value>127) - 128;
figure; plot(timestamp); title('time stamp (TSF value)'); ylabel('us'); xlabel('packet'); grid on;
figure; plot(rssi_half_db); title('RSSI half dB (uncalibrated)'); xlabel('sample'); ylabel('dB'); grid on;
figure; plot(timestamp,'b+-'); title('time stamp (TSF value)'); ylabel('us'); xlabel('packet'); grid on;
figure; plot(rssi_half_db(:)); title('RSSI half dB (uncalibrated)'); xlabel('sample'); ylabel('dB'); grid on;
figure;
plot(real(iq_capture)); hold on; plot(imag(iq_capture),'r'); title('I (blue) Q (red) sample'); xlabel('sample'); ylabel('I/Q'); grid on;
plot(real(iq_capture(:))); hold on; plot(imag(iq_capture(:)),'r'); title('I (blue) Q (red) sample'); xlabel('sample'); ylabel('I/Q'); grid on;
figure;
subplot(2,1,1); plot(agc_gain_lock); title('AGC lock status from AD9361'); xlabel('sample'); ylabel('status'); grid on;
subplot(2,1,2); plot(agc_gain_value); title('AGC gain from AD9361'); xlabel('sample'); ylabel('gain'); grid on;
figure;
agc_gain_value = reshape(agc_gain_value, [iq_len, num_iq_capture]);
agc_gain_lock = reshape(agc_gain_lock, [iq_len, num_iq_capture]);
subplot(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;
subplot(4,1,2); plot(rssi_half_db(:,idx_to_check)); title('RSSI half dB (uncalibrated)'); xlabel('sample'); ylabel('dB'); grid on;
subplot(4,1,3); plot(agc_gain_lock(:,idx_to_check)); title('AGC lock status from AD9361'); xlabel('sample'); ylabel('status'); grid on;
subplot(4,1,4); plot(agc_gain_value(:,idx_to_check)); title('AGC gain from AD9361'); xlabel('sample'); ylabel('gain'); grid on;

View File

@ -1,6 +1,6 @@
% Xianjun Jiao. xianjun.jiao@imec.be; putaoshu@msn.com
function test_side_info_file_display(num_eq, side_info_filename)
function timestamp = test_side_info_file_display(num_eq, side_info_filename, idx_to_check)
close all;
if exist('num_eq', 'var')==0 || isempty(num_eq)
@ -11,6 +11,10 @@ if exist('side_info_filename', 'var')==0 || isempty(side_info_filename)
side_info_filename = 'side_info.txt';
end
if exist('idx_to_check', 'var')==0 || isempty(idx_to_check)
idx_to_check = 1;
end
a = load(side_info_filename);
len_a = floor(length(a)/4)*4;
a = a(1:len_a);
@ -20,16 +24,18 @@ num_data_in_each_side_info = 2+56+num_eq*52;
num_side_info = floor(size(b,1)/num_data_in_each_side_info);
side_info = zeros(num_data_in_each_side_info, num_side_info);
timestamp = zeros(1, num_side_info);
timestamp = uint64(zeros(1, num_side_info));
freq_offset = zeros(1, num_side_info);
csi = zeros(56, num_side_info);
equalizer = zeros(num_eq*52, num_side_info);
b = uint16(b);
for i=1:num_side_info
sp = (i-1)*num_data_in_each_side_info + 1;
ep = i*num_data_in_each_side_info;
timestamp(i) = b(sp,1) + (2^16)*b(sp,2) + (2^32)*b(sp,3) + (2^48)*b(sp,4);
freq_offset(i) = (20e6*b(sp+1,1)/512)/(2*pi);
side_info(:,i) = b(sp:ep,1) + 1i.*b(sp:ep,2);
timestamp(i) = uint64(b(sp,1)) + (2^16)*uint64(b(sp,2)) + (2^32)*uint64(b(sp,3)) + (2^48)*uint64(b(sp,4));
freq_offset(i) = (20e6*double(typecast(b(sp+1,1),'int16'))/512)/(2*pi);
side_info(:,i) = double(typecast(b(sp:ep,1),'int16')) + 1i.*double(typecast(b(sp:ep,2),'int16'));
csi(:,i) = side_info(3:58,i);
equalizer(:,i) = side_info(59:end,i);
end
@ -45,5 +51,9 @@ if ~isempty(equalizer)
scatterplot(equalizer); grid on;
end
figure; plot(timestamp); title('time stamp (TSF value)'); ylabel('us'); xlabel('packet'); grid on;
figure; plot(timestamp,'b+-'); title('time stamp (TSF value)'); ylabel('us'); xlabel('packet'); grid on;
figure; plot(freq_offset); title('freq offset (Hz)'); ylabel('Hz'); xlabel('packet'); grid on;
figure;
subplot(2,1,1); plot(abs(csi(:,idx_to_check))); title('CSI'); ylabel('abs'); grid on; title(['Capture idx ' num2str(idx_to_check) ' timestamp ' num2str(timestamp(idx_to_check))]);
subplot(2,1,2); plot(angle(csi(:,idx_to_check))); ylabel('phase'); xlabel('subcarrier'); grid on;