Clear Filters
Clear Filters

FFT from a excel file

15 views (last 30 days)
Arnav Dabak
Arnav Dabak on 1 Jun 2023
Edited: Star Strider on 1 Jun 2023
I want to compute FFT on a set of data I have recorded.
Here is the code I am using and the error I am getting:
>> xdft = fft(channel1Data2(:,2));
Error using fft
Invalid data type. First argument must be double,
single, int8, uint8, int16, uint16, int32, uint32,
or logical.
  2 Comments
Mathieu NOE
Mathieu NOE on 1 Jun 2023
what is the type and dimension of channel1Data2 ?
Arnav Dabak
Arnav Dabak on 1 Jun 2023
The dimension of the data is 1000002 x 2,
Column 1 is Time and Column2 is Amplitude.

Sign in to comment.

Answers (2)

MarKf
MarKf on 1 Jun 2023
Well, make sure that the data contained in channel1Data2 is numeric (double, single, int8, etc..).
From the question title it seems that it is obtained by reading an Excel file, so likely the format/type has been messed up there. You could change the format to double with for example str2double (if the obtained data type happens to be a string), do check what's in that variable though (famous Excel® issue of converting values to nonsensical dates).
  1 Comment
Arnav Dabak
Arnav Dabak on 1 Jun 2023
I checked the data type and it is double and I am reading it from an excel file.
I have attached a screenshot of the error.

Sign in to comment.


Star Strider
Star Strider on 1 Jun 2023
Edited: Star Strider on 1 Jun 2023
EDIT — (1 Jun 2023 at 16:07)
The array is table apparently created by readtable. Use cell array indexing (explained below) or refer to it as:
xdft = fft(channel1Data2.Ampl);
or:
xdft = fft(channel1Data2.{:,2});
The cell array indexing approaches will also work, so I will leave that part of my original Answer unchanged.
It could be that ‘channel1Data2’ is a cell array. If so, converting it to a numeric array should work —
channel1Data2 = num2cell(rand(10,2))
channel1Data2 = 10×2 cell array
{[0.4233]} {[0.9203]} {[0.8342]} {[0.4878]} {[0.0641]} {[0.7609]} {[0.4819]} {[0.8762]} {[0.2812]} {[0.1188]} {[0.5806]} {[0.8916]} {[0.7699]} {[0.4074]} {[0.9036]} {[0.8791]} {[0.9735]} {[0.3604]} {[0.6840]} {[0.7983]}
xdft = fft(cell2mat(channel1Data2(:,2))); % Use 'cell2mat'
xdft
xdft =
6.5008 + 0.0000i 0.4475 - 0.0261i 0.0448 - 0.2162i 0.3068 + 0.8035i 1.2347 + 0.3965i -1.3651 + 0.0000i 1.2347 - 0.3965i 0.3068 - 0.8035i 0.0448 + 0.2162i 0.4475 + 0.0261i
xdft = fft([channel1Data2{:,2}]).'; % Cell Array Addressing (With Subsequent Transpose)
xdft
xdft =
6.5008 + 0.0000i 0.4475 - 0.0261i 0.0448 - 0.2162i 0.3068 + 0.8035i 1.2347 + 0.3965i -1.3651 + 0.0000i 1.2347 - 0.3965i 0.3068 - 0.8035i 0.0448 + 0.2162i 0.4475 + 0.0261i
xdft = fft(vertcat(channel1Data2{:,2})); % Cell Array Addressing (With 'vertcat')
xdft
xdft =
6.5008 + 0.0000i 0.4475 - 0.0261i 0.0448 - 0.2162i 0.3068 + 0.8035i 1.2347 + 0.3965i -1.3651 + 0.0000i 1.2347 - 0.3965i 0.3068 - 0.8035i 0.0448 + 0.2162i 0.4475 + 0.0261i
xdft = fft(channel1Data2(:,2)); % Numeric Array Addressing Of 'cell' Array (Reproduces The Error)
Error using fft
Invalid data type. First argument must be double, single, int8, uint8, int16, uint16, int32, uint32, or logical.
xdft
So there are several ways to solve this. Choose one.
.

Categories

Find more on Entering Commands in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!