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);
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!