FFT of discrete time domain data
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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?
답변 (2개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File 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!