필터 지우기
필터 지우기

How can I use SNR vector instead of scalar in AWGN function ? Can I use arrayfun , cellfun , spfun, splitapply, bsxfun, structfun , or other ?

조회 수: 1 (최근 30일)
Hi there
(I have updates in the comments)
is there a way to use SNR vector instead of scalar in AWGN ?
The reason is to avoid for loop for SNR range as it requires long computation time for large number of input samplse
N = 2^20;
EbN0_dB = (0:18);
X = randi(2,1,N)-1;
Y = awgn(X,EbN0_dB,'measured');
The above code produces the following error
Error using awgn
Expected SNR input to be a scalar.
So I have to use for loop as below
clear
N = 2^20;
EbN0_dB = (0:18);
Erate = zeros(size(EbN0_dB));
Enum = Erate ;
X = randi(2,1,N)-1;
for n = 1:numel(EbN0_dB)
Y = awgn(X,EbN0_dB(n),'measured');
Y = Y>0.5 ;
[Enum(n),Erate(n)]=biterr(X,Y);
end
semilogy(EbN0_dB,Erate)
grid
This is just a sample code. I have several hundred lines of code for different modulation scheme.
Can I use arrayfun , cellfun , spfun, splitapply, bsxfun, structfun , or other ? is it useful and faster than for loop ?
% Thanks in advance
  댓글 수: 1
Mustafa qays
Mustafa qays 2017년 11월 15일
This is an update ... I have implemented it using bsxfun but looks like it is slower than for loop
Below is the first code using for loop for both awgn and biterr functions
tic()
clear
N = 2^21;
EbN0_dB = (0:18);
Erate = zeros(size(EbN0_dB));
Enum = Erate ;
X = randi(2,N,1)-1;
for n = 1:numel(EbN0_dB)
Y = awgn(X,EbN0_dB(n),'measured');
Y = Y>0.5 ;
[Enum(n),Erate(n)]=biterr(X,Y);
end
toc()
semilogy(EbN0_dB,Erate)
grid
Elapsed time
Elapsed time is 3.504173 seconds.
The second using for loop for awgn only
tic()
clear
N = 2^21;
EbN0_dB = (0:18);
Erate = zeros(size(EbN0_dB));
Enum = Erate ;
X = randi(2,N,1)-1;
Y = zeros(size(X).*size(EbN0_dB));
for n = 1:numel(EbN0_dB)
Y(:,n) = awgn(X,EbN0_dB(n),'measured');
end
Y = (Y>0.5)+0 ;
[Enum,Erate]=biterr(X,Y,[],'column-wise');
toc()
semilogy(EbN0_dB,Erate)
grid
Elapsed time
Elapsed time is 3.894274 seconds.
And finally , using bsxfun for awgn function
tic()
clear
N = 2^21;
EbN0_dB = (0:18);
Erate = zeros(size(EbN0_dB));
Enum = Erate ;
X = randi(2,N,1)-1;
YY = bsxfun(@(a,b) awgn(a,b,'measured'),X,EbN0_dB);
YY = (YY > 0.5)+0 ;
[Enum,Erate]=biterr(X,YY,[],'column-wise');
toc()
semilogy(EbN0_dB,Erate)
grid
Elapsed time
Elapsed time is 3.999013 seconds.
Waiting you comments and advises .

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by