Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithmically get Amplitude and Phase of Sine wave?

I'm trying to figure out a way to algorithmically get the amplitude and phase of a function that has sinusoidal terms in the Maxima computer algebra system. This only applies to steady state (as t -> infinity and the transients decay). For example, a trivial case would be:

f(t) = 1 / w * sin(w * t + theta) + exp(-a * t) + 8

In this case, the gain would be 1 / w, the phase offset would be theta, and we would ignore the transient term exp(-a * t) because we only care about the steady state gain and phase delay, and exp(-a * t) -> 0 as t -> infinity. We would also ignore the "+ 8" term because it's just a DC offset. The way I've been taught to do it in my engineering classes requires a lot of heuristics and tedious rearranging of equations to get them in a form similar to the above, where the answer is obvious just from looking at it.

Does anyone know of a general, algorithmic method of finding the gain and phase delay assuming they exist, given that I have the full power of a computer algebra system (and the standard functions that one would expect a CAS to have) to throw at it? Although I will likely be implementing it in Maxima, I would certainly appreciate generic answers explained just in terms of math.

Edit: I thought it was abundantly clear from my example that I want the answer symbolically, in terms of w. w is really supposed to be omega, and represents the frequency of the input. What I'm really asking is whether there are any standard math operations that will produce the gain and phase terms without a bunch of heuristic, manual equation rearranging.

like image 777
dsimcha Avatar asked Jan 23 '23 04:01

dsimcha


2 Answers

Do you mean symbolically or numerically?

Numerically you'd want to perform a Fourier transform:

  • sample the function for at at least twice the expected maximum frequency (even higher if you want more precise measurement of phase) and for as long as at least your maximum expected wavelength

  • perform a Fourier transfomr (searching for FFT should turn up lots of examples - my searches suggest that maxima may even have a built in fft function)

  • this'll give you a "frequency domain" version of your function. You'll have a series of complex values where the magnitude is the amplitude for that frequency, and the angle is the phase of that frequency component. In your case it sounds like you want to look for the frequeny with the peak amplitude

like image 187
Laurence Gonsalves Avatar answered Jan 25 '23 18:01

Laurence Gonsalves


Either a Laplace or a Fourier transform may help; you can apply either symbolically as well as numerically. But I'm not sure you will be able to create a general algorithmic method - usually there are different case depending where the poles are.

like image 23
Pete Kirkham Avatar answered Jan 25 '23 18:01

Pete Kirkham