All you need to know is the time difference Ts between y(n) and y(n+1) where y is the data for which you are taking fft. Inverse of Ts is your sampling frequency fs. For fft you should use uniform sampling. So if you use tspan=[0:0.01:80] your fs=1/0.01. Navan --- mmg1928 <> wrote: > Hi, > I have a question on Power Specturm using fft . I am > using ode45 to > solve two second order Ordinary Differential > Equations. A part of my > program is : > > N > Yo=[zeros(N,1);zeros(N,1);zeros(N,1);zeros(N,1)];% > initial conditions > options =odeset('RelTol', 1e-4, 'AbsTol' , 1e-7); > to=0; tf; %initial time and final time > tspan=[to ; tf]'; > [t,Ys] = ode45(@fun1,tspan,Yo,options); > Y=Ys(:,N) > > % Find next highest power of 2 greater than or equal > to length(Y): > N =2.^(ceil(log(length(Y))/log(2))); > FFTY = fft(Y,N);% Take fft, padding with zeros, > length(FFTY) > NumUniquePts = ceil((N+1)/2); > FFTY = FFTY(1:NumUniquePts);% fft is symmetric, > throw away second half > Pyy = conj(FFTY).*FFTY / N; > > %HOW DO I FIND THE SAMPLING FREQUENCY(fs) TO BE USED > IN THE NEXT > LINE > f=(0:NumUniquePts-1)*2*fs/N; > plot(f,Pyy(1:N/2+1)) > I want to plot the power spectrum of Y and I am > using a Matlab code > using fft to calculate the fast fourier transform.I > am not very sure > how do I select the sampling frequency(fs) to plot > the graph. Could > you give me some suggestions.Would tspan affect the > sampling frequency > (fs) for the power spectrum? If I change > tspan=[0:0.01:80](uniform > interval), will it be helpful in any way to > calculate power spectrum. > Any kind of help is greatly appreciated. > > Thanks & Regards, > MMG __________________________________ |