Files
matlab/common/radio/result_rx.m
T
jens 579c1544b1 - added
git-svn-id: http://moon:8086/svn/matlab/trunk@157 801c6759-fa7c-4059-a304-17956f83a07c
2022-06-16 06:16:47 +00:00

380 lines
8.7 KiB
Matlab
Executable File

% dpll.m
%
% dpll(fa, fc, sr, mode, file, do_plot)
% Example: dpll(48000, 12000, 6000, 'Costas', 'qam.dat', 1);
% Mode : Normal | Costas
function result_rx(name)
plot_psd = 0;
do_plot = 1;
fa = 48000;
file = sprintf('%s_rf.dat',name);
fid = fopen(file,'r');
m = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_bitclk.dat'],'r');
bitClk= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_modulus.dat'],'r');
modulus= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_softsym_eq_i.dat'],'r');
softsym_eq_i= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_softsym_eq_q.dat'],'r');
softsym_eq_q= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_softsym_i.dat'],'r');
softsym_i= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_softsym_q.dat'],'r');
softsym_q= fread(fid, 'float32');
fclose(fid);
softsym_eq = softsym_eq_i + i*softsym_eq_q;
softsym = softsym_i + i*softsym_q;
close all;
if (do_plot)
fid = fopen([name '_symstat_p.dat'],'r');
symstat_p = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_symstat_err_mag.dat'],'r');
symstat_err_mag = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_symstat_err_phi.dat'],'r');
symstat_err_phi = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_loi.dat'],'r');
lo_I = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_loq.dat'],'r');
lo_Q = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_i.dat'],'r');
I = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_q.dat'],'r');
Q = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_if.dat'],'r');
IF = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_qf.dat'],'r');
QF= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_ircf.dat'],'r');
IRCF = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_qrcf.dat'],'r');
QRCF= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_ircf_rm.dat'],'r');
IRCF_RM = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_qrcf_rm.dat'],'r');
QRCF_RM= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_ted.dat'],'r');
TED= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_perr.dat'],'r');
perr= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_domega.dat'],'r');
dOmega = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_agc_mag.dat'],'r');
agc_mag = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_agc_bal.dat'],'r');
agc_bal = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_pwr_I.dat'],'r');
pwr_I = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_pwr_Q.dat'],'r');
pwr_Q = fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_vco_lock.dat'],'r');
vco_lock= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_str_lock.dat'],'r');
str_lock= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_vld_var1.dat'],'r');
vld_var1= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_vld_var2.dat'],'r');
vld_var2= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_domega.dat'],'r');
domega_nco= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_cma_i.dat'],'r');
cma_i= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_cma_q.dat'],'r');
cma_q= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_cma_eq_i.dat'],'r');
cma_eq_i= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_cma_eq_q.dat'],'r');
cma_eq_q= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_cef_real.dat'],'r');
cef_r= fread(fid, 'float32');
fclose(fid);
fid = fopen([name '_cef_imag.dat'],'r');
cef_i= fread(fid, 'float32');
fclose(fid);
cef = cef_r + i*cef_i;
fid = fopen([name '_impulse_armfilter.dat'],'r');
armfilter = fread(fid, 1024, 'float32');
fclose(fid);
N = lge(m);
K = lge(lo_I);
S = lge(perr);
nSymbols = length(softsym_eq);
plot(0:length(cef)-1, real(cef), 0:length(cef)-1, imag(cef));
legend('Real','Imag');
grid;
figure;
freqz(abs(cef));
figure;
subplot(2,1,1)
plot(1:K,lo_I,'b',1:K,lo_Q,'g');
legend('Local Osc I','Local Osc Q');
grid;
subplot(2,1,2)
plot(1:S,dOmega,'r');
legend('dOmega');
xlabel('n');
ylabel('-');
grid;
figure;
freqz(armfilter');
title('Arm filter I');
figure
subplot(3,1,1)
plot(1:S, agc_mag, 'b', 1:S, agc_bal, 'g', 1:S, min(2, pwr_I./pwr_Q), 'r')
legend('AGC gain','AGC err', 'AGC I/Q');
grid;
subplot(3,1,2)
plot(1:S, vld_var1, 'b-', 1:S, vld_var2, 'g-');
legend('Magnitude noise','Phase noise');
ylabel('dB');
grid;
subplot(3,1,3)
plot(1:S, 0.99*vco_lock, 'b-',1:S, 0.99*str_lock, 'g-');
legend('VCO Lock','STR Lock');
grid;
slices = find(bitClk);
n_slices = length(slices);
bc_amp_i = bitClk(slices).*IRCF(slices);
bc_amp_q = bitClk(slices).*QRCF(slices);
figure
subplot(3,1,1)
plot(1:K,IRCF ,'b',1:K,QRCF ,'g',slices,bc_amp_i,'r+',slices,bc_amp_q,'ro');
legend('Resampled I','Resampled Q','Clock','Clock');
grid;
subplot(3,1,2)
plot(1:K,TED ,'b');
legend('TED_{n}');
grid;
subplot(3,1,3)
plot(1:K,QRCF_RM ,'g',1:K,IRCF_RM ,'b');
legend('mu', 'm_{n}');
grid;
%figure
%len_w = length(cef_w);
%plot(0:len_w-1, cef_w);
%title('Channel Estimation Filter Weights');
%xlabel('n');
%grid;
figure
subplot(3,1,1)
plot(1:S, cma_eq_i, 1:S, cma_i);
title('SNR');
legend('Online', 'Offline');
grid;
subplot(3,1,2)
plot(1:S, cma_eq_q, 'b-', 1:S, cma_q, 'r-');
title('CEF SNR Distance');
legend('Distance','Updates');
grid;
subplot(3,1,3)
plot(1:S,perr);
title('Phase error');
xlabel('n');
legend('Phi(Err_{I},Err_{Q})');
grid;
figure;
subplot(2,1,1)
plot(1:lge(modulus),modulus);
title('Modulus');
xlabel('n');
legend('Modulus');
grid;
subplot(2,1,2)
bar(hist(modulus, 20));
title('Hist');
xlabel('Magnitude');
legend('Hist');
grid;
figure;
plot_range = fix(length(softsym_eq)/2+1):length(softsym_eq);
%plot(IRCF + i* QRCF,'cx');
hold on;
plot(softsym(plot_range), 'cx')
plot(softsym_eq(plot_range), 'bx')
hold off;
title('Diagram demodulated data')
axis([-1.0 1.0 -1.0 1.0]);
xlabel('Re(mod)');
ylabel('Im(mod)');
grid;
mean2 = mean(abs(softsym_eq(plot_range)).^2);
mean4 = mean(abs(softsym_eq(plot_range)).^4);
R2 = mean4/mean2;
R4 = mean4/(mean2*mean2);
mean_soft_i = mean(real(softsym))
mean_soft_q = mean(imag(softsym))
mean_soft_eq_i = mean(real(softsym_eq))
mean_soft_eq_q = mean(imag(softsym_eq))
figure;
nConst = length(symstat_p);
subplot(3,1,1),
bar(0:nConst-1, symstat_p);
axis([0 nConst-1 0 1.1*max(symstat_p)]);
title('Symbol Probability');
grid;
subplot(3,1,2),
bar(0:nConst-1, symstat_err_mag);
axis([0 nConst-1 0 1.1*max(symstat_err_mag)]);
title('Symbol Magnitude Error');
grid;
subplot(3,1,3),
bar(0:nConst-1, symstat_err_phi);
axis([0 nConst-1 0 1.1*max(symstat_err_phi)]);
title('Symbol Phase Error');
xlabel('Symbol');
ylabel('rad');
grid;
if(plot_psd == 1)
figure;
lenI = length(I);
lenQ = length(Q);
lenI_fft = length(fix(lenI/2):fix(3*lenI/4));
lenQ_fft = length(fix(lenQ/2):fix(3*lenQ/4));
lenI_f = fix(lenI_fft/2);
lenQ_f = fix(lenQ_fft/2);
I_f = 1/sqrt(lenI_fft)*abs(fft(I(fix(lenI/2):fix(3*lenI/4))));
Q_f = 1/sqrt(lenQ_fft)*abs(fft(Q(fix(lenQ/2):fix(3*lenQ/4))));
plot(fa*(0:lenI_f-1)/lenI_fft, 10*log10(I_f(1:lenI_f).^2),fa*(0:lenQ_f-1)/lenQ_fft, 10*log10(Q_f(1:lenQ_f).^2));
title('Power Spectral Density of baseband before arm filters');
xlabel('f');
ylabel('dB');
legend('I-Channel','Q-Channel');
grid;
figure;
lenIF = length(IF);
lenQF = length(QF);
lenIF_fft = length(fix(lenIF/2):fix(3*lenIF/4));
lenQF_fft = length(fix(lenQF/2):fix(3*lenQF/4));
lenIF_f = fix(lenIF_fft/2);
lenQF_f = fix(lenQF_fft/2);
IF_f = 1/sqrt(lenIF_fft)*abs(fft(IF(fix(lenIF/2):fix(3*lenIF/4))));
QF_f = 1/sqrt(lenQF_fft)*abs(fft(QF(fix(lenQF/2):fix(3*lenQF/4))));
plot(fa*(0:lenIF_f-1)/lenIF_fft, 10*log10(IF_f(1:lenIF_f).^2),fa*(0:lenQF_f-1)/lenQF_fft, 10*log10(QF_f(1:lenQF_f).^2));
title('Power Spectral Density of baseband after arm filters');
xlabel('f');
ylabel('dB');
legend('I-Channel','Q-Channel');
grid;
figure;
lenIRCF = length(IRCF);
lenQRCF = length(QRCF);
lenIRCF_fft = length(fix(lenIRCF/2):fix(3*lenIRCF/4));
lenQRCF_fft = length(fix(lenQRCF/2):fix(3*lenQRCF/4));
lenIRCF_f = fix(lenIRCF_fft/2);
lenQRCF_f = fix(lenQRCF_fft/2);
IRCF_f = 1/sqrt(lenIRCF_fft)*abs(fft(IRCF(fix(lenIRCF/2):fix(3*lenIRCF/4))));
QRCF_f = 1/sqrt(lenQRCF_fft)*abs(fft(QRCF(fix(lenQRCF/2):fix(3*lenQRCF/4))));
plot(fa*(0:lenIRCF_f-1)/lenIRCF_fft, 10*log10(IRCF_f(1:lenIRCF_f).^2),fa*(0:lenQRCF_f-1)/lenQRCF_fft, 10*log10(QRCF_f(1:lenQRCF_f).^2));
title('Power Spectral Density of baseband after matched filters');
xlabel('f');
ylabel('dB');
legend('I-Channel','Q-Channel');
grid;
end;
end;