www.gusucode.com > UWB_matlab源码程序 > CP0101/cp0101_genrect.m

    %
% FUNCTION 1.1 : "cp0101_genrect"
%
% Generates a unitary amplitude rectangular waveform
% that is modulated by a sinusoid at frequency 'f0'
% 'signal' is the output waveform
% 'dt' is the sampling period
% 
% Programmed by Guerino Giancola
% 

function [signal,dt] = cp0101_genrect

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

width = 1e-1;      % width of the rectangle [s]
points = 1000;     % number of samples for representing the rectangle  

f0 = 0;            % carrier frequency [Hz] 

% ----------------------------
% Step One - Output evaluation
% ----------------------------

dt = width / points;       % sampling period
signal = zeros(1,5*points);
signal(2*points:3*points-1)=ones(1,points);

mod=cos(2.*pi.*f0.*linspace(1,5*width,5*points));
signal=signal.*mod;


% ---------------------------
% Step Two - Graphical output
% ---------------------------

figure(1)
time=linspace(-2*width,3*width,5*points);
P1=plot(time,signal);
set(P1,'LineWidth',[2]);
axis([-2*width 3*width -1.2 1.2]);
AX=gca;
set(AX,'FontSize',12);
X=xlabel('Time [s]');
set(X,'FontSize',14);
Y=ylabel('Amplitude [V]');
set(Y,'FontSize',14);