Trouble with FFT and plotting velocity data for frequency

13 views (last 30 days)
Hi
I have recently completed an experiment to measure turbulence behind a cylinder ie a Van Karman street. A hotwire was used to gain data and the hotwire (placed downstream) was moved up and down to measure velocities at different vertical positions.
I have multiple sets of data at a specific sample rate and number of samples all for each position as the hotwire is moved. The number of samples being 1024 and sample rate 660. The velocity data was stored in a CSV file which I have coded to be read into an array by MATLAB.
My problem is, I am trying to get the FFT data for these files so that I can show how the frequency peaks vary by the position of the hotwire. I have written some code which produces the FFT but it simply does not look right and I am unsure which part is actually referring to my frequency.
Obviously a FFT produces an imaginary number too and I am getting minus values for magnitude plots which shouldn't be possible? I also get the warning "Warning: Imaginary parts of complex X and/or Y arguments ignored" so was just wondering if anyone can help me out with this one?
clear,clc
a=load('101024660allvels.csv');
%Sample rate
s=1024;
%Creates time data
t=0:1/s:1-1/s;
%Does the transform
b=abs(fft(a));
%Removes erroneous max values
b(1,:) = [0];
%plots
figure;
plot(t,b);
ylabel('Magnitude');
title('Graph for Position 0 Samples 1024, Sample Rate 660','FontSize',12)

Accepted Answer

Star Strider
Star Strider on 19 Nov 2014
Edited: Star Strider on 19 Nov 2014
Your fft should be calculated as:
b=abs(fft(a)/length(a));
and your frequency vector (that I call ‘fv’ here):
fv = linspace(0, 1, length(b)/2+1)*s/2;
iv = 1:length(fv);
. . . CODE . . .
figure;
plot(fv,b(iv));
but otherwise I see no problems with your code.
Attach a representative sample (or all) of '101024660allvels.csv' (use the ‘paperclip’ or ‘staple’ icon) so we can experiment and see if there is anything that could be causing problems.
  4 Comments

Sign in to comment.

More Answers (1)

Chris
Chris on 19 Nov 2014
I have modified the code and I get the attached image. I think this is correct and it gives me a peak frequency! Thank you very much!

Community Treasure Hunt

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

Start Hunting!