FFT issue

1 次查看(过去 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()

更多回答(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

Community Treasure Hunt

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

Start Hunting!

Translated by