📄 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -