Search code examples
algorithmmatlabwireless

Find Optimal Values of figure in matlab


I have a figure like x axis Bit Error Rate and y axis Data Rate. And I want to find minimum Bit Error Rate and maximum Data rate in this figure. Namely I want to do thing that in this figure there are 18 points and I want to find optimal result but I cannot it ?

enter image description here


Solution

  • I believe what you are asking is to find the optimal ratio between BitErrorRate and DataRate, in that case you need to calculate the ratio of BitErrorRate per DataRate and then find the min or max of that depending on whether you are looking for fewer or more BitErrorRate per DataRate. Assuming the BitErrorRate and BitRate are saved in arrays you could use code like this:

    % Give some random numbers to illustrate functionality
    BitErrorRate = [2 7 3 5 8 1];
    DataRate = [1 3 4 2 6 5];
    
    % Find the ratio of BitErrorRate per DataRate
    ErrorRatio = BitErrorRate ./ BitRate;
    
    % Optimal ratio with minimal errors per data rate and corresponding index
    [MinError, MinIndex] = min(ErrorRatio);
    
    % Print results in console
    disp(['Optimal error rate ratio is ' num2str(ErrorRatio(MinIndex)) ...
          ' BitErrorRate per DataRate with a Bit Error Rate of ' ...
          num2str(BitErrorRate(MinIndex)) ' and a Bit Rate of ' ...
          num2str(BitRate(MinIndex)) '.']);
    
    % Sort in ascending manner according to top row, below this is DataRate
    SortedForDataRate = sortrows([DataRate;BitErrorRate;ErrorRatio]')';
    
    fig = figure(1);
    subplot(3,1,1)
    plot(SortedForDataRate(1,:))
    title('BitErrorRate')
    subplot(3,1,2)
    plot(SortedForDataRate(2,:))
    title('DataRate')
    subplot(3,1,3)
    plot(SortedForDataRate(3,:))
    title('ErrorRatio')