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

    %
% FUNCTION 7.8 : "cp0703_random_pulse_combination"
%
% This function implements the random selection algorithm
% described in Section 7.2 for the determination of a
% combination of the first 15 Gaussian derivatives fitting
% the FCC emission mask
%
% 'smp' samples of the Gaussian pulse are considered in
% the time interval 'Tmax - Tmin' 
%
% The function receives as input:
% 1) the index 'i' indicating which setting must be adopted
%    for the shape factors of the derivatives
% 2) the pulse pepetition period Ts
% 3) the number of attempts in the random selection of the
%    coefficients 'attempts'
%
% The function returns:
% 1) the best coefficient set 'coefficient'
% 2) the coefficients for the set formed  by each single
%    derivative 'singlederivativeset'
% 3) the set of derivatives 'derivative'
% 4) a flag on the validity of the returned vectors
%    'validresult'
% 5) the fundamental frequency df

% The function singles out the best coefficient set within
% the sets found during the 'attempts' iterations and the
% best coefficient for the solutions based on each single
% derivative
% The function then plots the target mask, the solutions
% based on each single derivative, and the solution based on
% the set of the 15 derivatives of the Gaussian pulse
% 
% Programmed by Luca De Nardis

function [coefficients, singlederivativecoeff,...
   derivative, validresult,df] = ...
   cp0703_random_pulse_combination(i,Ts,attempts)

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

% lower time limit
Tmin=-4e-9;
% upper time limit
Tmax=4e-9;
% number of samples
smp = 1024;

% sampling period
dt = (Tmax-Tmin) / smp;
% sampling frequency
fs = 1/dt;
frequencysmoothingfactor = 8;
% number of samples (i.e. size of the FFT)
N = frequencysmoothingfactor * smp;
% fundamental frequency
df = 1 / (N * dt);

% initialization of the positive frequency axis
positivefrequency=linspace(0,(fs/2),N/2); 
% initialization of the time axis
t=linspace(Tmin,Tmax,smp);

% loading the alpha vector depending on the input 'i'
alpha=cp0703_get_alpha_value(i);
% loading the emission mask on N points
emissionmask = cp0703_generate_mask(N, fs);

for i=1:15
    
% ---------------------------------------------
% Step One - Pulse waveforms in the time domain
% ---------------------------------------------
   
   % determination of the i-th derivative
   derivative(i,:) = cp0702_analytical_waveforms(t, i,...
      alpha(i));
	% amplitude normalization of the i-th derivative
   derivative(i,:) = derivative(i,:) / max(abs(derivative(i,:)));
end

for i=1:15

   % determination of coefficients for each single
   % derivative considered as a stand-alone set
   [i_th_derivative_coeff,validresult] = ...
      cp0703_random_coefficients(attempts, derivative,...
      dt, smp, Ts, frequencysmoothingfactor,...
      emissionmask, i, i);
   % application of coefficient to the i-th derivative
   normalizedderivative(i,:) = i_th_derivative_coeff(i)...
      * derivative(i,:);
   % recording coefficient for the function output
   singlederivativecoeff(i)= i_th_derivative_coeff(i);
   if(validresult)

% -----------------------------------------------------
% Step Two - Evaluation of PSDs of normalized waveforms
% -----------------------------------------------------

        % double-sided MATLAB amplitude spectrum
        X=fft(normalizedderivative(i,:),N);
        % conversion from MATLAB spectrum to Fourier
        % spectrum
        X=X/N;
        % double-sided ESD
        E = fftshift(abs(X).^2/(df^2));
        % single-sided ESD
        Ess = 2.*E((N/2+1):N);
        % PSD of the i-th normalized derivative in dBm/MHz
        singlederivativePSD(i,:) = 10 * log10 ((1/Ts)...
           * Ess / 377) + 90;           
   end
% end of section dedicated to mask fitting through single
% derivatives
end

% ---------------------------------------------------------
% Step Three - Evaluation of mask fitting combination of
% pulse waveforms
% ---------------------------------------------------------

[coefficients,validresult] = ...
   cp0703_random_coefficients(attempts, derivative,...
   dt, smp, Ts, frequencysmoothingfactor, ...
   emissionmask,1,15);
if(validresult)
    % double-sided MATLAB amplitude spectrum
    X=fft(coefficients*derivative,N);
    % conversion from MATLAB spectrum to Fourier spectrum
    X=X/N;
    % double-sided ESD
    E = fftshift(abs(X).^2/(df^2));
    % single-sided ESD
    Ess = 2.*E((N/2+1):N);
    % PSD of the combination in dBm/MHz
    PSD = 10 * log10 ((1/Ts) * Ess / 377) + 90; 

% ----------------------------
% Step Four - Graphical output
% ----------------------------

    figure(1);
    plot(positivefrequency/1e6,...
       emissionmask,'r','Linewidth',[1]);
    hold on;
    plot(positivefrequency/1e6, singlederivativePSD);
    PF = plot(positivefrequency/1e6, PSD);
    set(PF,'LineWidth',[2]);
    AX=gca;
    set(AX,'FontSize',12);
    T=title('Random combination');
    set(T,'FontSize',14);
    X=xlabel('Frequency [MHz]');
    set(X,'FontSize',14);
    Y=ylabel('PSD  [dBm/MHz]');
    set(Y,'FontSize',14);
    axis([0 12e3 -400 0]);
    alphavalue = '\alpha = 0.714 ns';
    text(8e3, -100, alphavalue,'BackgroundColor', [1 1 1]);
    text(2e3, -300,...
       'normalized derivatives','BackgroundColor',[1 1 1]);
    text(7e3, -150, 'random combination',...
       'BackgroundColor', [1 1 1]);
    text(5e3, -25, 'FCC UWB indoor emission mask',...
       'BackgroundColor', [1 1 1]);
end