⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ofdm代码.txt

📁 Simulation of a transmitter implementingthe OFDM transmission chain with QPSK modulation on each su
💻 TXT
字号:
%
% FUNCTION 2.10 : "cp0203_qpsk_mod"
%
% This function receives a binary stream in input ('bits')
% and returns the corresponding sequence of QPSK symbols
%  ('S'),
% plus the two sequences 'Sc' and 'Ss' containing the real
% and imaginary part of each symbol
%
% Programmed by Guerino Giancola
%
function [S,Sc,Ss] = cp0203_qpsk_mod(bits)
nb = length(bits);      % number of bits
ns = ceil(nb/2);        % number of symbols
b0 = zeros(1,ns*2);     % zero padding
b0(1:nb) = bits;
j = sqrt(-1);
for s = 1 : ns

    ba = b0(((s-1)*2)+1);
    bb = b0(((s-1)*2)+2);
    k = bb + ba*2;
    p = ((pi/4)*(2*k-1))-pi;

    Sc(s) = cos(p);
    Ss(s) = sin(p);
    S(s) = Sc(s) + j*Ss(s);

end
%
% 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,Stx,fc,fp,T0,TP,TG,N] = ...
   cp0203_OFDM_qpsk;
% ----------------------------
% Step Zero - Input parameters
% ----------------------------

numbits = 1024;      % number of bits to be transmitted
fp = 1e9;            % 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=rand(1,numbits)>0.5;
% 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
     % Serial to Parallel conversion and zero padding
    c = S0((1+(b-1)*N):(N+(b-1)*N));    % block extraction

    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));
Stx = SI - SQ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -