www.gusucode.com > UWB_matlab源码程序 > CP0703/cp0703_random_coefficients.m

    %
% FUNCTION 7.11 : "cp0703_random_coefficients"
%
% This function selects coefficients for a set of BFs
% fit a given emission mask.
%
% The function receives as input:
% 1) the number of attempts in the random selection of the
%    coefficients 'attempts'
% 2) the set of BFs 'basefunction'
% 3) the sampling period 'dt'
% 4) the number of samples in the time domain 'smp'
% 5) the pulse repetition period 'Ts'
% 6) the frequency smoothing factor 'freqsmoothfactor' 
% 7) the target emission mask
% 8) and 9) the range of BFs to be used in the
%    mask fitting, given by the values 'lowerbasefunction'
%    and 'higherbasefunction'
% 
% The function returns:
% 1) the best coefficient set 'c'
% 2) a flag on the validity of the returned set 'result'

% The function singles out the best coefficient set for
% the BF set given as input within the sets
% found during the 'attempts' iterations by comparing the
% PSD of the resulting waveform for each iteration with the
% target emission mask
% After 'attempts' iterations, the function returns the best
% set, defined as the set leading to the waveform with
% maximum power within all sets fitting the mask
% 
% Programmed by Luca De Nardis

function [c,result] = cp0703_random_coefficients...
   (attempts, basefunction, dt, smp, Ts,...
   freqsmoothfactor, emissionmask, lowerbasefunction,...
   higherbasefunction)

% -----------------------------------------------
% Step Zero - Input parameters and initialization
% -----------------------------------------------

% sampling frequency
fs = 1 / dt;
% number of samples (i.e., size of the FFT)
N = freqsmoothfactor * smp;
% fundamental frequency 
df = 1 / (N * dt);

% initialization of the positive frequency axis
positivefrequency=linspace(0,(fs/2),N/2);
% initialization of the coefficient set vector
a=zeros(1,15);
% Inizialization of the random number generator
rand('state',sum(100*clock)); 

% ---------------------------------------------------------
% Step One - Evaluation of the best combination through
%            random search
% ---------------------------------------------------------

for numattempts=1:attempts

  % initialization of the power vector component for the
  % actual attempt
  P(numattempts)=0;
  % initialization of the coefficient set vector for the
  % actual attempt
  C(numattempts,1:15)=nan; 
  for i=lowerbasefunction:higherbasefunction
        count = 0;
        while (count < 100)
            count=count+1;
            if rand < (0.5)
                a(i) = rand;
            else
                a(i) = -rand;
            end
            % generation of the waveform associated with the
            %  actual coefficient set
            combo=a * basefunction;
            % double-sided MATLAB amplitude spectrum
            X=fft(combo,N);
            % conversion from MATLAB spectrum to Fourier
            % spectrum
            X=X/N;
            % double-sided ESD of the waveform
            E = fftshift(abs(X).^2/(df^2));
            % single-sided ESD of the waveform
            Ess = 2.*E((N/2+1):N);
            % PSD of the combination in dBm/MHz
            PSD = 10 * log10 ((1/Ts) * Ess / 377) + 90;            

            % comparison between the PSD and the mask
            if all(PSD < emissionmask)  
                % recording the power associated to the
                %  actual set
                found=1;
                % recording the actual set
                P(numattempts)=sum(1/Ts .* Ess.*df / 377);
                C(numattempts,1:15)=a;
                count=100;
            end
        end
    end
end

result = found;  % Setting the flag for function output
if(found==1)    
    [m,h]=max(P);% Selection of the set leading to the
                 % waveform at highest power 
    c=C(h,1:15); % Recording the set for function output
end