getMI.m 771 B

123456789101112131415161718192021
  1. function [MI, rows] = getMI(values1, values2)
  2. % by Mattia, 09/20
  3. % simple helper function to compute modulation index (normalize "paired" values in the -1 to 1 range)
  4. % inputs: - values1 & 2 -> vector with values to use to compute MI
  5. % output: modulation index for the given values
  6. % important: - if the inputs take negative AND positive values,
  7. % the behavior of the function is erratic (i.e.
  8. % normalization between -1 and 1 fails).
  9. % - if the inputs take negative OR positive values,
  10. % the normalization succeeds
  11. % take only real values if input is complex
  12. if ~isreal(values1) || ~isreal(values2)
  13. values1 = real(values1);
  14. values2 = real(values2);
  15. end
  16. % compute MI
  17. MI = (values1 - values2) ./ (values1 + values2);
  18. end