how can I change my time so that it takes frequency 1/250 hz

조회 수: 5 (최근 30일)
Manav Divekar
Manav Divekar 2021년 10월 20일
답변: Star Strider 2021년 10월 20일
clc
clear all
close all
C = readtable('G2_adolescent.txt', 'NumHeaderLines',8);
%Convert to SI Units
accG2test = C{:,1}.*9.81;
forceG2test = C{:,2}.*0.00981;
dispG2test = C{:,3}./1000;
% time = dispG2test./accG2test;
forceG2test2 = smoothdata(forceG2test, 'sgolay', 100);
% Valleys Of Smoothed Data
[Vlys,vlocs] = findpeaks(-forceG2test2, 'MinPeakProminence',0.5);
Vlys = [-forceG2test2(1); Vlys];
vlocs = [1;vlocs];
% Sampling Interval
Ts = 1;
t = 1:height(C);
figure
plot(t, forceG2test2)
hold on
plot(t(vlocs), -Vlys, '+r')
hold off
for k = 1:numel(vlocs)-1
% Index Range For This Segment
idx{k} = vlocs(k):vlocs(k+1);
% Time Vector
tc{k} = t(idx{k});
% Signal Segment
sc{k} = forceG2test(idx{k});
end
% Maximum Segment Length
tcmax = max(cellfun(@numel,tc));
% Preallocate
ensb = zeros(tcmax,numel(idx));
for k = 1:numel(idx)
% Create 'Ensemble'
ensb(1:numel(idx{k}),k) = sc{k};
end
figure
% Plot Ensemble
plot(1:tcmax, ensb)
title ('C:Force Vs Time (Cycles)');
legend('1','2','3','4','5','6','7','8','9');
xlabel('Time[sec]');
ylabel('Force[N]');
  댓글 수: 2
Star Strider
Star Strider 2021년 10월 20일
Missing: 'G2_adolescent.txt'
Image Analyst
Image Analyst 2021년 10월 20일
I'm not sure what the question means "how can I change my time so that it takes frequency 1/250 hz". How does a time "take" a frequency? A frequency of (1/250) Hz means the period is 250 seconds. Do you want the x axis to go from 0 seconds to 250 seconds?

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

채택된 답변

Star Strider
Star Strider 2021년 10월 20일
If is the sampling interval, multiply it by the sampling instants to convert them to time —
C = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/773388/G2_adolescent.txt', 'NumHeaderLines',8);
%Convert to SI Units
accG2test = C{:,1}.*9.81;
forceG2test = C{:,2}.*0.00981;
dispG2test = C{:,3}./1000;
% time = dispG2test./accG2test;
forceG2test2 = smoothdata(forceG2test, 'sgolay', 100);
% Valleys Of Smoothed Data
[Vlys,vlocs] = findpeaks(-forceG2test2, 'MinPeakProminence',0.5);
Vlys = [-forceG2test2(1); Vlys];
vlocs = [1;vlocs];
% Sampling Interval
% Ts = 1;
Ts = 1/250; % Define Sampling Interval
t = 1:height(C);
t = t * Ts; % Multiply 't' By 'Ts' To Convert Samples To Time
figure
plot(t, forceG2test2)
hold on
plot(t(vlocs), -Vlys, '+r')
hold off
for k = 1:numel(vlocs)-1
% Index Range For This Segment
idx{k} = vlocs(k):vlocs(k+1);
% Time Vector
tc{k} = t(idx{k});
% Signal Segment
sc{k} = forceG2test(idx{k});
end
% Maximum Segment Length
tcmax = max(cellfun(@numel,tc));
% Preallocate
ensb = zeros(tcmax,numel(idx));
for k = 1:numel(idx)
% Create 'Ensemble'
ensb(1:numel(idx{k}),k) = sc{k};
end
figure
% Plot Ensemble
plot(t(1:tcmax), ensb) % Subscript 't' To Show Time, Not Samples
% plot(1:tcmax, ensb)
title ('C:Force Vs Time (Cycles)');
legend('1','2','3','4','5','6','7','8','9');
xlabel('Time[sec]');
ylabel('Force[N]');
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by