gusucode.com > UWB_matlab源码程序 > CP0203/cp0203_OFDM_qpsk.m
% % 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] = 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)); Stx = SI - SQ;