SneakyMummin
SneakyMummin

Reputation: 711

Filter function usage Matlab

I am trying to perform a simple simulation in Matlab. I have a random signal x and a filter transfer function. What is the proper usage of the filter function?

x = rand(100,1);
syms z;
Pnum = (1-0.1*z^-1); 
Pdenum = (1-0.9*z^-1);

y = filter(Pnum, Pdenum, x); 

This throws the error

"Undefined function 'filter' for input arguments of type 'sym'."

I understand that it's complaining about the z variable. How should I go about solving it?

Upvotes: 1

Views: 3683

Answers (1)

learnvst
learnvst

Reputation: 16193

The filter command is not built to take symbolic data types. It takes the raw filter coefficients as input. What it looks like you are trying to define is a difference equation where the b coefficients are . .

b = [1 0.1];

and the a coefficients are

a = [1 0.9];

you can then filter the signal as follows

y = filter(b,a,x)

The freqz command reveals that this is a strange high pass filter with some gain . .

freqz(b,a)

enter image description here

Is this what you are trying to achieve?

If you reverse the coefficients so

b = [1 0.9];
a = [1 0.1];

...you end up with a low pass filter with some gain

freqz(b,a)

enter image description here

Upvotes: 3

Related Questions