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 comentario

KSSV
KSSV el 28 de Jul. de 2020
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)

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Jul. de 2020

1 voto

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 comentarios

Alia Hicks
Alia Hicks el 28 de Jul. de 2020
Editada: Walter Roberson el 28 de Jul. de 2020
Thanks for noticing my errors. I've started over. I get the error "Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters." at the second from last line "plot(t,f,); %amp vs time"
dt = .001;
t = 0:dt:1;
f = data_output;
%%Compute the Fast Fourier Transform FFT
n = length(t);
fhat = fft(f,n); % Compute the fast Fourier transform
PSD = fhat.*conj(fhat)/n; % Power spectrum (power per freq)
freq = 1/(dt*n)*(0:n); % Create x-axis of frequencies in Hz
L = 1:floor(n/2); % Only plot the first half of freqs
%%Use the PSD to filter out noise
indices = PSD>100; % Find all freqs with large power
PSDclean = PSD.*indices; % Zero out all others
fhat = indices.*fhat; % Zero out small Fourier coeffs. in Y
ffilt = ifft(fhat); % Inverse FFT for filtered time signal
%%PLOTS
plot(t,f,); %amp vs time
plot(f,fft); % mag vs freq
Walter Roberson
Walter Roberson el 28 de Jul. de 2020
Editada: Walter Roberson el 28 de Jul. de 2020
plot(t,f,); %amp vs time
Why do you have a comma right before the ) ?
Note that you do not appear to have "hold on" in effect, so your second plot() is going to erase the first plot()
Alia Hicks
Alia Hicks el 28 de Jul. de 2020
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 el 28 de Jul. de 2020
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;

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Fourier Analysis and Filtering en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 28 de Jul. de 2020

Comentada:

el 28 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by