www.gusucode.com > 关于蓝牙的很好的仿真程序(simulink加matlab)源码程序 > test_voice_basic.m

    % Do basic testing of model, ensuring zero errors
% for all SCO voice packet types and slot options at high SNR

% Define model
Modelname='bluetooth_full_duplex';

% Turn off AWGN
set_param([Modelname '/System parameters'],'Channel_type','None');

% Packet types and intial slot options to be simulated
Test_Packet_Types={'HV1', 'HV2', 'HV3', 'SCORT'};
Slot_options{1}={'1&2'};
Slot_options{2}={'1&2' '3&4'};
Slot_options{3}={'1&2' '3&4' '5&6'};
Slot_options{4}={'1&2'};

Simulation_time=7/1600; % 7 slots

for Test_Packet_Type=1:length(Test_Packet_Types) % For each packet type...
    
    %  Set devices to current packet type     
    set_param([Modelname '/System parameters'],'Packet_type',Test_Packet_Types{Test_Packet_Type});
   
    for Slot_option=1:length(Slot_options{Test_Packet_Type})
        
        % Set slot option
        set_param([Modelname '/BT Device'],'Slot_pair',Slot_options{Test_Packet_Type}{Slot_option});
        set_param([Modelname '/BT Device1'],'Slot_pair',Slot_options{Test_Packet_Type}{Slot_option});
        
        %  Display packet type currently being simulated
        disp(['Testing packet type: ' Test_Packet_Types{Test_Packet_Type} ', Slot Option: ' Slot_options{Test_Packet_Type}{Slot_option} '...'] );
        
        % Run simulation
        sim(Modelname, Simulation_time);
        
        % Display results
        disp('Error Results:');   
        disp(['Device 1: ' num2str(BER_Results1)]);   
        disp(['Device 2: ' num2str(BER_Results2)]);  
        disp(' ');
        
        % Error-out if any failures
        if any(BER_Results1)
            error(['Test failed. Packet type ' Test_Packet_Types{Test_Packet_Type}])
        end
    end
end