How to i change the SNR to Vector?

조회 수: 2(최근 30일)
Faheem Ur Rehman
Faheem Ur Rehman 2021년 8월 31일
댓글: Walter Roberson 2021년 9월 1일
I have following code and i want to change SNR=(-20:10:30). How can i do it in following code.
classdefhelperModClassTestChannel < 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
functionobj = helperModClassTestChannel(varargin)
% Support name-value pair arguments when constructing object
setProperties(obj,nargin,varargin{:})
end
end
methods(Access = protected)
functionsetupImpl(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
functiony = stepImpl(obj,x)
% Add channel impairments
yInt1 = addMultipathFading(obj,x);
yInt2 = addClockOffset(obj, yInt1);
y = addNoise(obj, yInt2);
end
functionout = addMultipathFading(obj, in)
% Get new path gains
reset(obj.MultipathChannel)
% Pass input through the new channel
out = obj.MultipathChannel(in);
end
functionout = 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
functionout = applyFrequencyOffset(obj, in)
obj.FrequencyShifter.FrequencyOffset =...
-(obj.C-1)*obj.CenterFrequency;
out = obj.FrequencyShifter(in);
end
functionout = 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
functionout = addNoise(obj, in)
out = awgn(in,obj.SNR);
end
functionresetImpl(obj)
reset(obj.MultipathChannel);
重置(obj.FrequencyShifter);
end
functions = infoImpl(obj)
ifisempty(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

답변(1개)

Wan Ji
Wan Ji 2021년 8월 31일
SNR = -20:10:30;
a(numel(SNR)) = helperModClassTestChannel();
fori = 1:1:SNR
a(i).SNR = SNR(i);
end
댓글 수: 2
Walter Roberson
Walter Roberson 2021년 9월 1일
SNR = -20:10:30;
fori = 1:1:SNR
a{i} = helperModClassTestChannel();
a{i}.SNR = SNR(i);
end

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by