Azzera filtri
Azzera filtri

FFT of discrete time domain data

2 visualizzazioni (ultimi 30 giorni)
PK
PK il 4 Lug 2011
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 Commenti
Rick Rosson
Rick Rosson il 4 Lug 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?
PK
PK il 6 Lug 2011
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

Accedi per commentare.

Risposte (2)

Rick Rosson
Rick Rosson il 4 Lug 2011
figure;
plot(abs(X));

Rick Rosson
Rick Rosson il 18 Ago 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

Categorie

Scopri di più su Get Started with Signal Processing Toolbox in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by