⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pr2_45.m

📁 Spread Spectrum and CDMA Principles and Applications 书籍和代码
💻 M
字号:
%Problem 2.45;
%Binary transmission;
%Experimentally finds error probabilities for arbitrary pairs of signals
%and compares the results with the theoretical predictions.

clear all; close all;
A=[ones(1,100); ones(1,50),-ones(1,50); -ones(1,70),ones(1,30); zeros(1,100)]; %we prepare matrix for all choices of sigfnals;
S=[A(1,:);-A(1,:)]; S=[zeros(2,10),S,zeros(2,10)]; %we choose a signal pair and pad zeros in front and end to have better visualization;
ds=norm(S(1,:)-S(2,:)); %find Euclidean distance between signals;
SNR=0.85; %set SNR per sample within 0.8 through 1.0;
nd=norm(S(1,:))/SNR; %calculate noise standard deviation providing set SNR;
No=normrnd(0,nd,1000,120); %Forming 1000 Gaussian noise vectors;
Ntr=2; %take either 1st or 2nd signal as sent;
er=0; %initialization of error counter;
Y=kron(ones(1000,1),S(Ntr,:))+No; %Forming 1000 observations;
subplot(211); plot(S'); grid; xlabel('t'); ylabel('signals'); ylim([-1.2 1.2]); %plotting signals
subplot(212); plot(Y(1:5,:)'); grid; xlabel('t'); ylabel('observations'); %plotting 5 superimposed observations;
for k=1:1000
    er=er+(norm(Y(k,:)-S(Ntr,:))>norm(Y(k,:)-S(3-Ntr,:))); %we compare Euclidean distances from 1000 observation to both signals;
end; %we have counted how many observations of 1000 are closer to wrong signal;
berex=er/1000; %counting experimental error probability;
bert=1-normcdf(ds/(2*nd)); %theoretically evaluated error probability;
disp('     SNR      ExErPr   TheErPr');
fprintf('\n');
disp([SNR,berex,bert]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -