hi ;i have a question please help me , i want to replace randi instead randint in ofdm_basic code in r2017a , but i dont know how i must do it . please answer and help me . this is that line :
X=randint(1,Nused*Nframe,M); % bit: integer vector

 채택된 답변

Jan
Jan 2018년 1월 2일
편집: Jan 2018년 1월 2일

1 개 추천

Do you mean randint from the Communications Toolbox or is this from Octave code?
I assume, for both the answer is the same: It depends on what M is.
  • [0, range-1] if range is a positive integer
  • [range+1, 0] if range is a negative integer
  • Between min and max, inclusive, if range = [min,max] or [max,min]
% X = randint(1, Nused*Nframe, M)
if length(M) == 1
if M > 0
Range = [0, M-1];
else
Range = [M+1, 0];
end
else
Range = [min(M), max(M)];
end
X = randi(Range, 1, Nused*Nframe);
I do not have this toolbox, but I guess that you should find something like this, if you look into the randint function:
edit randint

댓글 수: 1

mohamad gholami
mohamad gholami 2018년 1월 2일
thank my friend . in next answer i explain . please read that

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

추가 답변 (5개)

Geoff Hayes
Geoff Hayes 2018년 1월 2일

0 개 추천

mohamad - which ofdm_basic code are you referring to? Is this something found on the MATLAB FileExchange or something else? From Communications System Toolbox Release Notes, it looks like randint has been removed from the Communications System Toolbox and is to be replaced with randi.
If we assume that the code
X=randint(1,Nused*Nframe,M)
creates a 1x(Nused*Nframe) matrix with integers in the interval [0,M-1], then we can replace the above with
X = randi(M, 1, Nused*Nframe) - 1;
I think that will work...

댓글 수: 4

mohamad gholami
mohamad gholami 2018년 1월 2일
편집: Geoff Hayes 2018년 1월 2일
hi my friend . this code is from this book : MIMO-OFDM Wireless Communications with MATLAB . this is the source code :
%OFDM_basic.m
clc
clear all
close all
NgType=1; %NgType=1/2 for cyclic prefix/zeropadding
if NgType==1, nt='CP';
else
end
if NgType==2, nt='ZP';
end
Ch=0; %Ch=0/1 for AWGN/multipath channel
if Ch==0, chType='AWGN'; Target_neb=100;
else chType='CH'; Target_neb=500;
end
figure(Ch+1),clf
PowerdB=[0 -8 -17 -21 -25]; %channel tap power profile 'dB'
Delay=[0 3 5 6 8]; %channel delay 'sample'
Power=10.^(PowerdB/10); %Channel tap power profile 'linear sample'
Ntap=length(PowerdB); %Channel tap number
Lch=Delay(end)+1; %Channel length
Nbps=4;
M=2^Nbps; %Modulation order =2//4/6for QPSK/16QAM/64QAM
Nfft=64; %FFT SIZE
Ng=Nfft/4; %GI(Guard interval)length(Ng= for no GI)
Nsym=Nfft+Ng; %Symbol duration
Nvc=Nfft/4; %Nvc=0: noVC(Virtual Carrier)
Nused=Nfft-Nvc;
EbN0=[0:5:30]; %EbN0
N_iter=1e5; %Number of iterations for each EbN0
Nframe=3; %Number of symbols per frame
sigPow=0; %Signal power initialization
file_name=['OFDM_BER_' chType '_' nt '_''GL' num2str(Ng) '.dat'];
fid=fopen(file_name,'w+');
norms=[1 sqrt(2) 0 sqrt(10) 0 sqrt(42)];%BPSK 4-QAM 16-QAM
for i=0:length(EbN0)
rng(0,'v5uniform');
rng(0,'v5normal');
%Ber2=ber(); %BER initialisation
Neb=0;
Ntb=0; %Initialise the number of error/total bits
for m=1:N_iter %Tx__________________________________________________________________
X=randint(1,Nused*Nframe,M); %bit:integer vector
Xmod=qammod(X,M,0,'gray')/norms(Nbps);
% if Ngtype~=2, x_GI=zeros(1,Nframe*Nsym+Ng); %Extend an OFDM symbol by Ng zeros
end
kk1=[1:Nused/2];
kk2=[Nused/2+1:Nused];
kk3=1:Nfft;kk4=1:Nsym;
for k=1:Nframe
if Nvc~=0, X_shift=[0 Xmod(kk2) zeros(1, Nvc-1) Xmod(kk1)];
else X_shift=[Xmod(kk2) Xmod(kk1)];
end
x=ifft(X_shift);
x_GI(kk4)=guard_interval(Ng,Nfft,NgType,x);
kk1=kk1+Nused;
kk2=kk2+Nused;
kk3=kk3+Nfft;
kk4=kk4+Nsym;
end
if Ch==0, y=x_GI; %No channel else %
multipath Fading channel=(randn(1,Ntap)+j*randn(1,Ntap)).*sqrt(Power/2);
h=zeros(1,Lch); h(Delay+1)=channel;%cir:channelimpulse response
y =conv(x_GI,h);
end
if 1i==0 %only to measure signal power for adding AWGN noise
y1= y(1:Nframe*Nsym);
sigPow=sigPow+y1*y1';
continue;
end
%Add AWGN noise________________________________________________
snr = EbN0(i)+10*(Nbps*(Nused/Nfft)); %SNR vs Eb/N0 by Eq.(4.28)
noise_mag = sqrt((10.^(-snr/10))*sigPow/2);
y_GI = y+ noise_mag*(randn(size(y)) +1j*randn(size(y)));
%Rx________________________________________________________________________
kk1=(NgType==2)*Ng+[1:Nsym];
kk2=1:Nfft;
kk3=1:Nused;
kk4=Nused/2+Nvc+1:Nfft;
kk5(Nvc~=0)+[1:Nused/2];
if Ch==1
H=fft([h zeros(1,Nfft-Lch)]);%Channel frequency response
H_shift(kk3)=[H(kk4) H(kk5)];
end
for k=1:Nframe
Y(kk2)= fft(remove_GI(Ng,Nsym,NgType,y_GI(kk1)));
Y_shift= [Y(kk4) Y(kk5)];
if Ch==0, Xmod_r(kk3)=Y_shift;
else
Xmod_r(kk3)= Y_shift./H_shift;%Equaliser-channel compensation
end
kk1=kk1+Nsym;
kk2=kk2+Nfft;
kk3=kk3+Nused;
kk4=kk4+Nfft;
kk5=kk5+Nfft;
end
X_r=qammod(Xmod_r*norms(Nbps),M,'gray');
Neb=Neb+sum(sum(de2bi(X_r,Nbps)~=de2bi(X,Nbps)));
Ntb=Ntb+Nused*NFrame*Nbps;%[BER,Neb,Ntb] =ber(bit_Rx,bit,nbps);
if Neb>Target_neb,break;
end
end
if 1i==0,sigPow=sigPow/Nsym/Nframe/N_iter;
else
Ber =Neb/ntb;
fprintf('EbN0=%3d[db],BER=%4d/%8d=%11.3e\n', EbN0(1i),Neb,Ntb,Ber)
fprintf(fid,'%d\t%11.3e\n', EbN0(1i), Ber);
if ber<1e6,% break;
end
end
if(fid~=0),fclose(fid);
end
plot_ber(file_name,Nbps);
ok, so try replacing with the line
X = randi(M, 1, Nused*Nframe) - 1;
I subtract one since randi will generate integers from the interval [1,M] and not the [0,M-1] that randint seems to be using.
mohamad gholami
mohamad gholami 2018년 1월 2일
thanks a lot . but please explain this line and this change for me
Geoff Hayes
Geoff Hayes 2018년 1월 3일
ummm...see randi and then replace your one line of code with this one...

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

Mochan Yang
Mochan Yang 2019년 7월 22일

0 개 추천

bitstream=randi(2,1,N)-1
Yusuf lamah
Yusuf lamah 2020년 3월 22일

0 개 추천

thank you very much
khalil nasri
khalil nasri 2021년 3월 6일

0 개 추천

randn( )>0;

댓글 수: 1

Walter Roberson
Walter Roberson 2021년 3월 6일
Normal distribution has peak probability at 0 exactly. Does testing for strict greater than give 50% exactly?

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

HONG CHENG
HONG CHENG 2022년 4월 28일

0 개 추천

you can look at this link
Specifically
You just need to change the order of paramters
a=randint(3,4,[1,4]);
a=randi([1,4],3,4);

카테고리

태그

질문:

2018년 1월 2일

답변:

2022년 4월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by