FFT Plot different Vector not same length?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alia Hicks
el 28 de Jul. de 2020
Comentada: Star Strider
el 28 de Jul. de 2020
I am not getting any plots from my FFT of a 2X60000 database of the i and q channels of a dobbler radar measuring movment. I recieve "Error using plot Vectors must be the same length. Error in Julytwentyseventh (line 21) plot(t, f), hold on" for the first plot line. I've changed my value of t from t = 0:dt:1, and to t = 0:dt:60000. Same results.
dt = .001;
t = 0:dt:600;
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), hold on
plot (f, fft), hold on
plot (t,ffilt);
0 comentarios
Respuesta aceptada
Star Strider
el 28 de Jul. de 2020
Try this:
plot(t, f(1:n)), hold on
plot (freq(L), fhat(L)), hold on
plot (t,ffilt(1:n));
Note that with no knowldege of ‘f’ or ‘data_output’, writing exact code is not possible.
There may still be problems if there is a discrepancy in the sizes of ‘t’ and ‘f’.
.
2 comentarios
Star Strider
el 28 de Jul. de 2020
Try this:
plot(t(1:min(length(t),length(f))), f(1:min(length(t),length(f)))), hold on
The difference between ‘t’ and the others being row and column vectors should not mattter for the plot function in this instance, although in other situations it definitely would.
Nevertheless, it would be best to transpose ‘t’ to a column vector to avoid potential problems.
Más respuestas (0)
Ver también
Categorías
Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!