FFT of discrete time domain data

2 次查看(过去 30 天)
PK
PK 2011-7-4
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 个评论
Rick Rosson
Rick Rosson 2011-7-4
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?
PK
PK 2011-7-6
1. the size of the data is 512, and it represents discrete time domain continuous signal. That means the samples are taken after 6e-6 sec at each 1e-6 sec time interval.
2. the fft function is called only once at line 4
I have tried plot(abs(x)); it still does not work

请先登录,再进行评论。

回答(2 个)

Rick Rosson
Rick Rosson 2011-7-4
figure;
plot(abs(X));

Rick Rosson
Rick Rosson 2011-8-18
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

类别

Help CenterFile Exchange 中查找有关 Get Started with Signal Processing Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by