?? transmitter_tr_th_2ppm.m
字號:
%產生TR-PPM調制信號!!!!!
% FUNCTION 2.6 : "cp0201_transmitter_2PPM_TH"
%
% Simulation of a UWB transmitter implementing 2PPM with TH
%
% Transmitted Power is fixed to 'Pow'.
% The signal is sampled with frequency 'fc'.
% 'numbits' is the number of bits generated by the source.
% 'Ns' pulses are generated for each bit, and these pulses
% are spaced in time by an average pulse repetition period
% 'Ts'.
% The TH code has periodicity 'Np', and cardinality 'Nh'.
% The chip time has time duration 'Tc'.
% Each pulse has time duration 'Tm' and shaping factor
% 'tau'.
% The PPM introduces a time shift of 'dPPM'.
%
% The function returns:
% 1) the generated stream of bits ('bits')
% 2) the generated TH code ('THcode')
% 3) the generated signal ('Stx')
% 4) a reference signal without data modulation ('ref')
%
function [Stx]=transmitter_TR_TH_2PPM
%function [bits]=transmitter_TR_2PPM
% ----------------------------
% Step Zero - Input Parameters
% ----------------------------
%Pow = -30; % Average transmitted power (dBm)
%功率為1w
fc = 50e9; % sampling frequency
numbits = 2000; % number of bits generated by the source
% number of sequence generated is 2*numbits
Ts = 40e-9; % frame time, i.e. average bit period [s]
Tf = 4e-9; % average pulse repetition period [s]
Ns = 10; % 數據脈沖與參考脈沖的總個數
Nr = 4; % 參考脈沖的總個數
Nd = Ns-Nr; % 數據脈沖的總個數
Tc = 1e-9; % 數據脈沖相比參考脈沖的延遲 [s]
Tm = 0.5e-9; % pulse duration [s]
tau = 0.25e-9; % shaping factor for the pulse [s]
dPPM = 0.5e-9; % time shift introduced by the PPM [s]
G = 1;
% G=0 -> no graphical output
% G=1 -> graphical output
% ----------------------------------------
% Step One - Simulating Transmission Chain
% ----------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%% binary source
sequence = zeros(1,Ns*numbits);
bits = rand(1,numbits)>0.5;
%figure;
%plot(bits);
for i = Nr+1:Ns
sequence(i:Ns:Ns*numbits) = bits;
end%在每個bit前加入Nr個0,相當于Nr個參考脈沖;每個bit重復Ns-Nr次
pn = floor(rand(1,Nd).*3);%TH Code--0 1 2
%figure;
%plot(pn);
%%%%%%%%%%%%%%%%%% Pulse Position Modulation + TH%%%%%%%%%%%%%%%%
dt = 1 ./ fc; % sampling period
framesamples = floor(Ts./dt); % no. of samples between bits
pulsesamples = floor(Tf./dt); % no. of samples between pulses
thcodesamples = floor(Tc./dt); % no. of samples of Tc
PPMsamples = floor (dPPM./dt); % no. of samples for the
% PPM shift
totlength = framesamples*numbits;
TR_THPPMseq=zeros(1,totlength);
% ------------------------------------------------
% Step Two - main loop for introducing TH and 2PPM
% ------------------------------------------------
for k = 1 : Ns*numbits
if mod(k,Ns)<=Nr
if mod(k,Ns)>0
index = 1 + (k-1)*pulsesamples;
else
index = 1 + (k-1)*pulsesamples + pn(Ns-Nr)*thcodesamples + sequence(k)*PPMsamples;
end
else
index = 1 + (k-1)*pulsesamples + pn(mod(k,Ns)-Nr)*thcodesamples + sequence(k)*PPMsamples;
end
TR_THPPMseq(index) = 1;
end % for k = 1 : 2*numbits
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Shaping filter
power = 1;%(10^(Pow/10))/1000; % average transmitted power
% (watt)
Ex = power * Ts; % energy per pulse
w0 = cp0201_waveform(fc,Tm,tau);% Energy Normalized pulse
% waveform
wtx = w0 .* sqrt(Ex); % pulse waveform
Sa = conv(TR_THPPMseq,wtx); % Output of the filter
% (with modulation)
% Output generation
L = (floor(Ts*fc))*numbits;
%%%%%%%%%%%%%%%%%%%%%%%%%%%采樣數值
Stx = Sa(1:L);
% ---------------------------
% Step Two - Graphical Output
% ---------------------------
if G
F = figure(1);
set(F,'Position',[32 223 951 420]);
tmax = numbits*Ts;
time = linspace(0,tmax,length(Stx));
P = plot(time,Stx);
set(P,'LineWidth',[2]);
ylow=-1.5*abs(min(wtx));
yhigh=1.5*max(wtx);
axis([0 tmax ylow yhigh]);
AX=gca;
set(AX,'FontSize',12);
X=xlabel('Time [s]');
set(X,'FontSize',14);
Y=ylabel('Amplitude [V]');
set(Y,'FontSize',14);
end % end of graphical output
figure;
plot(bits);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -