# Inverse of filter function

72 views (last 30 days)

Show older comments

How to write the inverse of the filter function?

I use a filter function with input x to get output y. I want to get input x back.

y = filter(b,a,x,zi)

y = <inverse filter to get original input x>

##### 0 Comments

### Accepted Answer

Christoph F.
on 2 May 2017

In the z domain, the transfer function of a filter H(z) is B(z)/A(z).

The inverse of the transfer function is A(z)/B(z). However, this only makes sense if the zeros of B(z) are inside the unit circle; if they are outside, the inverse filter will have poles outside the unit circle and hence be unstable.

##### 1 Comment

Paul
on 15 Jan 2024

In addition to the possiblity of the inverse filter having poles outside the unit circle, which is of practical concern, another consideration is the causality of the inverse filter.

Define the signal

rng(100);

N = 1000;

sig = sin(2*pi*40*(0:N-1)*0.001);

n = 0:N-1;

Define an IIR filter with one zero and four poles and filter the signal

[B,A] = zp2tf(0.6,[0.1 0.2 0.3 0.4],1)

sigf = filter(B,A,sig);

figure

plot(n,sig,n,sigf)

Attempting to filter with the inverse filter casues an error because the inverse filter is non-causal (more zeros than poles)

try

sigr = filter(A,B,sigf);

catch ME

ME.message

end

Instead, we mutiply the inverse filter by 1/z^3 (the power is the number of leading zeros in B), then filter

sigr = filter(A,B(end-1:end),sigf);

then shift the output back by three samples.

sigr = sigr(4:end);

nr = numel(sigr);

This approach recovered the input signal except for the last three samples.

figure

plot(n,sig,n(1:nr),sigr)

figure

plot(n(1:nr),sig(1:nr)-sigr)

### More Answers (1)

Jan
on 2 May 2017

##### 8 Comments

John D'Errico
on 5 May 2017

Paul
on 15 Jan 2024

Using the 'same' option with conv is not the same operation as using filter. In this example, the 'same' option results in an output that is shifte by 1 sample relative to the output of filter. Can the A matrix be changed appropriately?

Probably won't change the general conclusion ....

rng(100)

K = ones(1,3)/3;

S0 = rand(1,10);

S1 = conv(S0,K,'same');

S1a = conv(S0,K);

S1b = filter(K,1,S0);

[S1;S1a(1:numel(S0));S1b]

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!