How to i change the SNR to Vector?
4 次查看(过去 30 天)
显示 更早的评论
I have following code and i want to change SNR=(-20:10:30). How can i do it in following code.
classdef helperModClassTestChannel < matlab.System
properties
SNR = 20;
CenterFrequency = 2.4e9
end
properties (Nontunable)
SampleRate = 1
PathDelays = 0
AveragePathGains = 0
KFactor = 3
MaximumDopplerShift = 0
MaximumClockOffset = 0
end
properties(Access = private)
MultipathChannel
FrequencyShifter
TimingShifter
C % 1+(ppm/1e6)
end
methods
function obj = helperModClassTestChannel(varargin)
% Support name-value pair arguments when constructing object
setProperties(obj,nargin,varargin{:})
end
end
methods(Access = protected)
function setupImpl(obj)
obj.MultipathChannel = comm.RicianChannel(...
'SampleRate', obj.SampleRate, ...
'PathDelays', obj.PathDelays, ...
'AveragePathGains', obj.AveragePathGains, ...
'KFactor', obj.KFactor, ...
'MaximumDopplerShift', obj.MaximumDopplerShift);
obj.FrequencyShifter = comm.PhaseFrequencyOffset(...
'SampleRate', obj.SampleRate);
end
function y = stepImpl(obj,x)
% Add channel impairments
yInt1 = addMultipathFading(obj,x);
yInt2 = addClockOffset(obj, yInt1);
y = addNoise(obj, yInt2);
end
function out = addMultipathFading(obj, in)
% Get new path gains
reset(obj.MultipathChannel)
% Pass input through the new channel
out = obj.MultipathChannel(in);
end
function out = addClockOffset(obj, in)
% Determine clock offset factor
maxOffset = obj.MaximumClockOffset;
clockOffset = (rand() * 2*maxOffset) - maxOffset;
obj.C = 1 + clockOffset / 1e6;
% Add frequency offset
outInt1 = applyFrequencyOffset(obj, in);
% Add sampling time drift
out = applyTimingDrift(obj, outInt1);
end
function out = applyFrequencyOffset(obj, in)
obj.FrequencyShifter.FrequencyOffset = ...
-(obj.C-1)*obj.CenterFrequency;
out = obj.FrequencyShifter(in);
end
function out = applyTimingDrift(obj, in)
originalFs = obj.SampleRate;
x = (0:length(in)-1)' / originalFs;
newFs = originalFs * obj.C;
xp = (0:length(in)-1)' / newFs;
out = interp1(x, in, xp);
end
function out = addNoise(obj, in)
out = awgn(in,obj.SNR);
end
function resetImpl(obj)
reset(obj.MultipathChannel);
reset(obj.FrequencyShifter);
end
function s = infoImpl(obj)
if isempty(obj.MultipathChannel)
setupImpl(obj);
end
% Get channel delay from fading channel object delay
mpInfo = info(obj.MultipathChannel);
% Calculate maximum frequency offset
maxClockOffset = obj.MaximumClockOffset;
maxFreqOffset = (maxClockOffset / 1e6) * obj.CenterFrequency;
% Calculate maximum timing offset
maxClockOffset = obj.MaximumClockOffset;
maxSampleRateOffset = (maxClockOffset / 1e6) * obj.SampleRate;
s = struct('ChannelDelay', ...
mpInfo.ChannelFilterDelay, ...
'MaximumFrequencyOffset', maxFreqOffset, ...
'MaximumSampleRateOffset', maxSampleRateOffset);
end
end
end
0 个评论
回答(1 个)
Wan Ji
2021-8-31
SNR = -20:10:30;
a(numel(SNR)) = helperModClassTestChannel();
for i = 1:1:SNR
a(i).SNR = SNR(i);
end
2 个评论
Walter Roberson
2021-9-1
SNR = -20:10:30;
for i = 1:1:SNR
a{i} = helperModClassTestChannel();
a{i}.SNR = SNR(i);
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Test and Measurement 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!