sync_log = [];
test_frame_sync_log = [];
test_frame_sync_state = 0;
+ error_pattern_log = [];
% SNR states
track = 0;
fest_state = 0;
+ % spectrum states
+
+ Nspec=1024;
+ spec_mem=zeros(1,Nspec);
+ SdB = zeros(1,Nspec);
+
% Main loop ----------------------------------------------------
for f=1:frames
rx_fdm_log = [rx_fdm_log rx_fdm(1:nin)];
+ % update spectrum
+
+ l=length(rx_fdm);
+ spec_mem(1:Nspec-l) = spec_mem(l+1:Nspec);
+ spec_mem(Nspec-l+1:Nspec) = rx_fdm;
+ S=fft(spec_mem.*hanning(Nspec)',Nspec);
+ SdB = 0.9*SdB + 0.1*20*log10(abs(S));
+
% frequency offset estimation and correction
[pilot prev_pilot pilot_lut_index prev_pilot_lut_index] = get_pilot(pilot_lut_index, prev_pilot_lut_index, nin);
end
if strcmp(modulation,'dqpsk')
- rx_symbols_log = [rx_symbols_log rx_symbols.*conj(prev_rx_symbols)*exp(j*pi/4)];
+ rx_symbols_log = [rx_symbols_log rx_symbols.*conj(prev_rx_symbols./abs(prev_rx_symbols))*exp(j*pi/4)];
else
rx_symbols_log = [rx_symbols_log rx_symbols];
endif
% count bit errors if we find a test frame
- [test_frame_sync bit_errors] = put_test_bits(test_bits, rx_bits);
+ [test_frame_sync bit_errors error_pattern] = put_test_bits(test_bits, rx_bits);
if (test_frame_sync == 1)
total_bit_errors = total_bit_errors + bit_errors;
total_bits = total_bits + Ntest_bits;
test_frame_count = 0;
if ((test_frame_sync == 0))
next_test_frame_sync_state = 0;
+ else
+ error_pattern_log = [error_pattern_log error_pattern];
end
end
end
test_frame_sync_state = next_test_frame_sync_state;
test_frame_sync_log = [test_frame_sync_log test_frame_sync_state];
-
end
-
+
% ---------------------------------------------------------------------
% Print Stats
% ---------------------------------------------------------------------
ber = total_bit_errors / total_bits;
-
+ Fcentre
printf("%d bits %d errors BER: %1.4f\n",total_bits, total_bit_errors, ber);
% ---------------------------------------------------------------------
figure(3)
clf;
- subplot(211)
- [a b] = size(rx_fdm_log);
- xt1 = (1:b)/Fs;
- plot(xt1, rx_fdm_log);
- title('Rx FDM Signal');
- subplot(212)
spec(rx_fdm_log,8000);
- title('FDM Rx Spectrogram');
figure(4)
clf;
figure(5)
clf;
+ subplot(211);
plot(xt, snr_est_log);
title('SNR Estimates')
-
+ subplot(212)
+ snrdB_pc = 20*log10(sig_est(1:Nc+1)) - 20*log10(noise_est(1:Nc+1));
+ bar(snrdB_pc(1:Nc) - mean(snrdB_pc(1:Nc)))
+ axis([0 Nc+1 -3 3]);
+
+ figure(6)
+ clf;
+ hold on;
+ lep = length(error_pattern_log);
+ for p=1:Nc
+ plot(p + 0.25*error_pattern_log((p-1)*2+1:Nc*Nb:lep));
+ plot(0.30 + p + 0.25*error_pattern_log(p*2:Nc*Nb:lep),'r')
+ end
+ hold off;
+ axis([1 lep/(Nc*Nb) 0 15])
+
+ figure(7)
+ clf;
+ subplot(211)
+ [a b] = size(rx_fdm_log);
+ xt1 = (1:b)/Fs;
+ plot(xt1, rx_fdm_log);
+ title('Rx FDM Signal');
+ subplot(212)
+ plot((0:Nspec/2-1)*Fs/Nspec, SdB(1:Nspec/2) - 20*log10(Nspec/2))
+ axis([0 Fs/2 -40 0])
+ grid
+ title('FDM Rx Spectrum');
+
endfunction
% Simulation Parameters --------------------------------------
-frames = 100;
-EbNo_dB = 7.3;
+frames = 50*10;
+EbNo_dB = 10.3;
Foff_hz = 0;
modulation = 'dqpsk';
hpa_clip = 150;
snr_log = [];
+Nspec=1024;
+spec_mem=zeros(1,Nspec);
+SdB = zeros(1,Nspec);
+
% ---------------------------------------------------------------------
% Main loop
% ---------------------------------------------------------------------
rx_fdm += noise;
rx_fdm_log = [rx_fdm_log rx_fdm];
+ % update spectrum
+
+ l=length(rx_fdm);
+ spec_mem(1:Nspec-l) = spec_mem(l+1:Nspec);
+ spec_mem(Nspec-l+1:Nspec) = rx_fdm;
+ S=fft(spec_mem.*hanning(Nspec)',Nspec);
+ SdB = 0.9*SdB + 0.1*20*log10(abs(S));
+
% Delay
rx_fdm_delay(1:Ndelay-M) = rx_fdm_delay(M+1:Ndelay);
[rx_bits sync foff_fine pd] = qpsk_to_bits(prev_rx_symbols, rx_symbols, modulation);
if strcmp(modulation,'dqpsk')
- %rx_symbols_log = [rx_symbols_log rx_symbols.*conj(prev_rx_symbols)*exp(j*pi/4)];
rx_symbols_log = [rx_symbols_log pd];
else
rx_symbols_log = [rx_symbols_log rx_symbols];
% count bit errors if we find a test frame
% Allow 15 frames for filter memories to fill and time est to settle
- [test_frame_sync bit_errors] = put_test_bits(rx_bits);
+ [test_frame_sync bit_errors] = put_test_bits(test_bits, rx_bits);
+
if test_frame_sync == 1
total_bit_errors = total_bit_errors + bit_errors;
total_bits = total_bits + Ntest_bits;
figure(3)
clf;
subplot(211)
-plot(real(tx_fdm_log));
-title('FDM Tx Signal');
+plot(real(rx_fdm_log));
+title('FDM Rx Signal');
subplot(212)
-Nfft=Fs;
-S=fft(rx_fdm_log,Nfft);
-SdB=20*log10(abs(S));
-plot(SdB(1:Fs/4))
+plot((0:Nspec/2-1)*Fs/Nspec, SdB(1:Nspec/2) - 20*log10(Nspec/2))
+axis([0 Fs/2 -40 0])
+grid
title('FDM Rx Spectrum');
figure(4)
figure(5)
clf
+subplot(211)
plot(snr_log)
+subplot(212)
+%plot(20*log10(sig_est(1:Nc))-20*log10(sig_est(Nc+1))+6)
+%axis([1 Nc -6 6]);
+sdB_pc = 20*log10(sig_est(1:Nc+1));
+bar(sdB_pc(1:Nc) - mean(sdB_pc(1:Nc)))
+axis([0 Nc+1 -3 3]);