help-octave
[Top][All Lists]

## Re: test this in matlab for my please

 From: Doug Stewart Subject: Re: test this in matlab for my please Date: Thu, 14 Jul 2016 10:04:09 -0400

On Fri, Jul 8, 2016 at 10:26 PM, Mike Miller wrote:
On Fri, Jul 08, 2016 at 22:01:03 -0400, Doug Stewart wrote:
> If you want to see what I have learned read this. It isn'e polished but
> does record
> the important points.
>
> https://dl.dropboxusercontent.com/u/24993484/Z_tran%20_of_repeated_roots.pdf
>
> I now have to rewrite my code to make it look better and then update the
> control pkg.
>
>
> There is one difference from matlab and as such one question.
> http://www.mathworks.com/help/signal/ref/impinvar.html
>
> matlab says;
>
> "
>
> Plot the digital impulse response, multiplying the numerator by a constant (
> Fs) to compensate for the 1/Fs gain introduced in the impulse response of
> the derived digital filter.
>
> [b,a] = butter(4,0.3,'s');
> [bz,az] = impinvar(b,a,10);
> sys = tf(b,a);
> impulse(sys);
> hold on;
> impz(10*bz,az,[],10);
>
> "
>
> Notice the 10*bz ;
>
> Their code produces the filter coefficients  that are wrong by a
> factor of Fs!!!!
>
> My code does not need this extra multiply by Fs.
>
> What should I do?
>
> To say it another way their output from the filter needs a correction factor!
>
> I would prefer to keep my results. It is derived with proper math.

Doug,

I haven't been following too closely since you've been mostly asking for
Matlab tests and I can't help with that.

Are you writing impinvar or are you working on impulse and comparing to
impinvar?

Are you aware that there already is an impinvar in the signal package?

I just don't want wasted duplicate effort if you didn't know that the
signal package already has an impinvar function. Maybe it needs
improvement or is not Matlab compatible, I'm not sure.

Cheers,

--
mike

Hi Mike.
No I did not know about impinvar in the signal pkg.
I am still glad that I wrote my version.

Testing impinvar i see:

s=tf('s');
T=.1
sys=1/(s)
[b a]=tfdata(sys,'v');
[bz az]=impinvar(b,a,T);
syssig=tf(bz,az,T)

output is

1
y1:  -
s

Continuous-time model.

Transfer function 'syssig' from input 'u1' to output ...

10
y1:  -----
z - 1

Sampling time: 0.1 s
Discrete-time model.

This answer is 10 times to big.

1/s is an integrator and/or  a step function in laplace.
the Z transform that will give the same output from an impulse input will be
an integrator with a pole at +1 and a zero at the origin
z
------
z+1

the result from impinvar is missing the zero at the origin and is 10 time to big.

Now Matlabe gives

ans =

0.1 z
-----          This is wrong!!!
z - 1

which has the zero at the origin but has a gain of 1/10th of what it should!
Matlab the does a correction factor of 1/T when they plot it so that it comes out correct,
but this does not help anyone who just wants the formula not the plot.

I also tested other inputs to impinvar and they are wrong in many ways.

here is one more example.

s=tf('s');
T=.1
sys=1/(s*s*(s+1))
[b a]=tfdata(sys,'v');
[bz az]=impinvar(b,a,T);
syssig=tf(bz,az,T)

sysdoug = imp_invariant2(sys,T)

T =  0.10000

Transfer function 'sys' from input 'u1' to output ...

1
y1:  ---------
s^3 + s^2

Continuous-time model.

Transfer function 'syssig' from input 'u1' to output ...

90 z + 9.995
y1:  ----------------------------
z^3 - 2 z^2 + 1 z - 4.54e-05

Sampling time: 0.1 s
Discrete-time model.

Transfer function 'sysdoug' from input 'u1' to output ...

0.004837 z^2 + 0.004679 z
y1:  ---------------------------------
z^3 - 2.905 z^2 + 2.81 z - 0.9048

Sampling time: 0.1 s
Discrete-time model.

Maltab and my  inp_invariant2 give the same result except for the 1/T factor

but impinvar gives

90 z + 9.995
y1:  ----------------------------
z^3 - 2 z^2 + 1 z - 4.54e-05

which is wrong.

Can you retest these two functions in your octave and verify what I am seeing please.

--
DAS