problem in the my matlab code at demodulation with counting error (xor) bits are not equal / balance it showing in command prompt
3 ビュー (過去 30 日間)
古いコメントを表示
clc;
clear;
close all;
N=1e5; %Number of data bits to send over the channel
EbN0dB=0:1:20;
N=N+rem((3-rem(N,3)),3); %add additional bits to the data to make the length multiple of 3
% one 8-PSK symbol contains 3 binary bits
x=rand(1,N)>=0.5;%Generate random 1's and 0's as data;
figure(1);
grid on;
stem( x(1:30),'filled')
%Club 3 bits together and gray code it individually
inputSymBin=reshape(x,3,N/3)';
g=bin2gray(inputSymBin);
%Convert each Gray coded symbols to decimal value this is to ease the process
%of mapping based on array index
b=bin2dec(num2str(g,'%-1d'))';
%8-PSK Constellation Mapper
%8-PSK mapping Table
map=[1.414 0.707;0.707 1.414;-0.707 1.414;-1.414 0.707;-1.414 -0.707;-0.707 -1.414;0.707 -1.414;1.414 -0.707];
s=map(b(:)+1,1)+1i*map(b(:)+1,2);
figure;
plot(real(s),imag(s),'ko','MarkerFaceColor','g','MarkerSize',7);
grid;
%plot(s);
% Filter Definition
%square root raised cosine filter at tansmitter for avoid the inter symbol
%interference (ISI).
% Define filter-related parameters.
filtorder = 16; % Filter order
nsamp=4;
delay = filtorder/(nsamp*2); % Group delay (# of input samples)
rolloff = 0.35; % Rolloff factor of filter
%Create a square root raised cosine filter.
rrcfilter = rcosine(1,nsamp,'fir/sqrt',rolloff,delay);
% Plot impulse response.
figure; impz(rrcfilter,1);
% Transmitted Signal
% Upsample and apply square root raised cosine filter.
ys = rcosflt(s,1,nsamp,'filter',rrcfilter);
%figure;
%impz(ys,1);
% Create Rayleigh fading channel object.
tau12 = [0 1e-6];
pdb12 = [0 3];
%h12 = rayleighchan(Ts,fd,tau12,pdb12);
%h12.PathGains
chan = rayleighchan(1/10000,100,tau12,pdb12);
ys1 = filter(chan,ys); % Apply the channel effects
%Simulation for each Eb/N0 value
M=8; %Number of Constellation points M=2^k for 8-PSK k=3
Rm=log2(M); %Rm=log2(M) for 8-PSK M=8
Rc=1; %Rc = code rate for a coded system. Since no coding is used Rc=1
simulatedBER = zeros(1,length(EbN0dB));
theoreticalBER = zeros(1,length(EbN0dB));
count=1;
figure;
for i=EbN0dB
%-------------------------------------------
%Channel Noise for various Eb/N0
%-------------------------------------------
%Adding noise with variance according to the required Eb/N0
EbN0 = 10.^(i/10); %Converting Eb/N0 dB value to linear scale
noiseSigma = sqrt(2)*sqrt(1./(2*Rm*Rc*EbN0)); %Standard deviation for AWGN Noise
%Creating a complex noise for adding with 8-PSK s signal
%Noise is complex since 8-PSK is in complex representation
n = noiseSigma*(randn(1,length(ys1))+1i*randn(1,length(ys1)))';
y = ys1 + n;
plot(real(y),imag(y),'r*');hold on;
plot(real(s),imag(s),'ko','MarkerFaceColor','g','MarkerSize',7);hold off;
title(['Constellation plots - ideal 8-PSK (green) Vs Noisy y signal for EbN0dB =',num2str(i),' dB']);
grid;
%pause;
y=2;
%Demodulation
%Find the signal points from MAP table using minimum Euclidean distance
demodSymbols = zeros(1,length(y));
for j=1:length(y)
[minVal,minindex]=min(sqrt((real(y(j))-map(:,1)).^2+(imag(y(j))-map(:,2)).^2));
demodSymbols(j)=minindex-1
end
demodBits=dec2bin(demodSymbols)-'0'; %Dec to binary vector
xBar=gray2bin(demodBits)'; %gray to binary
xBar=xBar(:)'
bitErrors=sum(sum(xor(x,xBar)));
simulatedBER(count) = log10(bitErrors/N);
theoreticalBER(count) = log10(1/3*erfc(sqrt(EbN0*3)*sin(pi/8)));
count=count+1;
end
figure;
grid;
plot(EbN0dB,theoreticalBER,'r-*');hold on;
plot(EbN0dB,simulatedBER,'k-o');
title('BER Vs Eb/N0 (dB) for 8-PSK');legend('Theoretical','Simulated');grid on;
xlabel('Eb/N0 dB');
ylabel('BER - Bit Error Rate');
grid on;
0 件のコメント
採用された回答
Sean de Wolski
2011 年 8 月 26 日
So what is the problem?
Type:
dbstop if error
and then run it, the program will stop when an error occurs and you can inspect it to see what's going on.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で PHY Components についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!