1# Copyright Oticon A/S 2018
2# SPDX-License-Identifier: Apache-2.0
3
4function BER = digital_ber(SNR)
5
6  NFigure = 2; %in dB, extra noise figure of the digital demodulation path
7  NoiseFloor = -35; %in dB, maximum SNR (equivalent to a quantization noise)
8
9  SNR_i = SNRLossv2(SNR,NFigure,NoiseFloor);
10
11  tmp = 10.^(SNR_i/20); %/20 instead of 10 to get the sqrt();
12  BER = alpi_q_func(tmp);
13end
14
15function SNR_2 = SNRLossv2(SNR,NFigure,NoiseFloor)
16  % SNR degradation produced internally by the receiver
17  %
18  % the input SNR (S/N) is transformed into
19  % S/(NFigure*N + S*Nfloor) (in normal units)
20
21  SNR = SNR - NFigure;
22
23  N_u = 1./10.^((SNR)/10);
24
25  N_u_o = N_u + 10.^(NoiseFloor/10) ;
26
27  SNR_2 = 10*log10(1./N_u_o) ;
28end
29
30function [value] = alpi_q_func(x)
31  %function [value] = alpi_q_func(x)
32  % Home made version of the matlab qfunc()
33  % the normal qfunc() requires the communications toolbox...
34  % http://www.mathworks.se/help/comm/ref/qfunc.html
35
36  value = 1/2*erfc(x/sqrt(2));
37end