how can I change my time so that it takes frequency 1/250 hz
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!