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

    %
% FUNCTION 1.4 : "cp0102_sinpulse_two"
%
% Generates a pulse composed of 'Nc' cycles of a sinusoidal waveform
% with fixed frequency 'Fp'
%
% Programmed by Guerino Giancola
%

function [sinpulse,dt]=cp0102_sinpulse_two

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

Fp = 8e8;          % frequency of the sinusoid [Hz]
Nc = 8;            % number of cycles composing the pulse
A = 1;             % pulse amplitude [V]

smp = 1000;        % number of samples for representing each cycle

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

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

sinpulse=zeros(1,3*Nc*smp);   % the pulse is represented in the center
sinpulse(1+Nc*smp:2*Nc*smp)=p;% of a time window with length 3*Nc*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 = Fp;
fh = Fp + 1/(Nc*Tp);
fl = Fp - 1/(Nc*Tp);
BW = 2/(Nc*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(4);
set(F,'Position',[100 190 850 450]);

subplot(1,2,1);
time=linspace(-Tp*Nc,2*Tp*Nc,3*Nc*smp);
PT=plot(time,sinpulse);
set(PT,'LineWidth',[2]);
axis([-Tp*Nc 2*Tp*Nc -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=Fp+(5/(Nc*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);