📄 ofdm-uwb信号经awgn信道.asv
字号:
%
% FUNCTION 2.11 : "cp0203_OFDM_qpsk"
%
% Simulation of a transmitter implementing
% the OFDM transmission chain with QPSK modulation
% on each sub-carrier
%
% 'numbits' is the number of bits generated by the source
% 'fp' is the carrier frequency of the generated signal
% 'fc' is the sampling frequency
% 'T0' is the block length in [s], i.e., 1/T0 is the carrier
% separation
% 'TP' is the length of the cyclic prefix [s]
% 'TG' is guard time
% 'A' is the amplitude of the rectangular impulse response
% [V]
% 'N' is the number of carriers (tones) used in the OFDM
% system
%
% The function returns:
% 1) the generated stream of bits ('bits')
% 2) the corresponding stream of QPSK symbols ('S')
% 3) the I component of the generated signal ('SI')
% 4) the Q component of the generated signal ('SQ')
% 5) the generated OFDM signal ('Stx')
% 6) the value of the sampling frequency ('fc')
% 7) the value of the carrier frequency ('fp')
% 8)9)10) the values of T0, TP, and TG
% 11) the number of tones used for transmission
%
% Programmed by Guerino Giancola
%
% function [bits,S,SI,SQ,mb01,fc,fp,T0,TP,TG,N] = ...
% cp0203_OFDM_qpsk;
% ----------------------------
% Step Zero - Input parameters
function [mb01] = ...
numbits = 4096; % number of bits to be transmitted
fp = 3.432e9; % central frequency
fc = 50e9; % sampling frequency
T0 = 242.4e-9; % information length
TP = 60.6e-9; % cyclic prefix
TG = 70.1e-9; % total guard time
A = 1; % amplitude of the rectangular impulse
% response
N = 128; % number of carriers of the OFDM
% system
% -------------------------
% Step One - OFDM modulator
% -------------------------
tc = T0 / N; % chip time
ntcp = floor(TP/tc); % number of tones of the cyclic
% prefix
n = (-ntcp+1:1:N); % tone counter
NT = length(n); % total number of tones per symbol
% Bit generation
[bits] = cp0201_bits(numbits);
% QPSK modulator
[S,Sc,Ss] = cp0203_qpsk_mod(bits);
% OFDM modulator
nb = ceil(length(S)/N); % number of OFDM blocks to be
% transmitted
S0 = zeros(1,nb*N); % zero padding
S0(1:length(S))=S;
dt = 1 / fc; % sampling period
if ntcp>0
tc = (T0+TP)/NT; % tone duration
end
tonesamples = floor(tc/dt); % samples per tone
toneres = floor((TG-TP)/dt); % samples for the residual
% part
symsamp = (tonesamples*NT)+toneres;
% number of samples representing one OFDM symbol
totsamp = symsamp * nb;
% number of samples representing the transmitted signal
X = [zeros(1,totsamp)'];
for b = 1 : nb
c = S0((1+(b-1)*N):(N+(b-1)*N)); % block extraction抽取
% Serial to Parallel conversion and zero padding填零
A = length(c);
a1 = floor(A/2);
a2 = A - a1;
FS = 2*A;
Czp=zeros(FS,1);
Czp(1:a1)=[c(1:a1).'];
Czp(FS-a2+1:FS)=[c(A-a2+1:A).'];
C = ifft(Czp); % IFFT of the zero-padded input
if ntcp>0 % insertion of the cyclic prefix
C1=zeros(length(C)+2*ntcp,1);
C1(1:(2*ntcp))=C(2*N+1-(2*ntcp):2*N);
C1(2*ntcp+1:length(C1))=C;
else
C1=C;
end
%
zp = floor(tonesamples/2);
C2 = [C1.';zeros((zp-1),length(C1))];
C3 = C2(:);
g = ones(1,zp);
C4 = conv(g,C3);
C4 = C4(1:(zp*NT*2));
ics = 1 + (b-1)*symsamp + toneres;
X(ics:ics+length(C4)-1)=C4;
end % for b = 1 : nb
XM = X'; % Parallel to Serial conversion
XM = XM(1:totsamp);
I = real(XM);
Q = imag(XM);
% carrier modulation
time = linspace(0,totsamp*dt,length(I));
SI = I.*(cos((2*pi*fp).*time));
SQ = Q.*(sin((2*pi*fp).*time));
mb01 = SI - SQ;
%
% FUNCTION 3.2 : "cp0301_PSD"
%
% Evaluates the PSD of the
% signal represented by the input vector 'x'
% The input signal is sampled with frequency 'fc'
%
% This function returns the PSD ('PSD')
% and the corresponding frequency resolution ('df')
%
% Programmed by Guerino Giancola
%
% function [PSDmb01,df]=cp0301_PSD(mb01,fc)
% --------------------------------
% Step One - Evaluation of the PSD
% --------------------------------
dt=1/fc;
N=length(mb01);
T=N*dt;
df=1/T;
X = fft(mb01);
X = X / N;
mPSD=abs(X).^2/(df^2);
PSD = fftshift(mPSD);
PSD = (1/T).*PSD;
% -----------------------------------
% Step Two - Graphical representation
% -----------------------------------
frequency = linspace(-fc/2,fc/2,length(PSD));
PF=plot(frequency,PSD);
set(PF,'LineWidth',[2]);
AX=gca;
set(AX,'FontSize',12);
X=xlabel('Frequency [Hz]');
set(X,'FontSize',14);
Y=ylabel('Power Spectral Density [V^2/Hz]');
set(Y,'FontSize',14);
axis([2.5e9,4.5e9,0,7e-12]);
%
% FUNCTION 8.2 : "cp0801_Gnoise1"
%
% Introduces additive white Gaussian noise over signal
% 'input'.
% Vector 'ebno' contains the target values of Eb/No (in dB)
% 'numbits' is the number of bits conveyed by the input
% signal
%
% Multiple output signals are generated, one signal for
% each target value of Eb/No. The array 'output' contains
% all the signals (input+AWGN), one signal per row.
% The array 'noise' contains the different realization of
% the Gaussian noise, one realization per each row
%
% Programmed by Guerino Giancola
%
%************************
%cm1信道输出的信号矢量rx被加上高斯白躁声,得到经过信道的输出信号
%即cp0801_Gnoise1(input,ebno,numbits)返回的output
tx=mb01;
c0=10^(-47/20); %运用公式G0=10^(-A0/10),G0即此的c0,为d=1m时参考功率增益
d=2; %cm1(0~4m),选择2m的距离
gamma=1.7; %A0=47db,对应gamma=1.7
[rx,attn] = cp0801_pathloss(tx,c0,d,gamma) %函数调用,先确定该函数的输入参数
%attn为信道增益,rx衰减后的信号矢量
input=rx;
ebno=[0 2 4 6 8 10];%主要考虑适用各种不同的Eb/No值
numbits = 4096;
% function [output,noise] = ...
% cp0801_Gnoise1(input,ebno,numbits)
% -------------------------------
% Step One - Introduction of AWGN
% -------------------------------
Eb = (1/numbits)*sum(input.^2); % measured energy per bit
EbNo = 10.^(ebno./10); % Eb/No in linear unit
No = Eb ./ EbNo; % Unilateral spectral
% density
nstdv = sqrt(No./2); % Standard deviation for
% the noise
for j = 1 : length(EbNo)
noise(j,:) = nstdv(j) .* randn(1,length(input));
output(j,:) = noise(j,:) + input;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -