Finding derivative of a transfer function in Matlab Symbolic

4 views (last 30 days)
Hi,
I've had a look through the answers here but haven't found anything that really helped me. This is a problem I've been able to solve in the past, but I can't seem to figure out how to do it now and I'm wasting a lot of time taking various approaches and not getting the result I'm looking for.
I have several transfer functions, which are defined in the form:
syms z b w;
H(z) = (z - exp(-b)*cos(w) - 1i* exp(-b)*sin(w)) * (z - exp(-b)*cos(w) + 1i * exp(-b)*sin(w));
(this is the simplest example - some are rational)
I'm trying to find the extremum of the magnitude frequency response. So the approach I want to take is something like this:
H_ps = abs(H)^2;
H_ps_prime = diff(H_ps, z);
with z restricted to the unit circle. I've tried doing this by:
syms r;
z = exp(1i* r);
% in this case, r essentially replaces z as the dependent variable in H
%I've also tried this, but it doesn't seem to work properly
assume(abs(z) == 1);
Once I've got it, I want to solve to H_ps_prime with respect to r - i.e. get the value of r for which the H_ps_prime is zero. I would also like to find the value of w for which this is the case, as the whole purpose of this exercise is to get a function that I can use to "correct" w so that it coincides with the magnitude extremum.
I've tried this by:
solve(H_ps_prime == 0, r);
.. but this does not give me the right result.
In the case of the two zero filter I've used as an example here, I already know what the result should be as I've obtained it previously and have it written down. The magnitude extremum is at:
r_ext = 2*atan(sqrt( - (exp(b)^2 * cos(w) - 2 * exp(b) + cos(w))/(exp(b)^2 * cos(w) + 2 * exp(b) + cos(w))));
and the solution for w is:
w_c = acos((2 * exp(b) * cos(r_ext)) / (exp( 2 * b) + 1));
whereas I'm getting the following:
syms r b w;
H(r) = (exp(1i*r) - exp(-b)*cos(w) - 1i* exp(-b)*sin(w)) * (exp(1i*r) - exp(-b)*cos(w) + 1i* exp(-b)*sin(w));
H_ps = abs(H)^2;
H_ps_prime = diff(H_ps, r);
solve(H_ps_prime == 0 , r);
ans =
-log(exp(-b)(cos(w) - sin(w) *1i)) * 1i;
-log(exp(-b)(cos(w) + sin(w) *1i)) * 1i;
-log(exp(-b)*cos(w))*1i;
Can anybody tell me where I'm going wrong? I feel like I must be doing something stupid.
edit:
To add some further details: I have set assumptions on w, b and r that all should be real. r should also be restricted to the range [-pi, pi] and w and b should be in the range [0, pi]. Despite this, when solving for r (or w for that matter), matlab gives me a complex number. I have also been getting a "maximum recursion" error when calling solve on occasion (not sure what triggers it, but it throws and exits the call).

Answers (1)

Walter Roberson
Walter Roberson on 5 Jun 2017
Once you have done the solve() that gives you the log() results, use rewrite() to express in terms of atan.
rewrite(ans, 'atan')
There are equivalences between log and atan
  2 Comments
David Browne
David Browne on 5 Jun 2017
The problem isn't the form of the equation, it's that the equation does not provide the result I'm after.
Walter Roberson
Walter Roberson on 5 Jun 2017
I cross-checked with another package; it agrees with the answers MATLAB produces, and confirms that the answer you expect does not match any of the three answers MATLAB produces.
Question: can we place constraints on any of the symbols? For example are w, b, and r all real-valued?

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!