📄 computeresults.m
字号:
%--------------------------------------------------------------------------
function data = computeResults(data,AdditionnalDisplay,polyOrder,extrapolEnd)
%optional: extrapolEnd
%optional: polyOrder default is 5;
if nargin==2
polyOrder=5;
end
SNR=data.StartSNR:data.EndSNR;
gonefor=size([data.StartSNR:data.stepSNR:data.EndSNR],2);
%-- Command window prints
if AdditionnalDisplay
data.simulationSpeed = max(data.SimulatedBits)*(gonefor) /data.totalTime ;
data.simulationSpeed_real = sum(data.SimulatedBits) /data.totalTime;
data.simulationSpeed = data.simulationSpeed /1000; %convert to kbits/s
data.simulationSpeed_real = data.simulationSpeed_real /1000; %convert to kbits/s
disp([' '])
disp([' '])
disp(['%-- Simulation Results: ------------------------------------------------------%'])
fprintf('Total Time = %6.2f sec.\n',data.totalTime)
fprintf('Simulated bits = %1.2e.\n' ,max(data.SimulatedBits))
fprintf('SNR range: %1.0f to %1.0f, with step=%1.0f. \n', data.StartSNR, data.EndSNR,data.stepSNR)
if data.fastSimulations
fprintf('fake Simulation Speed = %6.2f kbits/sec.\n' ,data.simulationSpeed)
fprintf('real Simulation Speed = %6.2f kbits/sec.\n' ,data.simulationSpeed_real)
else
fprintf('Simulation Speed = %6.2f kbits/sec.\n' ,data.simulationSpeed_real)
end
if data.displayFinalCountedErrors
disp([' '])
fprintf('For SNR %2.0f, CountedErrors = %9.0f, SimulatedBits = %9.0f, BER = %1.1e. \n', ...
[SNR(1:data.stepSNR:end)' data.CountedErrors(1:data.stepSNR:end)' data.SimulatedBits(1:data.stepSNR:end)' ...
[data.CountedErrors(1:data.stepSNR:end)./data.SimulatedBits(1:data.stepSNR:end)]']')
end
end
%-- Save data (maybe errors happen after)
data.SNR=SNR;
save(data.fOut,'data')
NnonZero=sum(data.CountedErrors~=0);
N2=max(find(data.CountedErrors~=0));
snrStep=0.25; %step for trendline
if nargin==4
desiredSNREnd = extrapolEnd;
else
desiredSNREnd = SNR(N2);
end
snrEnd=max(SNR(N2),desiredSNREnd);
snrRange_nomodif=[SNR(1):snrStep:SNR(N2)];
n1=size(snrRange_nomodif,2);
snrRange_extrapol=[SNR(N2)+snrStep:snrStep:desiredSNREnd];
snrRange=[SNR(1):snrStep:snrEnd];
disp(' ')
if size(snrRange_extrapol,2)>1
disp(['Warning: Extrapolation applied for SNR range ' int2str(snrRange_extrapol(1)) ' to ' int2str(snrRange_extrapol(end)) '.' ])
end
tab=find(data.CountedErrors(1:N2)~=0);
CE_wo0 = data.CountedErrors(tab);
S_wo0 = data.SimulatedBits(tab);
SNR_wo0=SNR(tab);
[trend,trendSNR] = trendline(SNR_wo0,CE_wo0./S_wo0,polyOrder,snrStep,desiredSNREnd);
%--Find spec dB location
spec={'10^-1' '10^-2' '10^-3' '10^-4' '10^-5' '10^-6'};
for i=1:size(spec,2)
locSpec = find(trend<str2num(spec{1,i}));
myLine = 'Trendline';
if isempty(locSpec)
fprintf('%s didnt cross the %s axis.\n',myLine,spec{i})
locationSpec(i)=-1;
SpecMet(i)=-1;
break
else
locationSpec(i) = locSpec(1);
SpecMet(i) = snrRange(locationSpec(i));
fprintf('%s crosses the %s axis at SNR = %1.2f dB.\n',myLine,spec{i},SpecMet(i)+1 )%+1 for hack
end
end
%-- Save data
data.trend=trend;
data.locationSpec=locationSpec;
data.spec=spec;
data.SpecMet=SpecMet;
data.snrRange_nomodif=snrRange_nomodif;
data.snrRange_extrapol=snrRange_extrapol;
data.SNR_wo0=SNR_wo0;
data.trendSNR=trendSNR;
save(data.fOut,'data')
%--------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -