How do i only plot last vector

조회 수: 9 (최근 30일)
Gabriel Aguirre
Gabriel Aguirre 2022년 8월 9일
댓글: Walter Roberson 2022년 8월 9일
hi, I'm trying to plot a speed and position fft but when I do the graph it plots all the lines but I just need the last one
clear all;clf;
data = readmatrix('2240.csv');
tempo = data(:,1);
ultima = data(end,1); %%ultimo valor de tempo de coleta
T = ultima; %tempo final da simulação
N = length(tempo); %T*100; %número de pontos entre 0 e T
t = tempo; %linspace(0,T,N);
dt= mean(diff(tempo)); %T/N;
df=1/T; fs=1/dt;
y=data(:,2); %4*sin(2*pi*5*t)+2*sin(2*pi*8*t); %função no tempo em 5Hz e 8Hz amplitudes 4 e 2.
figure(1)
plot(t,y,'b-',t,y,'r');
xlabel('tempo [s]');ylabel('aceleracao [m/s^2]');xlim([0,T])
Ytemp = fft(y-mean(y))/(N/2); %fft(y-mean(y))/(N/2); %FFT
Y=Ytemp(1:floor(N/2));
f= linspace(0,df*(N/2),N/2); %linspace(0,df*(N/2),N/2); 1/(dt*N)*(0:N-1);
figure(2)
subplot(3,1,1)
plot(f,abs(Y));
xlabel('frequencia [Hz]');ylabel('aceleracao [m/s^2]');
%iniciar FFT de velocidade e posição a partir de 1 Hz (denominador de vel e posição não deve ser zero).
inicio = find(f>1,1);
vel = 1000*abs(Y(inicio:end))./(2*pi*f(inicio:end));
subplot(3,1,2)
plot(f(inicio:end),vel);
xlabel('frequencia [Hz]');ylabel('velocidade [mm/s]');
posicao = 1000*abs(Y(inicio:end))./((2*pi*f(inicio:end)).^2);
subplot(3,1,3)
plot(f(inicio:end), posicao);
xlabel('frequencia [Hz]');ylabel('posiçao [mm]');
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 8월 9일
data = readmatrix('2240.csv');
tempo = data(:,1);
ultima = data(end,1); %%ultimo valor de tempo de coleta
T = ultima; %tempo final da simulação
N = length(tempo); %T*100; %número de pontos entre 0 e T
t = tempo; %linspace(0,T,N);
dt= mean(diff(tempo)); %T/N;
df=1/T; fs=1/dt;
y=data(:,2); %4*sin(2*pi*5*t)+2*sin(2*pi*8*t); %função no tempo em 5Hz e 8Hz amplitudes 4 e 2.
Ytemp = fft(y-mean(y))/(N/2); %fft(y-mean(y))/(N/2); %FFT
Y=Ytemp(1:floor(N/2));
f= linspace(0,df*(N/2),N/2); %linspace(0,df*(N/2),N/2); 1/(dt*N)*(0:N-1);
%iniciar FFT de velocidade e posição a partir de 1 Hz (denominador de vel e posição não deve ser zero).
inicio = find(f>1,1);
vel = 1000*abs(Y(inicio:end))./(2*pi*f(inicio:end));
posicao = 1000*abs(Y(inicio:end))./((2*pi*f(inicio:end)).^2);
plot(f(inicio:end), posicao);
xlabel('frequencia [Hz]');ylabel('posiçao [mm]');

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by