/lib/Aubt/aubt_getSpecRange.m

http://siento.googlecode.com/ · MATLAB · 28 lines · 11 code · 2 blank · 15 comment · 1 complexity · 7dd5acb18ea8ad70f00e29765a39dc00 MD5 · raw file

  1. function value = getSpecRange (data, hz, r1, r2)
  2. % Expects as input a signal vector and estimates the mean of the frequency
  3. % spectrum in a given range.
  4. %
  5. % values = aubt_getSpecRange (data, hz, r1, r2)
  6. %
  7. % input:
  8. % data: signal vector
  9. % hz: samplerate of the input signal(s)
  10. % r1: lower bound of the frequeny band
  11. % r2: upper bound of the frequeny band
  12. %
  13. % output:
  14. % values: mean of the frequency spectrum
  15. %
  16. % 2005, Johannes Wagner <go.joe@gmx.de>
  17. len = length (data);
  18. spec = psd (data, len, hz/2);
  19. spec = spec / sum (spec);
  20. hzPerSample = hz / len;
  21. spec = spec (ceil (r1/hzPerSample)+1:floor (r2/hzPerSample)+1);
  22. if isempty (spec)
  23. value = 0;
  24. else
  25. value = mean (spec);
  26. end