FFT of discrete time domain data
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I would appreciate if anyone could help me to figure out the following problem.
I have 512 samples, the samples are taken within 1 microseconds of time interval. I would like to see the signal from 6 microseconds to 5.17e-4 seconds in frequency domain.
I have already tried the following codes in MATLAB, but it only gives me the time-domain representation of signal.
T = 5.17e-4;
N=512;
t=linspace(6e-6,T,N);
X=fft(data);
X = X/N;
dt = t(2)-t(1);
fs=1/dt;
fn=fs/2;
f=linspace(0,fn,length(t)/2);
X1=X(1:length(t)/2);
X1=abs(X1);
plot(f,X1);
I look forward for your reply. Thanks.
2 commentaires
Rick Rosson
le 4 Juil 2011
1. Can you tell me the size of |data| and what type of signal it represents?
2. Why are you calling the |fft| function twice? Why not just once?
Réponses (2)
Rick Rosson
le 18 Août 2011
In the following code, I am assuming that data is predefined as a column vector of size N x 1. If it is a row vector of size 1 x N, then either transpose data or change the first line of the code to take the number of columns instead of the number of rows.
%%Number of samples:
N = size(data,1); % assumes data is an N x 1 column vector
%%Compute the time domain:
Fs = 1e6; % samples per second
dt = 1/Fs; % seconds
t = dt*(0:N-1)';
T = N*dt;
%%two-sided spectrum, centered on DC
X = fftshift(fft(data))/N;
%%Compute the frequency domain:
dF = Fs/N;
f = (-Fs/2:dF:Fs/2-dF)';
%%Plot the time domain signal:
figure;
plot(t,data);
%%Plot the magnitude response:
figure;
plot(f,abs(X));
HTH.
Best,
Rick
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with Signal Processing Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!