# How to generate H(-s) in MATLAB

1. ## How to generate H(-s) in MATLAB

Assume that I have transfer function, H(s).
Here I would like to generate H(-s) smartly.

Now I use following MATLAB code for this purpose.
Here I use "Control System Toolbox".
However it is not cool at all.

I will not use "Symbolic Math Toolbox".

Is there any cool method ?
Code:
```>> s=tf('s')

Transfer function:
s

>> H=(s^2+s^1+3)/(s^3+s^2+s+2)

Transfer function:
s^2 + s + 3
-----------------
s^3 + s^2 + s + 2

>> [z, p, k] = zpkdata(H, 'v')

z =

-0.5000 + 1.6583i
-0.5000 - 1.6583i

p =

-1.3532
0.1766 + 1.2028i
0.1766 - 1.2028i

k =

1

>> num_zeros = length(z)

num_zeros =

2

>> num_poles = length(p)

num_poles =

3

>> if mod(num_zeros+num_poles, 2) == 0
zpk(-z, -p, k)
else
zpk(-z, -p, -k)
end

Zero/pole/gain:
- (s^2 - s + 3)
---------------------------------
(s-1.353) (s^2 + 0.3532s + 1.478)

>>```

Code:
```>> s=tf('s')

Transfer function:
s

>> H=(s^2+s^1+3)/(s^3+s^2+s+2)

Transfer function:
s^2 + s + 3
-----------------
s^3 + s^2 + s + 2

>> [num, den] = tfdata(H, 'v')

num =

0     1     1     3

den =

1     1     1     2

>> for(i=1:length(num))
if mod(i+length(num), 2) == 1, num(i) = -num(i); end
end
>> for(i=1:length(den))
if mod(i+length(den), 2) == 1, den(i) = -den(i); end
end
>> tf(num, den)

Transfer function:
-s^2 + s - 3
-----------------
s^3 - s^2 + s - 2

>>```  Reply With Quote

•

2. ## Re: How to generate H(-s) in MATLAB

Hi,

Provide a little more detail of what you want to do, especially on H(-s).  Reply With Quote

•

3. ## Re: How to generate H(-s) in MATLAB Originally Posted by Akanimo Provide a little more detail of what you want to do, especially on H(-s).
For example, decompisition of H(s) to even and odd components.

H(s) = Heven(s) + Hodd(s)
Heven(s) = {H(s) + H(-s)} / 2
Hodd(s) = {H(s) - H(-s)} / 2  Reply With Quote

--[[ ]]--