Azzera filtri
Azzera filtri

impulse response for difference equation

18 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

David Goodmanson
David Goodmanson il 1 Ago 2020
Hi Roger,
try
bb(N+1) = -power(a,N);
which is what you actually have. I think you'll lilke the resulting plot.
  1 Commento
Roger J
Roger J il 1 Ago 2020
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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by