File: untitled.m Line: 1 Column: 5

C = 3e(8);
fc = 60e(9);
lambda = C/fc;
N = 2; % number of antenna in Tx
M = 2; % number of antenna in Rx
tx_location = [0;0;0];
rx_location = [1500;500;0];
[~,tx_theta] = rangeangle(rx_location,tx_location);
[~,rx_theta] = rangeangle(tx_location,rx_location);
Bw = 2*fc;
tx = [0;0;0];
rx = [0;0;0];
g = 1; % gain for the path
sisochan = scatteringchanmtx(tx,rx,tx_theta,rx_theta,g);
Ns = 1e6;
x = randi([0 1],Ns,1);
ebn0_param = -10:2:10;
SNR=0:2:20;
BER_SISO = helperMIMOBER(sisochan,x,ebn0_param)/Ns;
helperBERPlot(ebn0_param,BER_SISO);
legend('SISO')
C_SISO = Bw*log2(1+SNR );
% SIMO
rxarray = phased.ULA('NumElements',M,'ElementSpacing',lambda/2);
rxmopos = getElementPosition(rxarray)/lambda;
simochan = scatteringchanmtx(tx,rxmopos,tx_theta,rx_theta,g);
rxarraystv = phased.SteeringVector('SensorArray',rxarray,...
'PropagationSpeed',C);
wr = conj(rxarraystv(fc,rx_theta));
BER_SIMO = helperMIMOBER(simochan,x,ebn0_param,1,wr)/Ns;
helperBERPlot(ebn0_param,[BER_SISO(:) BER_SIMO(:)]);
legend('SISO','SIMO')
C_SIMO = Bw*log2(1+(M)*SNR);
%MISO
txarray = phased.ULA('NumElements',N,'ElementSpacing',lambda/2);
txmipos = getElementPosition(txarray)/lambda;
misochan = scatteringchanmtx(txmipos,rx,tx_theta,rx_theta,g);
txarraystv = phased.SteeringVector('SensorArray',txarray,...
'PropagationSpeed',C);
wt = txarraystv(fc,tx_theta)';
BER_MISO = helperMIMOBER(misochan,x,ebn0_param,wt,1)/Ns;
helperBERPlot(ebn0_param,[BER_SISO(:) BER_SIMO(:) BER_MISO(:)]);
legend('SISO','SIMO','MISO')
C_MISO = Bw*log2(1+(N)*SNR);
%MIMO
mimochan = scatteringchanmtx(txmipos,rxmopos,tx_theta,rx_theta,g);
C_MIMO = Bw*log2(1+(N)*(M)*SNR);
wt = txarraystv(fc,tx_theta)';
wr = conj(rxarraystv(fc,rx_theta));
BER_MIMO = helperMIMOBER(mimochan,x,ebn0_param,wt,wr)/Ns;
helperBERPlot(ebn0_param,[BER_SISO(:) BER_SIMO(:) BER_MISO(:) BER_MIMO(:)]);
legend('SISO (1*1)','SIMO (1*2)','MISO (2*1)','MIMO (2*2)')
xlabel('SNR (dB)')
ylabel('BER')
figure
plot(SNR,C_SISO(:),'-rs',SNR, C_SIMO(:),'*g',SNR, C_MISO(:),'--b',SNR, C_MIMO(:));
legend('SISO (1*1)','SIMO (1*2)','MISO (2*1)','MIMO (2*2)')
xlabel('SNR (dB)')
ylabel('Capacity (bit/s)')

3 Comments

why i cant run this code Error in untitled2 (line 19)
BER_SISO = helperMIMOBER(sisochan,x,ebn0_param)/Ns;
What happens when you try running that code?
  • Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
  • Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
  • Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
@Steven Lord — The Error messages had to do with the missing functions. Supplying them helped, however there were still errors in the code that I wouldn’t have expected to see in a MathWorks Blog post. I detailed them in my Comment.

Sign in to comment.

 Accepted Answer

Eliminate the parentheses —
C = 3e8;
fc = 60e9;
lambda = C/fc;
N = 2; % number of antenna in Tx
M = 2; % number of antenna in Rx
tx_location = [0;0;0];
rx_location = [1500;500;0];
[~,tx_theta] = rangeangle(rx_location,tx_location);
[~,rx_theta] = rangeangle(tx_location,rx_location);
Bw = 2*fc;
tx = [0;0;0];
rx = [0;0;0];
g = 1; % gain for the path
sisochan = scatteringchanmtx(tx,rx,tx_theta,rx_theta,g);
Ns = 1e6;
x = randi([0 1],Ns,1);
ebn0_param = -10:2:10;
SNR=0:2:20;
BER_SISO = helperMIMOBER(sisochan,x,ebn0_param)/Ns;
'helperMIMOBER' is used in Improve SNR and Capacity of Wireless Communication Using Antenna Arrays.
helperBERPlot(ebn0_param,BER_SISO);
legend('SISO')
C_SISO = Bw*log2(1+SNR );
% SIMO
rxarray = phased.ULA('NumElements',M,'ElementSpacing',lambda/2);
rxmopos = getElementPosition(rxarray)/lambda;
simochan = scatteringchanmtx(tx,rxmopos,tx_theta,rx_theta,g);
rxarraystv = phased.SteeringVector('SensorArray',rxarray,...
'PropagationSpeed',C);
wr = conj(rxarraystv(fc,rx_theta));
BER_SIMO = helperMIMOBER(simochan,x,ebn0_param,1,wr)/Ns;
helperBERPlot(ebn0_param,[BER_SISO(:) BER_SIMO(:)]);
legend('SISO','SIMO')
C_SIMO = Bw*log2(1+(M)*SNR);
%MISO
txarray = phased.ULA('NumElements',N,'ElementSpacing',lambda/2);
txmipos = getElementPosition(txarray)/lambda;
misochan = scatteringchanmtx(txmipos,rx,tx_theta,rx_theta,g);
txarraystv = phased.SteeringVector('SensorArray',txarray,...
'PropagationSpeed',C);
wt = txarraystv(fc,tx_theta)';
BER_MISO = helperMIMOBER(misochan,x,ebn0_param,wt,1)/Ns;
helperBERPlot(ebn0_param,[BER_SISO(:) BER_SIMO(:) BER_MISO(:)]);
legend('SISO','SIMO','MISO')
C_MISO = Bw*log2(1+(N)*SNR);
%MIMO
mimochan = scatteringchanmtx(txmipos,rxmopos,tx_theta,rx_theta,g);
C_MIMO = Bw*log2(1+(N)*(M)*SNR);
wt = txarraystv(fc,tx_theta)';
wr = conj(rxarraystv(fc,rx_theta));
BER_MIMO = helperMIMOBER(mimochan,x,ebn0_param,wt,wr)/Ns;
helperBERPlot(ebn0_param,[BER_SISO(:) BER_SIMO(:) BER_MISO(:) BER_MIMO(:)]);
legend('SISO (1*1)','SIMO (1*2)','MISO (2*1)','MIMO (2*2)')
xlabel('SNR (dB)')
ylabel('BER')
figure
plot(SNR,C_SISO(:),'-rs',SNR, C_SIMO(:),'*g',SNR, C_MISO(:),'--b',SNR, C_MIMO(:));
legend('SISO (1*1)','SIMO (1*2)','MISO (2*1)','MIMO (2*2)')
xlabel('SNR (dB)')
ylabel('Capacity (bit/s)')
Then, it works until it gets to the function call, and then stops.
.

5 Comments

still cant work
What is the exact error message you are getting now?
Searching for the ‘helperMIMOBER’ function eventually leads to this blog post: Steer Beams to Reality: from Phased Array to Beamforming, the code for it being:
function nber = helperMIMOBER(chan,x,snr_param,wt,wr)
Nsamp = size(x,1);
Nrx = size(chan,2);
Ntx = size(chan,1);
if nargin < 4
wt = ones(1,Ntx);
end
if nargin < 5
wr = ones(Nrx,1);
end
xt = 1/sqrt(Ntx)*(2*x-1)*wt; % map to bpsk
nber = zeros(Nrx,numel(snr_param),like,1); % real
for m = 1:numel(snr_param)
n = sqrt(db2pow(-snr_param(m))/2)*(randn(Nsamp,Nrx)+1i*randn(Nsamp,Nrx));
y = xt*chan*wr+n*wr;
xe = real(y)>0;
nber(:,m) = sum(x~=xe);
end
end
with the code next needing:
function helperBERPlot(ebn0,ber)
figure
h = semilogy(ebn0,ber);
set(gca,'YMinorGrid','on','XMinorGrid','on');
markerparam = {'x','+','^','v','.'};
for m = 1:numel(h)
h(m).Marker = markerparam{m};
end
xlabel('E_b/N_0 (dB)');
ylabel('BER');
end
Adding those two functions to the existing code then produces:
C = 3e8;
fc = 60e9;
lambda = C/fc;
N = 2; % number of antenna in Tx
M = 2; % number of antenna in Rx
tx_location = [0;0;0];
rx_location = [1500;500;0];
[~,tx_theta] = rangeangle(rx_location,tx_location);
[~,rx_theta] = rangeangle(tx_location,rx_location);
Bw = 2*fc;
tx = [0;0;0];
rx = [0;0;0];
g = 1; % gain for the path
sisochan = scatteringchanmtx(tx,rx,tx_theta,rx_theta,g);
Ns = 1e6;
x = randi([0 1],Ns,1);
ebn0_param = -10:2:10;
SNR=0:2:20;
BER_SISO = helperMIMOBER(sisochan,x,ebn0_param)/Ns;
helperBERPlot(ebn0_param,BER_SISO);
legend('SISO')
C_SISO = Bw*log2(1+SNR );
% SIMO
rxarray = phased.ULA('NumElements',M,'ElementSpacing',lambda/2);
rxmopos = getElementPosition(rxarray)/lambda;
simochan = scatteringchanmtx(tx,rxmopos,tx_theta,rx_theta,g);
rxarraystv = phased.SteeringVector('SensorArray',rxarray,...
'PropagationSpeed',C);
wr = conj(rxarraystv(fc,rx_theta));
BER_SIMO = helperMIMOBER(simochan,x,ebn0_param,1,wr)/Ns;
BER_SISO
BER_SISO = 1×11
0.3276 0.2871 0.2398 0.1868 0.1312 0.0789 0.0377 0.0125 0.0023 0.0002 0.0000
BER_SIMO
BER_SIMO = 2×11
0.2644 0.2123 0.1584 0.1039 0.0562 0.0227 0.0060 0.0008 0.0000 0 0 0.2644 0.2123 0.1584 0.1039 0.0562 0.0227 0.0060 0.0008 0.0000 0 0
helperBERPlot(ebn0_param,[BER_SISO(:) BER_SIMO(1,:).']);
legend('SISO','SIMO')
C_SIMO = Bw*log2(1+(M)*SNR);
%MISO
txarray = phased.ULA('NumElements',N,'ElementSpacing',lambda/2);
txmipos = getElementPosition(txarray)/lambda;
misochan = scatteringchanmtx(txmipos,rx,tx_theta,rx_theta,g);
txarraystv = phased.SteeringVector('SensorArray',txarray,...
'PropagationSpeed',C);
wt = txarraystv(fc,tx_theta)';
BER_MISO = helperMIMOBER(misochan,x,ebn0_param,wt,1)/Ns;
BER_MISO
BER_MISO = 1×11
0.2641 0.2137 0.1589 0.1034 0.0559 0.0226 0.0058 0.0008 0.0000 0 0
helperBERPlot(ebn0_param,[BER_SISO(:) BER_SIMO(1,:).' BER_MISO(:)]);
legend('SISO','SIMO','MISO')
C_MISO = Bw*log2(1+(N)*SNR);
%MIMO
mimochan = scatteringchanmtx(txmipos,rxmopos,tx_theta,rx_theta,g);
C_MIMO = Bw*log2(1+(N)*(M)*SNR);
wt = txarraystv(fc,tx_theta)';
wr = conj(rxarraystv(fc,rx_theta));
BER_MIMO = helperMIMOBER(mimochan,x,ebn0_param,wt,wr)/Ns;
BER_MIMO
BER_MIMO = 2×11
0.1856 0.1296 0.0782 0.0373 0.0125 0.0024 0.0002 0.0000 0 0 0 0.1856 0.1296 0.0782 0.0373 0.0125 0.0024 0.0002 0.0000 0 0 0
helperBERPlot(ebn0_param,[BER_SISO(:) BER_SIMO(1,:).' BER_MISO(:) BER_MIMO(1,:).']);
legend('SISO (1*1)','SIMO (1*2)','MISO (2*1)','MIMO (2*2)')
xlabel('SNR (dB)')
ylabel('BER')
figure
plot(SNR,C_SISO(:),'-rs',SNR, C_SIMO(:),'*g',SNR, C_MISO(:),'--b',SNR, C_MIMO(:));
legend('SISO (1*1)','SIMO (1*2)','MISO (2*1)','MIMO (2*2)', 'Location','best')
xlabel('SNR (dB)')
ylabel('Capacity (bit/s)')
grid
function nber = helperMIMOBER(chan,x,snr_param,wt,wr)
Nsamp = size(x,1);
Nrx = size(chan,2);
Ntx = size(chan,1);
if nargin < 4
wt = ones(1,Ntx);
end
if nargin < 5
wr = ones(Nrx,1);
end
xt = 1/sqrt(Ntx)*(2*x-1)*wt; % map to bpsk
nber = zeros(Nrx,numel(snr_param),'like',1); % real
for m = 1:numel(snr_param)
n = sqrt(db2pow(-snr_param(m))/2)*(randn(Nsamp,Nrx)+1i*randn(Nsamp,Nrx));
y = xt*chan*wr+n*wr;
xe = real(y)>0;
nber(:,m) = sum(x~=xe);
end
end
function helperBERPlot(ebn0,ber)
figure
h = semilogy(ebn0,ber);
set(gca,'YMinorGrid','on','XMinorGrid','on');
markerparam = {'x','+','^','v','.'};
for m = 1:numel(h)
h(m).Marker = markerparam{m};
end
xlabel('E_b/N_0 (dB)');
ylabel('BER');
end
However even that was not enough. After making a number of corrections to the code (including replacing ‘’ with '' in several places), and choosing only one row of the two-row matrices (that seem to be duplicates of the same vector) in order to make the concatenations work correctly, I can get it to run without error.
What else do you want to do with this?
.
yes i run this now
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!