📄 simulation_for_channel.m
字号:
function [sent_signal1,sent_signal2,training_sequence1,training_sequence2,data_block,fs,T,fc,pulsetype]=simulation_for_channel()%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Function part of simulation for Space-Time%%% coding project, group Grey-2001.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Author: Stef and Fred% Date: 2001-03-19% Version: 1.0% Revision (Name & Date):%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clf, clear%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Initializations%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%N = 500; % Number of total datablock_size = N; % block_size must be multiple of N.training_length1 = 200; % training_length + N must be an even number!training_length2 = training_length1;
fc = 2500; % Carrier-frequencyfs = 8000; % Sampling-frequencyT = 0.001; % Symboltimepulsetype = 4; % 1: rect 2:root-rais-cos 3:hamming 4:raised-cosmodel = 0; % 0: no Alamouti (1*1) 1: Alamouti (2*1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Running Simulation%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
compared_error = [];for(model=model:model)EbN0error = [];for(EbN0=10:10) error = []; data = random_data(N); % Generate random source-data for(i=0:(length(data)/block_size)-1) data_block = get_datablock(data,block_size,i); symbols = bpsk(data_block,model); [s_antenna1, s_antenna2] = alamouti(symbols,model); % set = 1, alamouti coding is performed! if model == 1 [s_antenna1,s_antenna2,training_sequence1,training_sequence2]=add_training2(s_antenna1,s_antenna2,... training_length1,training_length2,0); % type = 0, random training-sequence. outdata_block = [training_sequence1 training_sequence2 data_block]; elseif model == 0 [s_antenna1,training_sequence1]=add_training(s_antenna1,training_length1,0) % type = 0, random training-sequence. outdata_block = [training_sequence1 data_block]; end % model == 1
%%% %%% Antenna 1 %%%
[s1,t1]=pulseshape(s_antenna1,fs,pulsetype,T); % Apply pulseshaping [spb1]=carrier(s1,fc,fs,T); [Spb1,f]=ftfast(spb1,t1);
%%% %%% Antenna 2 %%%
[s2,t2]=pulseshape(s_antenna2,fs,pulsetype,T); % Apply pulseshaping [spb2]=carrier(s2,fc,fs,T); %%% %%% Plotting results %%% rows=2; cols=3; figure(1), subplot(rows,cols,1), plot(s1) subplot(rows,cols,2), plot(s2) subplot(rows,cols,3) %axis([0 2*fc 0.01 1]); plot(1:length(spb1),spb1); title('Signal on antenna 1') xlabel('sampel') subplot(rows,cols,4) %axis([0 2*fc 0.01 1]); plot(1:length(spb2),spb2); title('Signal on antenna 2') xlabel('sampel') subplot(rows,cols,5) plot(f,abs(Spb1)) title('Spectrum (Antenna 1)'); xlabel('Frequency [Hz]'); sent_signal1 = spb1; sent_signal2 = spb2; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% break %%%%%%%%%%%%%%%%% % Simulation stops here.. %%%%%%%%%%%%%%%%% %%% %%% Simulating with simple channel 1 & 2. %%%
%[spb1_thru_channel]=channel(spb1,[1 -0.5 -0.6 0.3 -0.2],1); [spb1_thru_channel]=channel(spb1,1,1); [spb1_thru_channel]=awgn(spb1_thru_channel,EbN0); % Input argument is SNR in decibel.
[spb2_thru_channel]=simple_test_channel(spb2,2); [spb2_thru_channel]=awgn(spb2_thru_channel,EbN0); % Input argument is SNR in decibel. %%% %%% Only recieving in recieve-antenna 1. %%%
recieve1 = spb1_thru_channel + spb2_thru_channel; [quad,inphase]=down_converter(recieve1,fc,fs,T,2*(fc/(fs/2)),20); figure(2), subplot(2,2,1), plot(1:length(quad),quad); title('Quad after down-conv.'); subplot(2,2,2), plot(1:length(inphase),inphase); title('Inphase after down-conv.'); [mf_quad_block]=matched_filter(fs, T, pulsetype, quad); % Quadrature-part [mf_inphase_block]=matched_filter(fs, T, pulsetype, inphase); % Inphase-part subplot(2,2,3), plot(1:length(mf_quad_block),mf_quad_block); title('Quad after MF'); subplot(2,2,4), plot(1:length(mf_inphase_block),mf_inphase_block); title('Inphase after MF'); %%% %%% Performing synchronization %%% [sample_nr]=synchronization(mf_inphase_block, fs, T, training_sequence1, model) block_length=length(outdata_block); [inphase_symbols]=down_sampler(mf_inphase_block,sample_nr,fs,T,block_length); [quad_symbols]=down_sampler(mf_quad_block,sample_nr,fs,T,block_length); figure(3), subplot(1,2,2), plot(mf_inphase_block), hold on for(i=0:block_length-1) plot(i*(fs*T)+sample_nr,inphase_symbols(i+1),'o'); end hold off title('Recieved data and samplepoints. (not yet combined!)'); subplot(1,2,1), plot(outdata_block), axis([-5 35 -0.5 1.5]), title('Sent data.'); %%%
%%% Forcing phase-shift pi/4.
%%%
alfa = abs(inphase_symbols + j*quad_symbols); fi = angle(inphase_symbols + j*quad_symbols); fi = fi + 5*(pi/8); quad_symbols = alfa.*sin(fi); inphase_symbols = alfa.*cos(fi); figure(4), subplot(1,2,1), plot(inphase_symbols,quad_symbols,'x'), axis([-2 2 -2 2]), title('Signals after MF and sampled')
%%% %%% Estimating Channel 1 and 2. %%%
%[alpha1,theta1]=channel_estimator_lms(quad_symbols(1:training_length1),inphase_symbols(1:training_length1)... % , bpsk(training_sequence1,1)) [alpha1,theta1] = channel_estimator(quad_symbols(1:training_length1), ... inphase_symbols(1:training_length2), training_sequence1, model, 1) if model == 1
%[alpha2,theta2]=channel_estimator_lms(quad_symbols(training_length1+1:training_length1+ ... %training_length2),inphase_symbols(training_length1+1:training_length1+ ... %training_length2), bpsk(training_sequence2,1)) [alpha2,theta2] = channel_estimator(quad_symbols(training_length1+1:training_length1+ ...
training_length2), inphase_symbols(training_length1+1:training_length1+ ...
training_length2), training_sequence2, model, 2) elseif model == 0 alpha2 = 1; theta2 = 0; end % set true values instead: %alpha1 = 1; %theta1 = 0; %alpha2 = 1; %theta2 = 0;
%%%
%%% No combiner used since only 1 antenna is used to send from so far.
%%%
[combined_signal]=combiner_var(alpha1, theta1, alpha2, theta2, ...
inphase_symbols, quad_symbols, model);
figure(5), plot(combined_signal,'x'), axis([-6 6 -6 6]), title('Signals after combiner')
%%%
%%% Detector
%%%
inphase_symbols = real(combined_signal);
[indata_est,training1_est,training2_est]=detector(inphase_symbols,training_length1,training_length2,model); disp('Received data is:')
indata_est
disp('Sent data is:') data_block nr_of_errors = sum(abs(data_block-indata_est)) nr_of_errors_in_rate = nr_of_errors/length(data_block) error = [error nr_of_errors_in_rate]; end error = mean(error); EbN0error = [EbN0error error];endEbN0errorcompared_error = [compared_error EbN0error'];end%compared_error%figure(11)%semilogy(1:length(compared_error(:,1)),compared_error(:,1),'blue',1:length(compared_error(:,2)),compared_error(:,2),'green')sent_signal = spb1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -