I a getting error while executing the code.Please help me to solve this

13 ビュー (過去 30 日間)
Prabha Kumaresan
Prabha Kumaresan 2017 年 11 月 20 日
コメント済み: Walter Roberson 2017 年 11 月 20 日
%//////// OFDMA ////////////
% No. of Subcarriers
NS = 512;
% Input Generation
x = rand(1,NS)>0.5;
fftlength = 512;
nd = 6;
BW = 5e6;
FS = 2*BW; % Sampling Frequency
% Conversion of data from serial to parallel
p = series2parallel(x,NS);
% M ary Modulation of PSK and QAM
M = 2;
X = 0;
for count1 = 2:1:7;
if (M==2||M==4||M==16||M==64)
M = M+X;
% M-ary modulation for producing y.
if(M<=8)
% Modulation for PSK
y = modulate(modem.pskmod(M),p);
else
% Modulation for QAM
y = modulate(modem.qammod(M),p);
end
ylen = length(y);
%Applying Mapping
q_out = ofdma_mapping(y,ylen);
% Apply IFFT operation
outifft = ifft(q_out);
% Cyclic Prefix Addition
cp(count1,:) = cyclicpad(outifft,64);
% Length of CP
cplength = length(cp);
% Conversion of data from parallel to serial
out = reshape(cp(count1,:),1,cplength);
% Signal transmits through AWGN channel.
ynoisy = awgn(out,100,'measured');
% Addition of Rayleigh Fading
c = rayleighchan(1/1000,100,[0 2e-5],[0 -9]);
rf = filter(c,ynoisy);
% Conversion of data from serial to parallel
p2 = series2parallel(rf,cplength);
re_par = real(p2);
% Remove cyclic prefix
rcp(count1,:) = decyclicpad(p2,64);
rcplength = length(rcp);
% FFT
zzfft = fft(rcp(count1,:),fftlength);
%Apply Demapping
qq_out = ofdma_demapping(zzfft,fftlength);
outfft = qq_out;
% %Applying IFFT
% zfft = ifft(qq_out);
if (M<=8)
% Demodulation of PSK at Reciever
z=demodulate(modem.pskdemod(M),outfft);
else
% Demodulation of QAM at Reciever
z=demodulate(modem.qamdemod(M),outfft);
end
% Conversion of data from parallel to serial
xdash = reshape(z,1,NS)
berr = 0 ;
for a = 1:1:NS;
if (xdash(:,a) == x(:,a))
berr = 0;
else
berr = berr+1;
end
end
tberr(count1,:) = berr;
Eb_No = 0:1:NS-1;
Eb_No = 0.4*Eb_No;
if(M<=8)
ber(count1,:) = berawgn(Eb_No,'psk',M,'nondiff');
Pe(count1,:) = erfc(sqrt(0.9*Eb_No)*sin(pi/M));
else
ber1(count1,:) = berawgn(0.9*Eb_No,'qam',M);
Pe(count1,:) = 2*((1-(1/sqrt(M)))*erfc(sqrt((1.5*Eb_No)/(M-1))));
end
for init = 1:1:32
switch M
end
end
end
M= 2^count1;
end
figure()
% Plot SNR and BER
semilogy(Eb_No,ber(2,:),'k',Eb_No,ber(3,:),'g',Eb_No,ber1(5,:),'b',Eb_No,ber1(7,:),'r');
axis([0 25 0.0001 1]);
xlabel('SNR [dB]')
ylabel('BER')
legend('BPSK','QPSK','16-QAM','64-QAM')
title('OFDMA')
figure()
% Plot Error Probability
semilogy(Eb_No,Pe(2,:),'k',Eb_No,Pe(3,:),'r',Eb_No,Pe(5,:),'b',Eb_No,Pe(7,:),'g');
axis([0 50 0.0001 1]);
xlabel('SNR [dB]')
ylabel('Probability of Error')
legend('BPSK','QPSK','16-QAM','64-QAM')
title('OFDMA')
h = spectrum.periodogram;
figure()
HS = psd(h,outifft,'SpectrumType','twosided','NFFT',NS,'FS',FS);
plot(HS)
xlabel('Sampling Frequency (2BW) in MHz')
ylabel('Power Spectral Density [dBm/Hz]')
title('OFDMA')
grid off;
%///////////SC-FDMA///////
% No. of Subcarriers
NS = 512;
% Input Generation
x = rand(1,NS)>0.5;
fftlength = 512;
nd = 6;
BW = 5e6;
FS = 2*BW; % Sampling Frequency
% Conversion of data from serial to parallel
par2 = series2parallel(x,NS);
% M ary Modulation of PSK and QAM
M = 2;
X = 0;
for count1 = 2:1:7;
if (M==2||M==4||M==16||M==64)
M = M+X
% M-ary modulation for producing y.
if(M<=8)
% Modulation for PSK
y=modulate(modem.pskmod(M),par2);
else
% Modulation for QAM
y=modulate(modem.qammod(M),par2);
end
%Apply FFT operation
out_fft = fft(y,fftlength);
%Applying Mapping
q_out = scfdma_mapping(out_fft,fftlength);
% Apply IFFT operation
out_ifft = ifft(q_out);
% Cyclic Prefix Addition
cp(count1,:) = cyclicpad(out_ifft,64);
cplength = length(cp);
% Conversion of data from parallel to serial
out = reshape(cp(count1,:),1,cplength);
% Signal transmits through an AWGN channel.
ynoisy = awgn(out,100,'measured');
% Rayleigh Fading
c = rayleighchan(1/1000,100,[0 2e-5],[0 -9]);
rf = filter(c,ynoisy);
% Conversion of data from serial to parallel
p = series2parallel(rf,cplength);
re_par = real(p);
% Remove cyclic prefix
rcp(count1,:) = decyclicpad(p,64);
len_rcp = length(rcp);
% Applying FFT operation
cpfft = fft(rcp(count1,:),fftlength);
%Applying Demapping
qq_out = scfdma_demapping(cpfft,fftlength);
%Applying IFFT operation
out_fft = ifft(qq_out);
if (M<=8)
% Demodulation of PSK
z=demodulate(modem.pskdemod(M),out_fft);
else
% Demodulation of QAM
z=demodulate(modem.qamdemod(M),out_fft);
end
% Conversion of data from parallel to serial
xdash = reshape(z,1,NS)
berr = 0 ;
for a = 1:1:NS;
if (xdash(:,a) == x(:,a))
berr = 0;
else
berr = berr+1;
end
end
tberr(count1,:) = berr;
Eb_No = 0:1:NS-1;
if(M<=8)
ber(count1,:) = berawgn(0.9*Eb_No,'psk',M,'nondiff');
Pe(count1,:) = erfc(sqrt(2*Eb_No)*sin(pi/M));
else
ber1(count1,:) = berawgn(0.9*Eb_No,'qam',M);
Pe(count1,:) = 2*((1-(1/sqrt(M)))*erfc(sqrt((1.5*Eb_No)/(M-1))));
end
for init = 1:1:32
switch M
end
end
end
M= 2^count1;
end
figure()
% Plot SNR and BER
semilogy(Eb_No,ber(2,:),'*-r',Eb_No,ber(3,:),'k',Eb_No,ber1(5,:),'b',Eb_No,ber1(7,:),'g');
axis([0 25 0.0001 1]);
xlabel('SNR [dB]')
ylabel('BER')
legend('BPSK','QPSK','16-QAM','64-QAM')
title('SC-FDMA')
figure()
% Plot Error Probability
semilogy(Eb_No,Pe(2,:),'-k',Eb_No,Pe(3,:),'-r',Eb_No,Pe(5,:),'-b',Eb_No,Pe(7,:),'-c');
axis([0 50 0.0001 1]);
xlabel('SNR [dB]')
ylabel('Probability of Error')
legend('BPSK','QPSK','16-QAM','64-QAM')
title('SC-FDMA')
h = spectrum.periodogram;
figure()
HS = psd(h,out_ifft,'SpectrumType','twosided','NFFT',NS,'FS',FS);
plot(HS)
xlabel('Sampling Frequency (2BW) in MHz')
ylabel('Power Spectral Density [dBm/Hz]')
title('SC-FDMA')
grid off;
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 11 月 20 日
You did not give us any clue as to what error you are encountering, and you did not give us the full source code.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangePHY Components についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by