I can not find the solution of this code in line number 105 and 112.Urgently needed .Please help me.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
clc
clear all; % Number of Users
%------------------Generation of gold code--------------------------------
n=input('enter the number of flip flops=');
L=(2^n)-1;
seq1=zeros(1,L);
for i=1:n
seq1(1,i)=1;
end
for i=n+1:L
seq1(i)=~seq1(i-1).*seq1(i-1)+seq1(i-2).*~seq1(i-1);
end
seq2=zeros(1,L);
for i=1:n
seq2(1,i)=1;
end
for i=n+1:L
seq2(i)=~seq2(i).*seq2(i-1)+seq2(i-2).*~seq2(i-1);
end
seq3=zeros(1,L);
for i=1:n
seq3(1,i)=1;
end
for i=n+1:L
seq3(i)=~seq3(i).*seq3(i-1)+seq3(i-1).*~seq3(i-1);
end
seq4=zeros(1,L);
for i=1:n
seq4(1,i)=1;
end
for i=n+1:L
seq4(i)=~seq4(i-2).*seq4(i-1)+seq4(i).*~seq4(i-1);
end
code1=xor(seq1,seq4);
code2=xor(seq2,seq3);
%------------------Generating data for User1-------------------------------
N=10^3; % Number of Bits for data_user1
data_user1= rand(1,N)>0.5; % Generation of data for user1
data_user1bpsk = 2*data_user1-1; % BPSK modulation 0 -> -1; 1 -> 0
%------------------Spreading & IFFT for User1------------------------------
data_user11=data_user1bpsk';
spdata1_user1=data_user11*code1; % Spreading
spdata12=(spdata1_user1)';
ifftdata_user1=ifft(spdata12); % Taking the IFFT
ifftdata12=ifftdata_user1';
%------------------Append Cyclic Prefix1 for User1-------------------------
y1=[ifftdata12(:,[(n-2):n]) ifftdata12];
transdata1=y1';
tx_user1=transdata1; % Transmitting data for user1
%------------------Generating data for User2-------------------------------
M=10^3; % Number of Bits for data_user2
data_user2= rand(1,M)>0.5; % Generation of data for user2
data_user2bpsk = 2*data_user2-1; % BPSK modulation 0 -> -1; 1 -> 0
%-----------------Spreading & IFFT for User2-------------------------------
data_user21=data_user2bpsk';
spdata2=data_user21*code2; % Spreading
spdata22=(spdata2)';
ifftdata_user2=ifft(spdata22); % Taking the IFFT
ifftdata22=ifftdata_user2';
%-----------------Append Cyclic Prefix1 for User2--------------------------
y2=[ifftdata22(:,[(n-2):n]) ifftdata22];
transdata2=y2';
tx_user2=transdata2; % Transmitting data for user2
%----------------------Adding data for Transmission of All User------------
x=tx_user1+tx_user2;
%----------------------Creating Rayleigh Channel---------------------------
Taps=4; % Number of Taps
p1=0.5/2.3; % Power of Tap1
p2=0.9/2.3; % Power of Tap2
p3=0.7/2.3; % Power of Tap3
p4=0.2/2.3;
gain1=sqrt(p1/2)*[randn(1,N) + j*randn(1,N)]; % Gain for Tap1
gain2=sqrt(p2/2)*[randn(1,N) + j*randn(1,N)]; % Gain for Tap2
gain3=sqrt(p3/2)*[randn(1,N) + j*randn(1,N)]; % Gain for Tap3
gain4=sqrt(p4/2)*[randn(1,N) + j*randn(1,N)]; % Gain for Tap4
x11=x(:);
x12=reshape(x11,1,length(x11));
i=1:length(x12);
delay1=1;
for i=delay1+1:length(x12) % Producing one sample delay in Tap2 w.r.t. Tap1
x13(i)=x(i-delay1);
end
delay2=2;
for i=delay2+1:length(x12) % Producing two sample delay in Tap2 w.r.t. Tap1
x14(i)=x(i-delay2);
end
delay3=3;
for i=delay3+1:length(x12) % Producing three sample delay in Tap2 w.r.t. Tap1
x15(i)=x(i-delay3);
end
x1=reshape(x13,(n+3),length(x13)/(n+3));
x2=reshape(x14,(n+3),length(x14)/(n+3));
x3=reshape(x15,(n+3),length(x15)/(n+3));
ch1=repmat(gain1,(n+3),1);
ch2=repmat(gain2,(n+3),1);
ch3=repmat(gain3,(n+3),1);
ch4=repmat(gain4,(n+3),1);
data_channel=x.*ch1+x1.*ch2+x2.*ch3+x3.*ch4; % Passing data through channel
%------------------------Addition of AWGN noise ---------------------------
data_noise1=data_channel(:);
data_noise2=reshape(data_noise1,1,length(data_noise1));
noise = 1/sqrt(2)*[randn(1,length(data_noise2)) + j*randn(1,length(data_noise2))];
snr = [0:20]; % multiple Eb/N0 values
for i = 1:length(snr)
y = data_noise2 + (sqrt(1)*10^(-snr(i)/20))*noise; %Addition of Noise
%--------------------------Receiver ---------------------------------------
data_received =y; %fadded data received with awgn noise
%---------------------Removing Cyclic Prefix-------------------------------
rx1=reshape(data_received,(n+3),length(data_received)/(n+3));
rx12=rx1';
rx13 = rx12(:,[(4:(n+3))]);
rx14=rx13';
%-----------------Taking FFT ----------------------------------------------
fft_data_received =fft(rx14);
%----------------equilization of the channel-------------------------------
channel_response=fft([gain1;gain2;gain3;gain4],n);
data_equilized=fft_data_received.*conj(channel_response);
%----------------BER of Data User1-----------------------------------------
recdata11=(data_equilized'*code1')';
recdata12=real(recdata11)>0;
errors_user1(i) = size(find([data_user1- recdata12]),2); %Errors for User1
SBer1 = errors_user1/N; % simulated ber user1
%----------------BER of Data User2-----------------------------------------
recdata21=(data_equilized'*code2')';
recdata22=real(recdata21)>0;
errors_user2(i) = size(find([data_user2- recdata22]),2); %Errors for User1
SBer2 = errors_user2/M; % simulated ber user2
end
% ------------------------Theoretical Result-------------------------------
snrlnr=10.^(snr/10);
TBer = 0.5*erfc(sqrt(snrlnr)); % Theoretical BER for AWGN
TBerf = 0.5.*(1-sqrt(snrlnr./(snrlnr+1)));% theoretical BER fro Flat fadding
%-------------------Displaying Result--------------------------------------
figure
semilogy(snr,TBer,'c*-','LineWidth',2);
hold on;
semilogy(snr,TBerf,'r-','LineWidth',3);
hold on;
semilogy(snr,SBer1,'bd','LineWidth',4);
hold on;
semilogy(snr,SBer2,'go-','LineWidth',1);
axis([0 20 10^-5 0.5]);
grid on
legend('Theoratical BER for BPSK on AWGN ','Theoratical BER for BPSK on Rayleigh Channel ' ,'Simulated BER for User1','Simulated BER for User2');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER Vs Eb/No on Rayleigh Channel')
4 commentaires
John BG
le 3 Juin 2016
correction: with
enter the number of flip flops=10
now the error is
Error using reshape
Size arguments must be real integers.
Error in fix_crash_26 (line 89)
x1=reshape(x13,(n+3),length(x13)/(n+3));
Réponses (2)
the cyclist
le 4 Juin 2016
length(x13) is not evenly divisible by (n+3), so you are trying to reshape to a non-integer number of elements, which is not sensible.
0 commentaires
John BG
le 4 Juin 2016
Modifié(e) : John BG
le 4 Juin 2016
Dear Mr Shil
Your are building a communications model. And you are starting from ground zero when SIMULINK has plenty of tools to help you build the BPSK spread basic chain you are attempting to build.
I have seen presentations of people who earn a lot designing mobile phones and base stations, and they even do not touch MATLAB, just SIMULINK.
I started commenting and suggesting some changes to your code
1.- don't waste time answering a prompt every time you run your script, at least not until it does not crash:
% n=input('enter the number of flip flops=');
n=5;
L=2^n-1;
2.- no need for those initial for loops
seq1=zeros(1,L);seq1([1:n])=1;seq1([n+2:2:L])=1
seq2=zeros(1,L); seq2([1:n])=1;seq2([n+2:2:L])=1;
seq3=zeros(1,L); seq3([1:n])=1;seq3([n+2:2:L])=1;
seq4=zeros(1,L); seq4([1:n])=1;seq4([n+2:2:L])=1;
code1=xor(seq1,seq4); code2=xor(seq2,seq3);
%------------------Generating data for User1-------------------------------
N=10^3; % Number of Bits for data_user1
data_user1= rand(1,N)>0.5; % Generation of data for user1
3.- BPSK means phase shift: same signal but shifted phase. Your 0->-1; 1->0 is ASK not BPSK. your 0->-1;1->0 should be among many BPSK possibilities: 0->-1; 1->1, or 0->1; 1->-1
data_user1bpsk = 2*data_user1-1; % BPSK modulation 0 -> -1; 1 -> 0
data_user1bpsk=data_user1; data_user1bpsk(data_user1bpsk==0)=-1;
data_user11=data_user1bpsk';
and 4.- the product of to 1xN 1xN vectors, product as you've written it, generates an NxN matrix use element wise product with v1.*v2
spdata1_user1=data_user11*code1;
However, the spreading is usually performed with xor mod2 operation, not a basic product
the essential reason being that the basic product is biased towards 0,
0*0=0 0*1=1 1*0=0 only 1*1=1, while xor and mod2 'spread' or better said
keep it statistically as spreaded as the input is, it does not 'bring down' 3/4th of the bit wise
products down to '0'
So change this to whatever spread operation you find suitable, but not attempting, for n=5, a multiplication of a 1001 vector against a 31 spread code vector
Mr Shil, your model would be up and running in no time if you translate it to SIMULINK. Would you like to try it?
If you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John
0 commentaires
Voir également
Catégories
En savoir plus sur Error Detection and Correction dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!