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

📄 cp0203_ofdm_qpsk_try.asv

📁 uwb无线电基础书本(电子工业出版社)的MATLAB程序
💻 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 lenght 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 [x,bits] = cp0203_OFDM_qpsk(numbits,N);

% ----------------------------
% Step Zero - Input parameters
% ----------------------------
 
numbits = 2032;      % number of bits to be transmitted  127*n
N = 128;      % number of carriers of the OFDM
                     %  system
[bits] = cp0201_bits(numbits);
[S,Sc,Ss] = cp0203_qpsk_mod(bits);
%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

       

% -------------------------
% 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



% QPSK modulator


% OFDM modulator

nb = ceil(length(S)/(N-1));      % 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)'];
x = zeros(1,(2*N+2*ntcp)*nb);
for  b = 1 : nb
    
    c = S0((1+(b-1)*(N-1)):(N-1+(b-1)*(N-1)));    % block extraction

    % S/P conversion and zero padding
    A = length(c);
   % a1 = floor(A/2);
   % a2 = A - a1;
   % FS = 2*A;
    Czp=zeros(1,A);
    Czp(1:A)=c(1:A);
    %Czp(1+A:2*A)=[conj(c(N:-1:1)).']
    %Czp(FS-a2+1:FS)=[c(A-a2+1:A).'];
    Czp=[0 Czp 0 conj(Czp(A:-1:1))];  
    C = ifft(Czp);  % IFFT of the zero-padded input
    
   
    
    if ntcp>0 % Insertion of the cyclic prefix
        C1=zeros(1,length(C)+2*ntcp);
        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(1+(2*N+2*ntcp)*(b-1):2*N+2*ntcp+(2*N+2*ntcp)*(b-1))=C1;
    C3=fft(x(65+(2*N+2*ntcp)*(b-1):2*N+2*ntcp+(2*N+2*ntcp)*(b-1)));
    
    
    
end % for b = 1 : nb




y = x;
t= (length(x)/320)*312.5e-9;
time = linspace(0,t,length(x));

figure(3);
S3=stem(time,y);



ntcp = N/4;
NT = 2*N + 2*ntcp;
r_n = max(size(y))/NT;
Y1 = zeros(1,2*N*r_n);
Y = zeros(1,(N-1)*r_n);
Z = zeros(1,2*N);

for a = 1:r_n
    Z = fft(y(2*ntcp+1+(a-1)*NT):NT+(a-1)*NT);
    Y1(1+(a-1)*2*N:2*N+(a-1)*2*N) = Z(1:2*N);
    Y(1+(a-1)*(N-1):N-1+(a-1)*(N-1)) = Y1(2+(a-1)*2*N:N+(a-1)*2*N);
end

[r_bits] = cp0203_qpsk_demod(Y);
R_bits = r_bits;


ER = sum(abs(bits-r_bits));

⌨️ 快捷键说明

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