FFT issue

3 views (last 30 days)
B T
B T on 3 Mar 2012
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

Accepted Answer

Walter Roberson
Walter Roberson on 3 Mar 2012
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 Comment
B T
B T on 3 Mar 2012
Thank you.

Sign in to comment.

More Answers (2)

B T
B T on 3 Mar 2012
%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 Comments
Walter Roberson
Walter Roberson on 4 Mar 2012
Do you possibly need to fftshift() to get what you are looking for?
B T
B T on 4 Mar 2012
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.

Sign in to comment.


B T
B T on 4 Mar 2012
bump, thanks

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!