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

📄 simulation_ortho.m

📁 这个程序主要是实现空时编码的matlab编解码仿真。
💻 M
字号:
function []=simulation_ortho(input1,input2,input3,input4)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     %%% 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 = 120;                   % training_length + N must be an even number!training_length2 = training_length1;
fc              = 1000;                  % Carrier-frequencyfs              = 10000;                 % Sampling-frequencyT               = 0.01;                  % Symboltimepulsetype       = 4;							% 1: rect 2:root-rais-cos 3:hammingmodel		    = 1;							% 0: no Alamouti (1*1) 1: Alamouti (2*1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Running Simulation%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
compared_error = [];for(model=1:1)EbN0error = [];for(EbN0=30:30)    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.        [s_antenna1,s_antenna2,training_sequence1,...
              training_sequence2]=add_orthotrain(s_antenna1,s_antenna2,training_length1) % train1-train2 same length!
        
        outdata_block = [xor(training_sequence1,training_sequence2) data_block]; % xor is just put to get the correct length of vector.            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        %%%    %%% 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]');        %%%    %%% 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,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.    spb1_thru_channel = spb1;    spb2_thru_channel = spb2;        %%%    %%% Only recieving in recieve-antenna 1.    %%%    
    if(model==0)        recieve1 = spb1_thru_channel;    elseif(model==1)        recieve1 = spb1_thru_channel + spb2_thru_channel;    end        [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    %%%        %[corr_max,sample_nr]=synchronization(mf_inphase_block, fs, T, training_sequence1, model);    [corr_maxi,sample_nri,sum_of_r_times_c1i,sum_of_r_times_d2i]=...
       orthosynchronization(mf_inphase_block, fs, T, training_sequence1, training_sequence2, model);	 [corr_maxq,sample_nrq,sum_of_r_times_c1q,sum_of_r_times_d2q]=...
       orthosynchronization(mf_quad_block, fs, T, training_sequence1, training_sequence2, model);
    if corr_maxi > corr_maxq
       sample_nr = sample_nri
    else
       sample_nr = sample_nrq
    end
    
    %%%
    %%% Down-sampling
    %%%
    
    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), stem(outdata_block), axis([-5 35 -0.5 1.5]), title('Sent data.');                %%%
    %%% Forcing phase-shift.
    %%%
    alfa = abs(inphase_symbols + j*quad_symbols);    fi = angle(inphase_symbols + j*quad_symbols);    fi = fi + pi/4;    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(1:training_length2), inphase_symbols(1: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(alpha1, theta1, alpha2, theta2, ...
        inphase_symbols, quad_symbols, model);
     figure(5), plot(combined_signal(training_length1+1:end),'x'), axis([-6 6 -6 6]), title('Signals after combiner'), grid on
    %%%
    %%% Detector
    %%%
    
    inphase_symbols = real(combined_signal);
        [indata_est,training1_est,training2_est]=detector_ortho(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'];endcompared_errorfigure(11)%semilogy(1:length(compared_error(:,1)),compared_error(:,1),'blue',1:length(compared_error(:,2)),compared_error(:,2),'green')

⌨️ 快捷键说明

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