How to evaluate dirac function for Infi

조회 수: 7 (최근 30일)
Elijah Kornefel
Elijah Kornefel 2019년 3월 5일
댓글: Elijah Kornefel 2019년 3월 5일
dk= 1;
k = -10:dk:10;
G=(dirac(k+8)-2*dirac(k+4)+dirac(k)-2*dirac(k-4)+dirac(k-8)).*exp(-1i*pi.*k/8);
idx = G == Inf; %find Inf
G(idx) = 1; %sets Inf = 1
mag=abs(G);
stem(k,mag)
title('Magnitude vs k')
xlabel('k')
ylabel('Magnitude')
figure
phase=angle(G);
stem(k,phase)
title('Phase vs. k')
xlabel('k')
ylabel('Phase')
I know how to show values when G is equal to Inf, but my issue rises when G = Inf + Infi for example.
I have tried:
idi = G == -Inf + Infi;
G(idi) = 1i;
But no luck. Any help appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2019년 3월 5일
idi = G == complex(-inf, inf);
G(idi) = 1i;
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 3월 5일
Could you confirm that your system cannot produce +inf +inf*i ?
You can make the code more compact:
notfin = ~isfinite(G);
G(notfin) = complex(sign(real(G(notfin))), sign(imag(G(notfin))));
Elijah Kornefel
Elijah Kornefel 2019년 3월 5일
This also works. Thank you. I'll be sure to check for these any time I use dirac. My function did not necessarily produce every inf and infi combination, but it is more to check for all. This shorter snippet does that.
Thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by