Need help, How do filter function work?

조회 수: 2 (최근 30일)
Miguel Faria
Miguel Faria 2018년 1월 20일
댓글: William Rose 2018년 1월 22일
y[n] − 0.4y[n − 1] = x[n]; y[−1] = 1.
Need response to input signal, x[n] = ((0.4)^n)u[n] to n = −5, ..., 30.
  댓글 수: 2
Rik
Rik 2018년 1월 20일
Have a read here and here. It will greatly improve your chances of getting an answer.
William Rose
William Rose 2018년 1월 20일
Mr. Faria, You state that y is known at time n=-1, but you also say you want to see the system response to a signal which starts at n=-5. That leaves me unsure about whether you want to know y starting at time n=-5 or starting at time n=0. The Z transform of the system is Y(z)=H(z)*X(z), where H(z)=B(z)/A(z), where B and A are the numerator and denominator polynomials (polynomials in z^-1). In this case, the numerator polynomial is B=1, and the denominator polynomial is A=1-0.4*z^-1. Therefore the vector of numerator coefficients is b=1 and the vector of denominator coefficients is a=[1,-0.4]. If we ignore the bit about initial conditions on y (which means we assume y=0 at times in the past, then we can compute y at times from -5 to +30 using the filter function, as follows:
n=[-5:30];
ustep=(n>=0);
x=ustep.*0.4.^n;
a=[1 -.4];b=1;
y=filter(b,a,x);
plot(n,x,'ro-',n,y,'bx-');
xlabel('Time'); legend('X','Y');
You could get the same result for y using a for loop. I will call it y2 this time:
y2(1)=0;
for i=2:36,y2(i)=.4*y2(i-1)+x(i); end
The solution above started at n=-5 and did not obey the required initial condition y(-1)=1. If we want to apply the initial condition at n=-1, then we will use Matlab's filter to compute the output starting at time n=0. No time for more now. Maybe later.

댓글을 달려면 로그인하십시오.

채택된 답변

Miguel Faria
Miguel Faria 2018년 1월 21일
My problem is: This is what I have : y(n) - 0.4y(n-2) = x(n) , y(-1) = 1 , x(n) = (0.4)^n * u(n)
I started to solve: a = [1, -0.4] b = 1
n = -5:1:30.
y= filter(b , a , x , filtic(b,a,1))
And my problem is: How do I define this? --> x(n) = (0.4)^n * u(n) I already tried it: (0.4)^n * (ones(1,30)) but it does not.
  댓글 수: 1
William Rose
William Rose 2018년 1월 22일
I assume that by u(n) you mean the unit step function: u=0 for n<0, u=1 for n>=0. I did give you x(n) in the code I posted earlier. I wrote:
n=[-5:30]; %vector of times
ustep=(n>=30); %boolean vector with 5 false values
%followed by 31 true values
x=ustep.*0.4.^n; %element-wise multiply and
%element-wise power

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Pole and Zero Locations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by