?? simleofd_hwsnr.m
字號:
yifft=[];
xifft=[];
%ranges of Variables
num_symbol=100;%number of symbol,1k OFDM
N_OFDM=1024;%set 1K OFDM
nsamp=1;
M_print=4;%while ((M==M_print)*(EbNo==EbNo_print)) print some produre curve
EbNo_print=5;%while ((M==M_print)*(EbNo==EbNo_print)) print some produre curve
Mvec=[4 8 16];%Values of M PSK
EbNovec=[0:10];%Values of EbNo to consider
%Preallocate space for results
number_of_errors=zeros(length(Mvec),length(EbNovec));
sym_error_rate=zeros(length(Mvec),length(EbNovec));
for idxM=1:length(Mvec)
for idxEbNo=1:length(EbNovec)
M=Mvec(idxM);%size of signal constellation,QPSK
EbNo=EbNovec(idxEbNo);%set SNR; dB
K=log2(M);%number of bits per symbol
data_0=(N_OFDM*K)*num_symbol; %number of total bits for processing
%signal source,first create a binary data stream with 8000bits as
% colomn vector.
x=randint(data_0,1);%random binary data stream
%mapping into I-Q constellation
data_1= bi2de(reshape(x,K,length(x)/K).','left-msb');%produce 2bit symbol for modulating
data_21=pskmod(data_1,M,pi/M);%qpsk modulating,initial phase is pi/4
data_2=reshape(data_21,N_OFDM,100);%scatter the modulated signal vector to 1024rows and 100colomns matrix
%serial to parallel
data_3=data_2;
%IFFT
data_4=ifft(data_3);
%GI add
data_5=[data_4(N_OFDM,:);data_4];
%Add noise
ytx=data_5;% ytx is the transmitted signal;
%send signal over an AWGN channel
snr=EbNo+10*log10(M)-10*log10(nsamp);%convert EbNo value to the corresponding signal-to noise ratio(SNR)
ynoisy=awgn(ytx,snr,'measured');
yrx=ynoisy;%yrx is the received signal;
%GI remove
data_6=yrx([2:(N_OFDM+1)],:);
%FFT
data_7=fft(data_6);
%received singal demodulate
data_8=reshape(data_7,N_OFDM*num_symbol,1);
data_demod=pskdemod(data_8,M,pi/M);
while (M==4)&&(EbNo==5)
%figure(1);
%stem(x(1:40),'filled','--');
%title('Random Bits transmitted');
% xlabel('Bit Index'); ylabel('Binary Value');
%figure(2);
%stem(data_1(10240:10260),'filled','--');
%title('Random symbols transmitted');
%xlabel('Bit Index'); ylabel('Binary Value');
figure(3);
map=scatterplot(data_21);%scatter and display in constellation
axis([-3 3 -3 3]);
title('I-Q constellation');
xlabel('I'); ylabel('Q');
figure(4);
%for j=1:100
for i=1:N_OFDM
yifft=[yifft abs(data_4(i,1))];
xifft=[xifft i];
end
%end
plot(xifft,yifft,'--');
%figure(5);
map1=scatterplot(data_8);
axis([-3 3 -3 3]);
title('I-Q constellation');
xlabel('I'); ylabel('Q');
figure(6);
stem(data_demod(10240:10260),'filled','--');
title('Random symbols demodulated');
xlabel('Bit Index'); ylabel('Binary Value');
break,
end
[number_of_errors(idxM,idxEbNo),sym_error_rate(idxM,idxEbNo)]=symerr(data_1,data_demod);
end% End of loop over EbNo values
%% Plot a Curve.
figure(7);
markerchoice = '.xo*';
plotsym = [markerchoice(idxM) '-']; % Plotting style for this curve
semilogy(EbNovec,sym_error_rate(idxM,:),plotsym); % Plot one curve.
drawnow; % Update the plot instead of waiting until the end.
hold on; % Make sure next iteration does not remove this curve.
end% End of loop over M values
%% Complete the plot.
title('Performance of M-PSK for Varying M');
xlabel('EbNo (dB)'); ylabel('BER');
legend('M = 4','M = 8','M = 16','M = 32',...
'Location','SouthWest');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -