How do i only plot last vector

10 Ansichten (letzte 30 Tage)
Gabriel Aguirre
Gabriel Aguirre am 9 Aug. 2022
Kommentiert: Walter Roberson am 9 Aug. 2022
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 Kommentar
Walter Roberson
Walter Roberson am 9 Aug. 2022
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]');

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by