1# Copyright Oticon A/S 2018
2# SPDX-License-Identifier: Apache-2.0
3
4function [SNR, RSSI] = analog_model( ListInter, Desired, ModulationRx, CenterFreq )
5PlotF = 0;
6
7%%Thermal noise calculation
8NoiseFigure = 4; %dB
9                 % Note that in reality the noise figure will increase as the gain decreases, but anyway the thermal noise wont be significant once we have higher levels
10
11%ThermalNoise =  -174dBm/Hz * ReceiverBW * NoiseFigure
12ThermalNoisemW = 10^( (-174 + NoiseFigure)/10 ) * ReceiverNoiseBW(ModulationRx);
13
14%end of thermal noise
15%%Interference calculation
16[FilterRx, HalfBW, SpectrumSamplingBW] = RxFilterShape( ModulationRx );
17
18StartR = (CenterFreq - 2400e6)/SpectrumSamplingBW - HalfBW;
19EndR   = (CenterFreq - 2400e6)/SpectrumSamplingBW + HalfBW;
20
21if PlotF == 1,
22  figure(1);
23  hold off;
24  plot( (StartR:EndR), 10*log10(FilterRx) , 'x','DisplayName','Rx Filter');
25  hold all;
26  plot( (CenterFreq-2400e6)/SpectrumSamplingBW, Desired.RxPower , '^','DisplayName','Desired Signal');
27end
28
29InterfPowermW = 0;
30
31for i = 1:numel(ListInter),
32  [ListInter{i}.Spectrum , ListInter{i}.HalfBW, ~] = ModSpectrum( ListInter{i}.Modulation );
33
34  StartI = (ListInter{i}.CenterFreq - 2400e6)/SpectrumSamplingBW - ListInter{i}.HalfBW;
35  EndI   = (ListInter{i}.CenterFreq - 2400e6)/SpectrumSamplingBW + ListInter{i}.HalfBW;
36
37  StartOverlap = max(StartR, StartI);
38  EndOverlap = min(EndR, EndI);
39
40  if PlotF == 1,
41    plot( (StartI:EndI), 10*log10(ListInter{i}.Spectrum.* 10^(ListInter{i}.RxPower/10)) ,'o','DisplayName',['Interf. ' num2str(i)]);
42  end
43
44  AccRatio = 0;
45  for Freq = StartOverlap:EndOverlap,
46    IndexR = (Freq - StartR) + 1; %matlab indexing
47    IndexI = (Freq - StartI) + 1; %matlab indexing
48    AccRatio = AccRatio + ListInter{i}.Spectrum(IndexI) * FilterRx(IndexR);
49  end
50  InterfPowermW = InterfPowermW + AccRatio * 10^(ListInter{i}.RxPower/10);
51end
52if PlotF == 1,
53  legend('Location','Best');
54end
55%End of interference calculation
56TotalNoisemW = InterfPowermW + ThermalNoisemW;
57
58SNR = Desired.RxPower - 10*log10(TotalNoisemW);
59RSSI = 10*log10( 10^(Desired.RxPower/10) + TotalNoisemW );
60