📄 transmitter.asv
字号:
function m1 = transmitter(training_seq, pilot, pilots_ten, message, bn, en, size_frame, is_updated)% This is simulation for the transmitter in the OFDM system.% ------- transmitter.m ------------------------------------% Black team% April-08-05% ----------------------------------------------------------global nr_cyclic_bitsglobal nr_subcarriersglobal encoder_orderglobal nr_pilotsglobal nr_framesglobal nr_fftglobal Ex%initialization, just for transmitterglobal startglobal begin_flag % to know when is the beginning of allglobal train_flag % to know when is the beginning of messageif(begin_flag==0) begin_flag % transmit only training sequence and 10_pilots. for nr = 1:nr_pilots IFFTframes(:,nr) = symifft(pilots_ten(:,nr)); end % add 10_empty_pilots for Noise_var estimation IFFTframes = [IFFTframes zeros(nr_fft,nr_pilots)]; cyclic_frames = add_prefix(IFFTframes,nr_cyclic_bits); m1 = reshape(cyclic_frames,1,(nr_cyclic_bits + nr_fft) * (nr_pilots + nr_pilots) ); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % upsampling and pulse shaping m1 = upfir(m1); m1 = m1(1:end-7); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% m1 = [training_seq m1]; begin_flag = 1; else if(is_updated==0) % wait wait = 1 else %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % transmit message size_block = size_frame * nr_frames ; untransmit_bits = length(message) - start + 1; if (untransmit_bits > size_block) % if the remain message is larger than a block transmit_bits = message(start:size_block+start); start = start + size_block; flag = 0; else % if not, we add zeros to get one block flag = size_block - untransmit_bits % record how many '0's are padded transmit_bits = [message(start:end) zeros(1,flag)]; start = 0; end % convolution coding coded_bits = conencoder(transmit_bits); %ouput of the encoder inter_output = coded_bits;% % interleaver% inter_output = interleaving(coded_bits,5,5); %output of the interleaver % modulation modulated_symbols=[]; for i = 1:nr_frames modulated_symbols = [modulated_symbols ... modulation(inter_output((i-1)*size_frame*encoder_order+1 : i*size_frame*encoder_order),bn,en)]; end a = 0; % add one frame to send the length of padding '0's if(flag~=0) flag_bits = de2bi(flag,nr_subcarriers,'left-msb'); flag_symbols = modulation(flag_bits,1,Ex); % BPSK modulation for flag frame flag_frame = reshape(flag_symbols,nr_subcarriers,1); flag_fft_frame = symifft(flag_frame); IFFTframes = [frames flag_fft_frame]; a = 1 end % serial to parallel : construct a matrix, each column is a frame. frames = reshape(modulated_symbols,nr_subcarriers,nr_frames); % insert pilots before transmitted message frames = [pilot frames]; % compute the IFFT % In the references, the formula for ifft and fft was % IFFT : x(k) = 1/sqrt(N) * sum( X(n) * exp(2.pi.j.n.k/N) ) % FFT : X(n) = 1/sqrt(N) * sum( x(k) * exp(-2.pi.j.n.k/N) ) for nr = 1:nr_frames+1 IFFTframes(:,nr) = symifft(frames(:,nr)); end % add zero-pilot to estimate noise power IFFTframes = [IFFTframes(:,1) zeros(nr_fft,1) IFFTframes(:,2:end)]; % add the cyclic prefix cyclic_frames = add_prefix(IFFTframes,nr_cyclic_bits); % parallel to serial m1 = reshape(cyclic_frames,1,(nr_cyclic_bits + nr_fft) * (nr_frames + 2 + a) ); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % synchro m1 = upfir(m1); m1 = m1(1:end-7); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if (train_flag == 0) % transmit message with syn. training sequence to know when to start processing message m1 = [training_seq m1]; train_flag = 1; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -