FFT issue

조회 수: 4 (최근 30일)
B T
B T 2012년 3월 3일
When I attempt a Fourier Transform of my data, v, all the values of Y are NaN + NaNi
%v(t)
t=-1.5:0.001:1.5; %time, s
B=1.5*pi; %T
f0=20; %Hz
for i=1:length(t);
v(i)=(B*sin(2*pi*f0*t(i)))/(pi*t(i));
end
plot(t,v);
max(v) %Voltage,V
min(v) %Voltage,V
%Fourier Transform
Y=fft(v)
Any clues as to why this is occurring??
Thanks guys

채택된 답변

Walter Roberson
Walter Roberson 2012년 3월 3일
Your time range includes time 0, and your v(i) for time 0 is 0/0 which is NaN. Once you have a NaN in your data, it is going to "pollute" everything else when you do the fft()
  댓글 수: 1
B T
B T 2012년 3월 3일
Thank you.

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

추가 답변 (2개)

B T
B T 2012년 3월 3일
%v(t)
t=-1.5:0.001:1.5; %time, s
B=1.5*pi; %T
f0=20; %Hz
for i=1:length(t);
v(i)=(B*sin(2*pi*f0*t(i)))/(pi*t(i));
end
plot(t,v)
display('Max V')
max(v) %Voltage,V
display('Min V')
min(v) %Voltage,V
%Fourier Transform
t=(0.01*10^-15):0.001:1.5; %time, s
B=1.5*pi; %T
f0=20; %Hz
for i=1:length(t);
v1(i)=(B*sin(2*pi*f0*t(i)))/(pi*t(i));
end
Y=fftn(v1);
f=0:(20/length(Y)):19.9867;
plot(f,Y)
So I am now getting values for the Transform, but the values seem to be almost...inverted. It should look half a square, ending at frequency, f, of 20. But instead it looks flipped, and all values are almost 0 until just before f = 20.
any suggestions?
^similiar to what I'm looking to get
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 3월 4일
Do you possibly need to fftshift() to get what you are looking for?
B T
B T 2012년 3월 4일
Im probably not using it right right now, but I will look into it more tomorrow morning. Thank you though, I think this might lead to the solution.

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


B T
B T 2012년 3월 4일
bump, thanks

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by