📄 transmitter.m
字号:
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) % transmit only10_pilots. % transmit one more frame to record the length of message Len = length(message); len_bits = de2bi(Len,nr_subcarriers); % BPSK modulation for length frame len_symbols = modulation(len_bits,ones(1,nr_subcarriers),Ex*ones(1,nr_subcarriers)); len_frames = reshape(len_symbols,nr_subcarriers,1); frames = [pilots_ten len_frames]; for nr = 1:nr_pilots + 1 IFFTframes(:,nr) = symifft(frames(:,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 + 1) ); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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; % flag: 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 % 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 % 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) ) % symifft :obtain real value to transmit % symfft : pick up only half values to get back data 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) ); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if (train_flag == 0) % transmit message with syn. training sequence to know when to start processing message train_flag = 1; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -