0

请参阅下面我估计通道响应的代码。我应该如何将信道估计和脉冲整形集成到我的代码中?

%SNR (Eb/No) values in decibels  
SNR=[0:2:14]'; %column vector  
%SNR in linear scale  
snr=10.^(SNR/10);  

%-------------------------------------------------

%I create initial zero vectors for BER
BER=zeros(length(SNR),1)
%-----------------------------------------------


%some initial values
%totally Nmax symbols
Nmax=1000; %maximum number of iterations
Nerr=100; %minimum number of errors

for k=1:length(SNR), %I do MC trials for each SNR
for l=1:Nmax, %MC loop

%-------------------------------------------------

%DATA
%I create data as vectors of length Ns symbols
Ns=100;
data=2*round(rand(Ns,1))-1;
%data is random and generated again and again for each MC trial
%--------------------------------------------------

%totally Ns * Nmax symbols, if 100*1000 = 100 000
%results rather reliable down to 1e-4
%-------------------------------------------------

%plot data
if l==1 & k==1, %I plot to see things only once, at the first round
plot(data),title('data'),axis([0 Ns -1.1 1.1]),pause,
end
%-------------------------------------------------

%MODULATION
%BPSK signal
bpsk=data;

%-------------------------------------------------

%noise gereration for BPSK
n=1/sqrt(2)*(randn(Ns,1)+j*randn(Ns,1));
%Since complex noise is generated by two real noise sequences the
%total variance is 2 x variance of one sequence(now 1). If we multiply
%by 1/sqrt(2) the total variance of noise becomes1.
%This is two sided noise spectral density No in BER equations.

%we check this
if l==1 & k==1,
var_n=norm(n)^2, pause
end
%This should be Ns since I sum Ns variables.
%Since n is a realization of a random process,
%the result is not exact.
%Average of repeated trials gives more exact result.
%---------------------------------------------------


%AWGN BPSK
Bpsk=sqrt(snr(k))*data+n; %snr is Eb/N0 in BER equations
if l==1 & k==1,
plot([real(Bpsk) data])
legend('real part of signal','data'),
title('BPSK signal in noise'),pause
end
%--------------------------------------------

%DEMODULATION

%BPSK
r1=real(Bpsk); %demodulated signal, soft decision
%different demodulated symbols
if l==1 & k==1,
plot([r1])
title('demodulated symbols'),pause
end

%hard decisions, converts soft demodulated symbolsto sequence of +-1
%AWGN
d1=find(r1>=0);d2=find(r1<0);
r1(d1)=1;r1(d2)=-1;

%plot example
if l==1 & k==1,
plot([r1])
axis([0 Ns -1.1 1.1]),
title('demodulated symbols after hard decisions')
pause
end
%--------------------------------------------------

%BER analysis
%errors in the current MC run
Ber=length(find((data-r1)~=0)); %number of errors in AWGN
if k==1 & l==1,
errors=[Ber],pause
end
%---------------------------------------------------

%we add errors to previous error counts, initially zero
%index k is for SNRs
BER(k)=BER(k)+Ber; %AWGN
%-------------------------------------------------

%I stop MC trials if minimum number of errors is obtained in all systems
if BER(k)>Nerr ,
break %terminates the innermost loop
end

end %end MC
%------------------------------------------------

%I calculate BER by dividing number of successful trials by their total number
BER(k)=BER(k)/Ns/l;

end %ends SNR loop
%--------------------------------------------------

%all simulated BER and corresponding SNR in a matrix
BER=[SNR BER ]
%------------------------------------------------

%logarithmic plot (y-axis)
semilogy(SNR,[BER ])
xlabel('SNR [dB]')
ylabel('BER')
axis([0 SNR(length(SNR)) 1e-6 .5])
grid on
4

0 回答 0