📄 uwb_trx.m
字号:
%================================================
%UWB BPSK SYSTEM
%================================================
clear
Fs=100e9; %sample frequency
Fn=Fs/2; %Nyquist frequency
t=-.3e-9:1/Fs:45e-9; %Sets the Entire Freq. Range
%================================================
%PULSE GENERATION
%================================================
pw=100e-12; %Sets value for the pulse width: 600ps
y=((60./pw.^5).*(t-0).*exp(-(t-0).^2./pw.^2)-(80./pw.^7).*(t-0).^3.*exp(-(t-0).^2./pw.^2)+ ...
(16.*(t-0).^5./pw.^9.*exp(-(t-0).^2/pw.^2)));%Fifth derivative of Gaussian pulse.(5 zero crossings)
plot(y);
%================================================
%NOISE SETUP FOR BER AND SNR
%================================================
noise=(1e-50)*(randn(size(t)));%(Noise-AWGN)Set to 1e-50 to disable
%===========================================================
%BPSK PULSE SEQUENCE GENERATION - 9 Pulses with 200MHz PRF
%===========================================================
A=.6e-45; %Sets voltage level out of TX or input to mixer(.6e-45 for .3mv volt peak)
yp=A*y+ ...
-A*((60./pw.^5).*(t-5e-9).*exp(-(t-5e-9).^2./pw.^2)-(80./pw.^7).*(t-5e-9).^3.*exp(-(t-5e-9).^2./pw.^2)+ ...
(16.*(t-5e-9).^5./pw.^9.*exp(-(t-5e-9).^2/pw.^2)))+ ...
A*((60./pw.^5).*(t-10e-9).*exp(-(t-10e-9).^2./pw.^2)-(80./pw.^7).*(t-10e-9).^3.*exp(-(t-10e-9).^2./pw.^2)+ ...
(16.*(t-10e-9).^5./pw.^9.*exp(-(t-10e-9).^2/pw.^2)))+ ...
-A*((60./pw.^5).*(t-15e-9).*exp(-(t-15e-9).^2./pw.^2)-(80./pw.^7).*(t-15e-9).^3.*exp(-(t-15e-9).^2./pw.^2)+ ...
(16.*(t-15e-9).^5./pw.^9.*exp(-(t-15e-9).^2/pw.^2)))+ ...
A*((60./pw.^5).*(t-20e-9).*exp(-(t-20e-9).^2./pw.^2)-(80./pw.^7).*(t-20e-9).^3.*exp(-(t-20e-9).^2./pw.^2)+ ...
(16.*(t-20e-9).^5./pw.^9.*exp(-(t-20e-9).^2/pw.^2)))+ ...
-A*((60./pw.^5).*(t-25e-9).*exp(-(t-25e-9).^2./pw.^2)-(80./pw.^7).*(t-25e-9).^3.*exp(-(t-25e-9).^2./pw.^2)+ ...
(16.*(t-25e-9).^5./pw.^9.*exp(-(t-25e-9).^2/pw.^2)))+ ...
A*((60./pw.^5).*(t-30e-9).*exp(-(t-30e-9).^2./pw.^2)-(80./pw.^7).*(t-30e-9).^3.*exp(-(t-30e-9).^2./pw.^2)+ ...
(16.*(t-30e-9).^5./pw.^9.*exp(-(t-30e-9).^2/pw.^2)))+ ...
-A*((60./pw.^5).*(t-35e-9).*exp(-(t-35e-9).^2./pw.^2)-(80./pw.^7).*(t-35e-9).^3.*exp(-(t-35e-9).^2./pw.^2)+ ...
(16.*(t-35e-9).^5./pw.^9.*exp(-(t-35e-9).^2/pw.^2)))+ ...
A*((60./pw.^5).*(t-40e-9).*exp(-(t-40e-9).^2./pw.^2)-(80./pw.^7).*(t-40e-9).^3.*exp(-(t-40e-9).^2./pw.^2)+ ...
(16.*(t-40e-9).^5./pw.^9.*exp(-(t-40e-9).^2/pw.^2)));
%===========================================================
%TEMPLATE SEQUENCE GENERATION FOR CORRELATION IN RX SIDE
%===========================================================
B=.6e-45; %Sets voltage level out of TX or input to mixer(.6e-45 for .3mv volt peak)
yum=B*y+ ...
B*((60./pw.^5).*(t-5e-9).*exp(-(t-5e-9).^2./pw.^2)-(80./pw.^7).*(t-5e-9).^3.*exp(-(t-5e-9).^2./pw.^2)+ ...
(16.*(t-5e-9).^5./pw.^9.*exp(-(t-5e-9).^2/pw.^2)))+ ...
B*((60./pw.^5).*(t-10e-9).*exp(-(t-10e-9).^2./pw.^2)-(80./pw.^7).*(t-10e-9).^3.*exp(-(t-10e-9).^2./pw.^2)+ ...
(16.*(t-10e-9).^5./pw.^9.*exp(-(t-10e-9).^2/pw.^2)))+ ...
B*((60./pw.^5).*(t-15e-9).*exp(-(t-15e-9).^2./pw.^2)-(80./pw.^7).*(t-15e-9).^3.*exp(-(t-15e-9).^2./pw.^2)+ ...
(16.*(t-15e-9).^5./pw.^9.*exp(-(t-15e-9).^2/pw.^2)))+ ...
B*((60./pw.^5).*(t-20e-9).*exp(-(t-20e-9).^2./pw.^2)-(80./pw.^7).*(t-20e-9).^3.*exp(-(t-20e-9).^2./pw.^2)+ ...
(16.*(t-20e-9).^5./pw.^9.*exp(-(t-20e-9).^2/pw.^2)))+ ...
B*((60./pw.^5).*(t-25e-9).*exp(-(t-25e-9).^2./pw.^2)-(80./pw.^7).*(t-25e-9).^3.*exp(-(t-25e-9).^2./pw.^2)+ ...
(16.*(t-25e-9).^5./pw.^9.*exp(-(t-25e-9).^2/pw.^2)))+ ...
B*((60./pw.^5).*(t-30e-9).*exp(-(t-30e-9).^2./pw.^2)-(80./pw.^7).*(t-30e-9).^3.*exp(-(t-30e-9).^2./pw.^2)+ ...
(16.*(t-30e-9).^5./pw.^9.*exp(-(t-30e-9).^2/pw.^2)))+ ...
B*((60./pw.^5).*(t-35e-9).*exp(-(t-35e-9).^2./pw.^2)-(80./pw.^7).*(t-35e-9).^3.*exp(-(t-35e-9).^2./pw.^2)+ ...
(16.*(t-35e-9).^5./pw.^9.*exp(-(t-35e-9).^2/pw.^2)))+ ...
B*((60./pw.^5).*(t-40e-9).*exp(-(t-40e-9).^2./pw.^2)-(80./pw.^7).*(t-40e-9).^3.*exp(-(t-40e-9).^2./pw.^2)+ ...
(16.*(t-40e-9).^5./pw.^9.*exp(-(t-40e-9).^2/pw.^2)));
ym=yp+noise; %BPSK modulated fifth with noise
yc=ym.*yum;%yc(correlated output)=ym(modulated)times yum(unmodulated) fifth.
%This is where the correlation occurs in the receiver and would be the
%mixer in the receiver.
%==================================================
% FFT
%==================================================
%FFT for BPSK modulated fifth(ym)
NFFYM=2.^(ceil(log(length(ym))/log(2)));
FFTYM=fft(ym,NFFYM);%pad with zeros
NumUniquePts=ceil((NFFYM+1)/2);
FFTYM=FFTYM(1:NumUniquePts);
MYM=abs(FFTYM);
MYM=MYM*2;
MYM(1)=MYM(1)/2;
MYM(length(MYM))=MYM(length(MYM))/2;
MYM=MYM/length(ym);
f=(0:NumUniquePts-1)*2*Fn/NFFYM;
%FFT for unmodulated fifth(yum)
NFFYUM=2.^(ceil(log(length(yum))/log(2)));
FFTYUM=fft(yum,NFFYUM);%pad with zeros
NumUniquePts=ceil((NFFYUM+1)/2);
FFTYUM=FFTYUM(1:NumUniquePts);
MYUM=abs(FFTYUM);
MYUM=MYUM*2;
MYUM(1)=MYUM(1)/2;
MYUM(length(MYUM))=MYUM(length(MYUM))/2;
MYUM=MYUM/length(yum);
f=(0:NumUniquePts-1)*2*Fn/NFFYUM;
%FFT for correlated pulses(yc)
%yc is the time domain signal output of the multiplier
%(modulated times unmodulated) in the correlation receiver.
NFFYC=2.^(ceil(log(length(yc))/log(2)));
FFTYC=fft(yc,NFFYC);%pad with zeros
NumUniquePts=ceil((NFFYC+1)/2);
FFTYC=FFTYC(1:NumUniquePts);
MYC=abs(FFTYC);
MYC=MYC*2;
MYC(1)=MYC(1)/2;
MYC(length(MYC))=MYC(length(MYC))/2;
MYC=MYC/length(yc);
f=(0:NumUniquePts-1)*2*Fn/NFFYC;
%===================================================
% PLOTS
%===================================================
%plots for modulated fifth(ym)
figure(1)
subplot(2,2,1); plot(t,ym);xlabel('TIME');ylabel('AMPLITUDE');
title('Modulated pulse train');
grid on;
%axis([-1e-9,27e-9 -1 2])
subplot(2,2,2); plot(f,MYM);xlabel('FREQUENCY');ylabel('AMPLITUDE');
%axis([0 20e9 0 .0001]);%zoom in/out
grid on;
subplot(2,2,3); plot(f,10*log10(abs(MYM).^2));xlabel('FREQUENCY');ylabel('PSD');%PSD shown here
%axis([0 12e9 -20 5]);
grid on;
%===================================================
%plots for unmodulated fifth(yum)
figure(2)
subplot(2,2,1); plot(t,yum);xlabel('TIME');ylabel('AMPLITUDE');
title('Template pulse train');
grid on;
%axis([-1e-9,27e-9 -1 1])
subplot(2,2,2); plot(f,MYUM);xlabel('FREQUENCY');ylabel('AMPLITUDE');
%axis([0 10e9 0 .1]);%zoom in/out
grid on;
subplot(2,2,3); plot(f,20*log10(MYUM));xlabel('FREQUENCY');ylabel('20LOG10=DB');
%axis([0 20e9 -120 0]);
grid on;
%====================================================
%plots for correlated pulses(yc)
figure(3)
subplot(2,2,1); plot(t,yc);xlabel('TIME');ylabel('AMPLITUDE');
title('Receiver correlator output-no LPF');
grid on;
%axis([-1e-9,27e-9 -1 1])
subplot(2,2,2); plot(f,MYC);xlabel('FREQUENCY');ylabel('AMPLITUDE');
%axis([0 7e9 0 .025]);%zoom in/out
grid on;
subplot(2,2,3); plot(f,20*log10(MYC));xlabel('FREQUENCY');ylabel('20LOG10=DB');
%axis([0 20e9 -120 0]);
grid on;
%===========================================================
%CORRELATION RECEIVER COMPARATOR(before lowpass filter)
%===========================================================
pt=.1e-8 %sets level where threshhold device comparator triggers
H=5;%(volts)
L=0;%(volts)
LEN=length(yc);
for ii=1:LEN;
if yc(ii)>=pt; %correlated output(yc) going above pt threshold setting
pv(ii)=H; %pulse voltage
else;
pv(ii)=L;
end;
end ;
po=pv; %pulse out=pulse voltage
%figure(3)
subplot(2,2,4);
plot(t,po);
axis([-1e-9 27e-9 -1 6])
title('Comparator output');
xlabel('Frequency');
ylabel('Voltage');
grid on;
%===================================================================
% CORRELATION RECEIVER LOW PASS FILTER(INTEGRATOR)
%===================================================================
rc=.5e-9;%time constant
ht=(1/rc).*exp(-t/rc);%impulse response
ycfo=filter(yc,1,ht)/Fs;%use this instead of ycfo=conv(yc,ht)/Fs for proper dimension.
%The #=1 allows this. The LPF RC time constant(integrates over this time).
%Theory states that it should be set to the pulse width but should be set
%to a value that gives the best error free operation at the highest noise
%levels. Different filter types(butterworth,etc) may give different
%results.I don't have the butter function.
%The 3DB or 1/2 power bandwidth on the RC LPF is f=1/(2*pi*RC). The noise
%bandwith is f=1/(4*rc).
yn=filter(noise,1,ht)/Fs;%looks at filtered noise only(Figure 5)
%new FFT for filtered correlated pulses(ycfo)
NFFYCFO=2.^(ceil(log(length(ycfo))/log(2)));
FFTYCFO=fft(ycfo,NFFYCFO);%pad with zeros
NumUniquePts=ceil((NFFYCFO+1)/2);
FFTYCFO=FFTYCFO(1:NumUniquePts);
MYCFO=abs(FFTYCFO);
MYCFO=MYCFO*2;
MYCFO(1)=MYCFO(1)/2;
MYCFO(length(MYCFO))=MYCFO(length(MYCFO))/2;
MYCFO=MYCFO/length(ycfo);
f=(0:NumUniquePts-1)*2*Fn/NFFYCFO;
%new FFT for filtered noise(yn)
NFFYN=2.^(ceil(log(length(yn))/log(2)));
FFTYN=fft(yn,NFFYN);%pad with zeros
NumUniquePts=ceil((NFFYN+1)/2);
FFTYN=FFTYN(1:NumUniquePts);
MYN=abs(FFTYN);
MYN=MYN*2;
MYN(1)=MYN(1)/2;
MYN(length(MYN))=MYN(length(MYN))/2;
MYN=MYN/length(yn);
f=(0:NumUniquePts-1)*2*Fn/NFFYN;
%plots for filtered correlated pulses(ycfo)
figure(4)
subplot(2,2,1); plot(t,ycfo);xlabel('TIME');ylabel('AMPLITUDE');
title('Receiver filtered correlator output');
grid on;
%axis([-1e-9,27e-9 -1 1])
subplot(2,2,2); plot(f,MYCFO);xlabel('FREQUENCY');ylabel('AMPLITUDE');
%axis([0 7e9 0 .25]);%zoom in/out
grid on;
subplot(2,2,3); plot(f,20*log10(MYCFO));xlabel('FREQUENCY');ylabel('20LOG10=DB');
%axis([0 20e9 -120 0]);
grid on;
%=========================================================
% CORRELATION RECEIVER COMPARATOR(after low pass filter)
%=========================================================
pt1=.1e-8%sets level where threshhold device comparator triggers
H=5;%(volts)
L=0;%(volts)
LEN=length(ycfo);
for ii=1:LEN;
if ycfo(ii)>=pt1;%correlated output(ycfo) going above pt threshold setting
pv1(ii)=H;%pulse voltage
else;
pv1(ii)=L;
end;
end ;
po1=pv1;%pulse out=pulse voltage
%figure(4)
subplot(2,2,4);
plot(t,po1);
%axis([-1e-9 50e-9 -1 6])
title('Comparator output');
xlabel('Frequency');
ylabel('Voltage');
grid on;
%plots for filtered noise(yn)
figure(5)
subplot(2,2,1);plot(t,yn);xlabel('TIME');ylabel('AMPLITUDE');
title('Receiver filtered noise output');
grid on;
%axis([-1e-9,27e-9 -1 1])
subplot(2,2,2); plot(f,MYN);xlabel('FREQUENCY');ylabel('AMPLITUDE');
%axis([0 7e9 0 .25]);%zoom in/out
grid on;
subplot(2,2,3); plot(f,20*log10(MYN));xlabel('FREQUENCY');ylabel('20LOG10=DB');
%axis([0 20e9 -120 0]);
grid on;
subplot(2,2,4);plot(t,ht);xlabel('TIME');ylabel('AMPLITUDE');
title('impulse response(ht)');
grid on;
%axis([0,1e-9 0 1])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -