MATLAB- ifft of simple lowpass filter returns NaN
조회 수: 25 (최근 30일)
이전 댓글 표시
Hello, I seem to be having issues using MATLAB's fft and ifft functions, when simulating a simple electrical circuit. Generally the strategy I've been taking is to fft the incoming time-domain signal, multiply the result by the frequency response of the circuit, and ifft the product to produce the time-domain output. However ifft seems to be producing NaN for the real part (and a small complex part). Any idea why this may be occurring and what to do about it? A simple example is below, using a first order RC butterworth filter. I'm really confused as to why this may be happening. I realize there are other ways to simulate such a simple system, however I'm applying this method to much more complex systems with existing frequency-domain models. Thanks!
clear all
Fs = 100;
n=1000;
t = (1/Fs:1/Fs:10); %time
test1 = cos(2*pi*5*t); %test funcion, 10Hz cosine
X = fft(test1,n); %1k pt fft
dF = Fs/n; %0.1Hz bin width
f = (dF*(0:n-1))-Fs/2; %frequency vector, centered around zero
c=1e-4;
r=1e3;
tf = (1./(j*2*pi*f*c))./(r+(1./(j*2*pi*f*c))); %filter frequency response
X_filtered = X.*tf;
out = ifft(X_filtered,n);
댓글 수: 0
채택된 답변
David Goodmanson
2017년 3월 7일
Hello Nathan, I believe the problem is because the frequency grid contains the point f=0, and your expression for tf comes up with nan at that one point. If you write tf as
tf = 1./(1+j*2*pi*f*r*c); %filter frequency response
you should get better results. (Or find the nan in the first expression and change it to 1).
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!