📄 gensinpulse.m
字号:
%function gensinpulse 产生固有时间宽度的正弦脉冲
%tp 脉冲宽度
%nc 正弦波的个数
%a 脉冲幅度
%smp 脉冲采样点数
%sinpulse 输出波形
%dt 采样周期
function [sinpulse,dt]=gensinpulse(tp,nc,a,smp)
%step1 generation of the reference pulse
f=nc/tp; %正弦波频率
p=sin(2.*pi.*f.*linspace(0,tp,smp));
sinpulse=zeros(1,3*smp);
sinpulse(1+smp:2*smp)=p; %产生波形
%step2 analysis in the frequency domain
fs=smp/tp; %抽样频率
dt=1/fs; %采样周期
n=length(sinpulse);
t=n*dt;
df=1/t;
x=fft(sinpulse);
x=x/n;
e=fftshift(abs(x).^2/(df^2)); %双边功率谱
%step3 输出文字
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);
%step4 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -