fft error in function?

조회 수: 9 (최근 30일)
Alia Hicks
Alia Hicks 2020년 7월 28일
댓글: Walter Roberson 2020년 7월 28일
data_output is a 60000x2 matrix.
Concerning line the line that is highlighted with arrows, "fhat = fft(f,n);", I keep recieving "Error using fft
Invalid data type. First argument must be double, single, int8, uint8, int16, uint16, int32,uint32, or logical.".
What can I do to make the code function? Are either t or f that is the problem?
dt = .001;
t = 0:dt:1;
f = 'data_output(:1)';
figure;
plot(t,ffilt); ",
dt = .001;
%dt = 0.00001666667;
t = 0:dt:1;
f = 'data_output(:1)';
figure;
plot(data_output)
xlabel('time(s)');
ylabel('Amplitude');
grid on
%% Compute the Fast Fourier Transform FFT
n = length(t);
----------------------------- >>>fhat = fft(f,n); <<< ------------------------
PSD = fhat.*conj(fhat)/n;
freq = 1/(dt*n)*(0:n);
L = 1:floor(n/2);
figure;
dim = 2;
plot(f,fhat,2); % FFT plot
xlim([0 1]);
xlabel('Frequency(Hz)');
ylabel('FFT Magnitude');
grid on
%% USe the PSD to filter out noise
indices PSD>35000;
PSDclean = PSD.*indices;
fhat = indices.*fhat;
ffilt = ifft(fhat);
figure;
plot(t,ffilt);
  댓글 수: 1
KSSV
KSSV 2020년 7월 28일
What for is this line?
f = 'data_output(:1)';
I guess it should be
f = data_output(:,1);
Isn't it? In your case what is
class(f)

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

채택된 답변

Walter Roberson
Walter Roberson 2020년 7월 28일
f = 'data_output(:1)';
That is a character vector. You cannot fft() a character vector.
If you need to apply fft to the ASCII codes that are used for the letters 'd' 'a' 't' and so on, then fft(double(f), n) . I would, however, suggest that it is very unlikely that is what you want, and that instead your line should be something closer to
f = data_output(:,1);
where data_output would be replaced by the name of the variable whose first column you want to extract.
plot(t,ffilt); ",
ffilt is not defined at that point.
You have a stray double-quote on that line.
plot(f,fhat,2); % FFT plot
When you use more than one numeric input to plot(), then you must have an even number of numeric inputs.
dim = 2;
That line hints that the 2 in your plot might refer to the second dimension, but your fhat looks like it will be a vector so it does not appear that giving the dimension would be useful.
If you are expecting that f or fhat are 2D arrays, then some of your other lines will have problems.
indices PSD>35000;
There is no MATLAB function named indices to invoke on the character vector 'PSD>35000' . I would suspect
indices = PSD>35000;
  댓글 수: 4
Alia Hicks
Alia Hicks 2020년 7월 28일
That comma was an error. I'm using hold on now.
plot(t,f), hold on
plot (f,fft);
Error recieved, "Error using plot Vectors must be the same length. Error in Julytwentyseventh (line 21)
plot(t,f), hold on"
Walter Roberson
Walter Roberson 2020년 7월 28일
What is size(data_output) ?
Is there a reason that you are making your number of samples for your time different than the number of data points you have? I would think it more likely that you should define
n = length(data_output);
dt = 0.001;
t = (0:n-1) * dt;

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by