2
0

phasesecord.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. % phasesecord.m
  2. % David Rowe Aug 2012
  3. % Used to experiment with aproximations of phase of 2nd order systems
  4. function phasesecord(w,beta)
  5. a = [1 -2*cos(w)*beta beta*beta];
  6. b = 1;
  7. [h w1] = freqz(b,a);
  8. figure(1)
  9. subplot(211)
  10. plot(abs(h))
  11. subplot(212)
  12. plot(angle(h))
  13. % for beta close to 1, we approximate 3 dB points as 1-beta above
  14. % and below the resonance freq. Note this fails if w=0 as there is a
  15. % double pole. Lets sample the freq response at the 3dB points and
  16. % w:
  17. ws = [w-(1-beta) w w+(1-beta)];
  18. [h w1] = freqz(b,a,ws);
  19. % gain as a fraction of max, should be 3dB. Within 1.3 dB or for w > pi/8,
  20. % gets innacurate near w=0 due to 2nd pole
  21. printf("mag measured...:"); printf("% 4.3f ", abs(h)/max(abs(h)));
  22. % measured angle, 45 deg from angle at w
  23. printf("\nangle measured.: "); printf("% 5.3f ", angle(h));
  24. % Our estimate of angle, (pi+w) is phase at resonance, at lower 3dB
  25. % phase is pi/4 ahead, at upper 3B pi/4 behind. -pi/2 is contribution of
  26. % other pole at at -w to phase
  27. ph_lower = (pi+w) + pi/4 - pi/2;
  28. ph_res =(pi+w) - pi/2;
  29. ph_upper = (pi+w) - pi/4 - pi/2;
  30. ph_ests = [ph_lower ph_res ph_upper];
  31. ph_ests = ph_ests - 2*pi*(floor(ph_ests/(2*pi)) + 0.5);
  32. printf("\nangle estimated:"); printf("% 5.3f ", ph_ests);
  33. printf("\n");
  34. endfunction