📄 pamthuwbpsd.m
字号:
function [bits,THcode,Stx,ref]=cp0402_transmitter_2PAM_TH
Pow=-30;
fc=50e9;
numbits=3;
Ts=5e-9;
Ns=5;
Tc=1e-9;
Nh=5;
Np=5;
Tm=0.5e-9;
tau=0.25e-9;
G=1;
bits=rand(1,numbits)>0.5;
numbits=length(bits);
temprect=ones(1,Ns);
temp1=zeros(1,numbits*Ns);
temp1(1:Ns:1+Ns*(numbits-1))=bits;
temp2=conv(temp1,temprect);
repbits=temp2(1:Ns*numbits);
THcode=floor(rand(1,Np).*Nh);
dt=1./fc;
framesamples=floor(Ts./dt);
chipsamples=floor(Tc./dt);
THp=length(THcode);
totlength=framesamples*length(repbits);
PAMTHseq=zeros(1,totlength);
THseq=zeros(1,totlength);
for k=1:length(repbits)
index=1+(k-1)*framesamples;
kTH=THcode(1+mod(k-1,THp));
index=index+kTH*chipsamples;
THseq(index)=1;
PAMTHseq(index)=((repbits(k)*2)-1);
end
power=(10^(Pow/10))/1000;
Ex=power*Ts;
dt=1/fc;
OVER=floor(Tm/dt);
e=mod(OVER,2);
kbk=floor(OVER/2);
tmp=linspace(dt,Tm/2,kbk);
s=(1-4.*pi*((tmp./tau).^2)).*exp(-2.*pi.*((tmp./tau).^2));
if e
for k=1:length(s)
y(kbk+1)=1;
y(kbk+1+k)=s(k);
y(kbk+1-k)=s(k);
end
else
for k=1:length(s)
y(kbk+k)=s(k);
y(kbk+1-k)=s(k);
end
end
E=sum((y.^2).*dt);
w0=y./(E^0.5)+sin(2.*pi.*5e10.*tmp);
wtx=w0.*sqrt(Ex);
Sa=conv(PAMTHseq,wtx);
Sb=conv(THseq,wtx);
L=(floor(Ts*fc))*Ns*numbits;
Stx=Sa(1:L);
ref=Sb(1:L);
if G
F=figure(1);
set(F,'Position',[32 223 951 420]);
tmax=numbits*Ns*Ts;
time=linspace(0,tmax,length(Stx));
P=plot(time,Stx);
set(P,'LineWidth',[2]);
ylow=-1.5*max(wtx);
yhigh=1.5*max(wtx);
axis([0 tmax ylow yhigh]);
AX=gca;
set(AX,'FontSize',12);
X=xlabel('时间 [s]');
set(X,'FontSize',14);
Y=ylabel('幅度 [V]');
set(Y,'FontSize',14);
for j=1:numbits
tj=(j-1)*Ns*Ts;
L1=line([tj tj],[ylow yhigh]);
set(L1,'Color',[0 0 0],'LineStyle','--','LineWidth',[2]);
for k=0:Ns-1
if k>0
tn=tj+k*Nh*Tc;
L2=line([tn tn],[ylow yhigh]);
set(L2,'Color',[0.5 0.5 0.5],'LineStyle','-.','LIneWidth',[2]);
end
for q=1:Nh-1
th=tj+k*Nh*Tc+q*Tc;
L3=line([th th],[0.8*ylow 0.8*yhigh]);
set(L3,'Color',[0 0 0],'LineStyle',':','LIneWidth',[1]);
end
end
end
end
hold on
figure(2)
dt=1/fc;
N=length(Stx);
T=N*dt;
df=1/T;
X=fft(Stx);
X=X/N;
mPSD=abs(X).^2/(df^2);
PSD=fftshift(mPSD);
PSD=(1/T).*PSD;
frequency=linspace(-fc/2,fc/2,length(PSD));
PF=plot(frequency,PSD);
set(PF,'LineWidth',[2]);
AX=gca;
set(AX,'FontSize',12);
X=xlabel('频率 [Hz]');
set(X,'FontSize',14);
Y=ylabel('功率谱密度 [V^2/Hz]');
set(Y,'FontSize',14);
axis([0 10e9 0 1.2e-15]);
hold on
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -