how to get FFT of the polynomial
1 view (last 30 days)
Show older comments
this is my code below and I tried to repeat it for 3 times so that I have a frequency of repeating so I can have a FFT, but I do not know how to get its FastfourierTransform:
%%%%Initial and final values definition %% qk=[0 2 0 2 0 2]; % Initial position qk1=[2 0 2 0 2 0 ]; % Final position dotqk=[0 0 0 0 0 0]; % Initial velocity dotqk1=[0 0 0 0 0 0]; % Final velocity ddotqk= [0 0 0 0 0 0]; % Initial acceleration ddotqk1= [0 0 0 0 0 0]; % Final acceleration dddotqk= [0 0 0 0 0 0]; % Initial jerk dddotqk1= [0 0 0 0 0 0]; % Final jerk tk= [0 1 2 3 4 5 6 ]; % Initial time tk1=[1 2 3 4 5 6]; % Final time tstep=1000; a=2; b=3;
%% polynomial 3 x3=zeros(4,numel(qk)); v3=zeros(3,numel(qk)); a3=zeros(2,numel(qk)); j3=zeros(1,numel(qk)); position3=zeros(numel(qk),tstep); velocity3=zeros(numel(qk),tstep); acceleration3=zeros(numel(qk),tstep); jerk3=zeros(numel(qk),tstep);
for i=1:numel(qk) x3(:,i)=pol3interpol(tk(i),tk1(i),qk(i),qk1(i),dotqk(i),dotqk1(i)); t(i,:) = linspace(tk(i),tk(i+1),tstep); position3(i,:)=polyval(x3(:,i),t(i,:)); v3(:,i)=polyder(x3(:,i)); velocity3(i,:)=polyval(v3(:,i),t(i,:)); a3(:,i)=polyder(v3(:,i)); acceleration3(i,:)=polyval(a3(:,i),t(i,:)); j3(:,i)=polyder(a3(:,i)); jerk3(i,:)=polyval(j3(:,i),t(i,:)); end
I have writen this code for fft but the result is strange:
% FFT
Fs = 1000; % Sampling frequency Ts = 1/Fs; % Sampling Period T=tk(1):Ts:tk(4)-Ts; L = length(T); % Signal length n = 2^nextpow2(L); f = Fs*(0:(n-1))/n;
% fft of Position position3T=(position3)'; pos3onerow=reshape(position3T,[],1); FFTpos3=fft(pos3onerow,n); abspos3=abs(FFTpos3); subplot(a,b,5) plot(f,abspos3); xlabel('frequency [Hz]') ylabel('|X(f)|') title('FFT of Trajectory Trend') grid on
0 Comments
Answers (0)
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!