impulse response for difference equation

조회 수: 57 (최근 30일)
Roger J
Roger J 2020년 7월 30일
댓글: Roger J 2020년 8월 1일
I'm trying to derive the impulse response for the following:
y[n] = ay[n − 1] + x[n] − (a^N)x[n − N]
I am using two different methods.
  1. using the filter() function in Matlab.
  2. using pencil and paper, as per Exercise 2.25 in DTSP by Oppenheim
But the results don't agree with each other:
My code:
close all
clear
% solve the following:
% y[n] = ay[n − 1] + x[n] − (a^N)x[n − N]
% first with the fitler() function
% next with direct calculation of h(n), as per ex. 2.25 in the textbook
% using the filter() function
a=0.8;
N=5;
aa=zeros(1,50);
aa(1:2)=[1 -a];
bb=zeros(1,50);
bb(1)=1;
bb(N+1)=power(a,N);
myImpulse=zeros(1,50);
myImpulse(1)=1;
myImpulseResponse=filter(bb,aa,myImpulse);
t=0:49;
figure(1);
subplot(2,1,1)
stem(t,myImpulseResponse)
title('using filter()');
% next with direct calculation of h(n), as per ex. 2.25 in DTSP Oppenheim
% h[n] = (a^n)u[n] - (a^(n))*u[n-N]
a1 = power(a,t);
a2 = power(a,t);
a2(1:N)=0;
calculatedImpulseResponse = a1-a2;
subplot(2,1,2)
stem(t,calculatedImpulseResponse)
title('calculated as per DTSP Oppenheim')
I can explain my derivation (as per the example 2.25 in DTSP) if you need it.
I would like to know if I am using filter() correctly. Any observations would be appreciated.

채택된 답변

David Goodmanson
David Goodmanson 2020년 8월 1일
Hi Roger,
try
bb(N+1) = -power(a,N);
which is what you actually have. I think you'll lilke the resulting plot.
  댓글 수: 1
Roger J
Roger J 2020년 8월 1일
Thanks David.
Since asking the question I also have built the difference equation in simulink and verified my calculations matched simulink. So I was really stumped about filter().
Great catch. Thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Filter Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by