Matlab (fft)

  • MATLAB
  • Thread starter RAYINDASKY
  • Start date
  • #1
I have data in excel file and want to convert that to frequency domain. I wrote the following code but its giving me the wrong results.

If my data is 2,2,2,5,5,6
Shouldn't

Amplitude =2 and frequency =3
Amplitude =5 and frequency =2
Amplitude =6 and frequency =1




%Read in the data
data = xlsread('time.xls');

%Analyze the frequency components.
y=2*abs(fft(data))/length(data);
%Plot frequency versus frequency componant magnitude, circle f_max
figure
plot(x,y)
xlabel('Frequency (Hz)')
ylabel('Amplitude ')
title('Frequency Domain ')
 

Answers and Replies

  • #2
marcusl
Science Advisor
Gold Member
2,768
419
You are confusing Fourier transforms with histograms. You are asking for the number of occurrences in your data of each value, which has absolutely nothing to do with FFT's. Instead use Matlab's hist command:

data = [2,2,2,5,5,6];
N = length(data);
y = hist(data,N)
bar(1:N,y)
 

Related Threads on Matlab (fft)

  • Last Post
Replies
0
Views
3K
  • Last Post
Replies
12
Views
5K
  • Last Post
Replies
2
Views
4K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
10
Views
5K
Replies
0
Views
4K
Replies
11
Views
2K
  • Last Post
Replies
1
Views
18K
Replies
1
Views
2K
Replies
4
Views
10K
Top