gusucode.com > UWB_matlab源码程序 > CP0801/cp0801_PAMreceiver.m

    %
% FUNCTION 8.7 : "cp0801_PAMreceiver"
%
% Simulates the receiver for 2PAM DS UWB signals
% and computes the average BER
% 'R' is an array containing different waveforms
% of the received signal.
% 'mask' is the waveform of the correlation mask
% 'fc' is the sampling frequency
% 'bits' is the binary stream generated by the source
% (it is the same stream for all the waveforms in 'R')
% 'Ns' is the number of pulses per bit
% 'Ts' is the average pulse repetition period [s]
%
% The function returns the binary stream after the 
% detection process ('RXbits') and the vector 'BER'
% containing the average bit error rates for all
% the signals in the input array 'R'.
%
% Programmed by Guerino Giancola
%

function [RXbits,BER] = ...
   cp0801_PAMreceiver(R,mask,fc,bits,numbit,Ns,Ts)

% -----------------------------
% Step Zero - Receiver settings
% -----------------------------

HDSD = 2;
% HDSD = 1 --> Hard Decision Detection
% HDSD = 2 --> Soft Decision Detection

% -----------------------------------------
% Step One - Implementation of the receiver
% -----------------------------------------

% N is the number of different signals at the receiver
% input L is the number of samples representing each signal
[N,L] = size(R);

RXbits = zeros(N,numbit);

dt = 1 / fc;                        % sampling time
framesamples = floor(Ts ./ dt);     % number of samples per
                                    % frame
bitsamples = framesamples * Ns;     % number of samples per
                                    % bit

for n = 1 : N
    
    rx = R(n,:);
    mx = rx .* mask;
    
    if HDSD == 1 % Hard Decision Detection
        
        for nb = 1 : numbit

            mxk = mx(1+(nb-1)*bitsamples:bitsamples+...
               (nb-1)*bitsamples);
            No0 = 0;
            No1 = 0;
            
            for np = 1 : Ns
                mxkp = mxk(1+(np-1)*framesamples:...
                   framesamples+(np-1)*framesamples);
                zp = sum(mxkp.*dt);
                if zp < 0 
                    No0 = No0 + 1; 
                else      
                    No1 = No1 + 1;
                end
            end % for np = 1 : Ns
            
            if No0 > No1
                % the estimated bit is '0'
                RXbits(n,nb) = 0;
            else
                % the estimated bit is '0'
                RXbits(n,nb) = 1;
            end
            
        end % for nb = 1 : numbit
        
    end % end of Hard Decision Detection
    
    if HDSD == 2 % Soft Decision Detection
        
        for nb = 1 : numbit
            
            mxk = mx(1+(nb-1)*bitsamples:...
               bitsamples+(nb-1)*bitsamples);
            zb = sum(mxk.*dt);
            
            if zb < 0
                % the estimated bit is '0'
                RXbits(n,nb) = 0;
            else
                % the estimated bit is '1'
                RXbits(n,nb) = 1;
            end
            
        end % for nb = 1 : numbit
                
    end % end of Soft Decision Detection

end % for n = 1 : N

% ---------------------
% Step Two - Statistics
% ---------------------

for n = 1 : N
    WB = sum(abs(bits-RXbits(n,:)));
    BER(n) = WB / numbit; % average Bit Error Rate
end