FFT Plot different Vector not same length?

2 次查看(过去 30 天)
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);

采纳的回答

Star Strider
Star Strider 2020-7-28
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 个评论
Alia Hicks
Alia Hicks 2020-7-28
Thanks for your answer.I really appreciate your writing a different few lines of code to try. I did change it to what you suggested and I get the error, "Index exceeds the number of array elements (120000). Error in Julytwentyseventh (line 47) plot(t, f(1:n)), hold on" Do you think it matters that t is being stored as a row (1x600000 double) while my f and fhat and ffilt are stored as colomns and rows (60000x2 double) (complex on the fhat)? If so how do I fix this?
Star Strider
Star Strider 2020-7-28
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by