필터 지우기
필터 지우기

FFT from a excel file

조회 수: 4 (최근 30일)
Arnav Dabak
Arnav Dabak 2023년 6월 1일
편집: Star Strider 2023년 6월 1일
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
Mathieu NOE
Mathieu NOE 2023년 6월 1일
what is the type and dimension of channel1Data2 ?
Arnav Dabak
Arnav Dabak 2023년 6월 1일
The dimension of the data is 1000002 x 2,
Column 1 is Time and Column2 is Amplitude.

댓글을 달려면 로그인하십시오.

답변 (2개)

MarKf
MarKf 2023년 6월 1일
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
Arnav Dabak
Arnav Dabak 2023년 6월 1일
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.

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2023년 6월 1일
편집: Star Strider 2023년 6월 1일
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.
.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by