FFT Plot different Vector not same length?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Alia Hicks
il 28 Lug 2020
Commentato: Star Strider
il 28 Lug 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 Commenti
Risposta accettata
Star Strider
il 28 Lug 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 Commenti
Star Strider
il 28 Lug 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!