2017-04-30 04:48:43 +08:00
# ! / usr / bin / octave
% you need to first install the parallel and struct packages :
% pkg install - forge struct
% pkg install - forge parallel
pkg load parallel
2017-04-30 19:51:12 +08:00
function y = inarg ( x )
for i = 1 : length ( argv ( ) )
if strcmp ( argv ( ) { i } , x )
y = 1 ;
return
end
end
y = 0 ;
end
if ! inarg ( ' - - nogen ' )
fwrite ( stdout , "===========================================\nGenerating baseband signal from random data\n===========================================\n" ) ;
system ( ' cat / dev / urandom | csdr pack_bits _8to1 _u8 _u8 | csdr psk_modulator _u8 _c 2 | csdr gain_ff 0.25 | csdr psk31_interpolate _sine _cc 256 | csdr add_n _zero _samples _at _beginning _f 170 | pv - ps 2 g | dd iflag = fullblock bs = 128 M count = 16 of = / tmp / psk31 - raw - data ' ) ;
fwrite ( stdout , "===========================================\nGenerating Gaussian white noise for agwn_cc\n===========================================\n" ) ;
system ( ' csdr gaussian_noise _c | pv - ps 256 m | dd of = / tmp / psk31 - gaussian - noise iflag = fullblock bs = 256 M count = 1 ' ) ;
end
if inarg ( ' - - onlygen ' )
exit ( 0 )
end
fwrite ( stdout , "===========================================\nCalculating variance graph data \n===========================================\n" ) ;
2017-04-30 04:48:43 +08:00
function output = shrun ( cmd , type , minsize )
SIGTERM = 15 ;
output = [ ] ;
cmd
[ pin , pout , pid ] = popen2 ( ' bash ' , { ' - c ' , cmd } ) ;
% fclose ( pin ) ;
do
sleep ( 0.3 )
2017-04-30 05:27:39 +08:00
fwrite ( stdout , ' . ' ) ;
2017-04-30 04:48:43 +08:00
% size ( output )
% output
2017-04-30 05:27:39 +08:00
current_output = fread ( pout , Inf , type ) ;
frewind ( pout ) ;
2017-04-30 04:48:43 +08:00
output = [ output ; current_output ] ;
until ( size ( output ) ( 1 ) >= minsize )
waitpid ( pid ) ;
kill ( pid , SIGTERM ) ;
fclose ( pin ) ;
fclose ( pout ) ;
end
function variance = run_var ( snr , which_ted )
disp ( ' ran a command ' )
2017-04-30 19:51:12 +08:00
out_vect = shrun ( sprintf ( ' cat / tmp / psk31 - raw - data | csdr awgn_cc % d - - awgnfile / tmp / psk31 - gaussian - noise | csdr timing_recovery _cc % s 256 - - add_q - - output_indexes | CSDR_FIXED _BUFSIZE = 1048576 csdr normalized_timing _variance _u32 _f 256 85 ' , snr , which_ted ) , ' float32 ' , 1 ) ;
2017-04-30 04:48:43 +08:00
disp ( ' run_var output : ' ) ;
out_vect '
2017-04-30 19:51:12 +08:00
variance = out_vect ( 1 ) ;
2017-04-30 04:48:43 +08:00
end
function variances = mkvarplot ( which_ted , snrs )
fun = @ ( x ) run_var ( x , which_ted ) ;
variances = pararrayfun ( nproc , fun , snrs ) ;
2017-04-30 05:27:39 +08:00
% {
2017-04-30 04:48:43 +08:00
variances = [ ]
for snr = snrs
snr
variances = [ variances run_var ( snr , which_ted ) ] ;
end
2017-04-30 05:27:39 +08:00
% }
2017-04-30 04:48:43 +08:00
end
function fmtplot ( h )
FN = findall ( h , ' - property ' , ' FontName ' ) ;
set ( FN , ' FontName ' , ' / usr / share / fonts / truetype / ttf - dejavu / DejaVuSerifCondensed . ttf ' ) ;
set ( FN , ' FontName ' , ' times ' ) ;
FS = findall ( h , ' - property ' , ' FontSize ' ) ;
set ( FS , ' FontSize ' , 18 ) ;
2017-04-30 16:06:31 +08:00
xlabel ( ' E_b / N_0 [ dB ] ' ) ;
2017-04-30 05:27:39 +08:00
ylabel ( ' Phase error variance [ rad ^ 2 ] ' ) ;
2017-04-30 04:48:43 +08:00
end
2017-04-30 16:06:31 +08:00
snrs = -5 : 5 : 30
% snrs = [ 10 ]
2017-04-30 19:51:12 +08:00
error_values _gardner = mkvarplot ( ' GARDNER ' , snrs ) ;
2017-04-30 04:48:43 +08:00
% {
snrs_earlylate = 0 : 256
error_values _earlylate = mkvarplot ( ' EARLYLATE ' , snrs_earlylate ) ;
% }
% graphics_toolkit ( "gnuplot" )
h = figure ( 1 ) ;
2017-04-30 16:18:26 +08:00
ebn0 = snrs -13.26 -10 * log10 ( 1 / 256. )
% 13.56 dB is the difference between the real ( measured ) SNR and the number input to awgn_cc .
% This is because agwn_cc assumes a signal with 0 dB power at te input , while our BPSK31 baseband signal is of -13.26 dB .
2017-04-30 16:06:31 +08:00
semilogy ( ebn0 , error_values _gardner , ' linewidth ' , 2 ) ;
title ( ' Estimation variance ' ) ;
2017-04-30 04:48:43 +08:00
fmtplot ( h )
pause
% {
semilogy ( snrs_earlylate , error_values _earlylate , ' linewidth ' , 2 ) ;
title ( ' S - curve for early - late TED ' ) ;
fmtplot ( h )
pause
% }
2017-04-30 19:51:12 +08:00
if ! inarg ( ' - - nogen ' )
system ( ' rm / tmp / psk31 - raw - data / tmp / psk31 - gaussian - noise ' ) ;
end