www.gusucode.com > UWB_matlab源码程序 > CP0102/cp0102_sinpulse_one.m

    %
% FUNCTION 1.3 : "cp0102_sinpulse_one"
%
% Generates a pulse with length 'Tp',
% which is composed of 'Nc' cycles of a sinusoidal waveform 
% 'sinpulse' is the waveform representing the pulse
%
% Programmed by Guerino Giancola
%

function [sinpulse,dt]=cp0102_sinpulse_one

% ----------------------------
% Step Zero - Input parameters
% ----------------------------

Tp = 1e-8;           % pulse duration [s]
Nc = 8;              % number of cycles
A = 1;               % pulse amplitude [V]

smp = 1000;          % number of samples for representing the pulse

% --------------------------------------------
% Step One - Generation of the reference pulse
% --------------------------------------------

f = Nc / Tp;
p = sin(2.*pi.*f.*linspace(0,Tp,smp));

sinpulse = zeros(1,3*smp);  % The pulse is represented in the 
sinpulse(1+smp:2*smp) = p;  % center of a time window with length 
                            % 3*Tp

% -------------------------------------------
% Step Two - Analysis in the frequency domain
% -------------------------------------------

fs = smp / Tp;        % sampling frequency
dt = 1 / fs;          % sampling period
N = length(sinpulse); % number of samples (i.e. size of the FFT)
T = N * dt;           % time window
df = 1 / T;           % fundamental frequency

X=fft(sinpulse); % double-sided MATLAB amplitude spectrum
X=X/N;           % conversion from MATLAB spectrum to Fourier
                 %  spectrum
E = fftshift(abs(X).^2/(df^2));    % double-sided ESD

% -------------------------------
% Step Three - Output computation
% -------------------------------

fc = f;
fh = f + 1/Tp;
fl = f -1/Tp;
BW = 2/Tp;
FBW = 2*(fh-fl)/(fh+fl);

fprintf('\nCentral Frequency = %f [GHz]\nBandwidth = %f [GHz]\nFractional Bandwidth = %f\n\n',fc*1e-9,BW*1e-9,FBW);


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

F=figure(3);
set(F,'Position',[100 190 850 450]);

subplot(1,2,1);
time=linspace(-Tp,2*Tp,3*smp);
PT=plot(time,sinpulse);
set(PT,'LineWidth',[2]);
axis([-Tp 2*Tp -1.2*A 1.2*A]);
AX=gca;
set(AX,'FontSize',12);
T=title('Time domain');
set(T,'FontSize',14);
X=xlabel('Time [s]');
set(X,'FontSize',14);
Y=ylabel('Amplitude [V]');
set(Y,'FontSize',14);

subplot(1,2,2)
frequency=linspace(-(fs/2),(fs/2),N);
PF=plot(frequency,E);
set(PF,'LineWidth',[2]);
L1=line([fh fh],[0 max(E)]);
set(L1,'Color',[0 0 0],'LineStyle',':')
L1=line([fl fl],[0 max(E)]);
set(L1,'Color',[0 0 0],'LineStyle',':')
L1=line([-fh -fh],[0 max(E)]);
set(L1,'Color',[0 0 0],'LineStyle',':')
L1=line([-fl -fl],[0 max(E)]);
set(L1,'Color',[0 0 0],'LineStyle',':')
fref=f+(5/Tp);
axis([-fref fref -(0.1*max(E)) 1.1*max(E)]);
AX=gca;
set(AX,'FontSize',12);
T=title('Frequency domain');
set(T,'FontSize',14);
X=xlabel('Frequency [Hz]');
set(X,'FontSize',14);
Y=ylabel('ESD  [V^2s/Hz]');
set(Y,'FontSize',14);