MATLAB Answers

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

1 view (last 30 days)
Manav Divekar on 20 Oct 2021
Answered: Star Strider on 20 Oct 2021
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 CommentsShowHide 1 older comment
Image Analyst on 20 Oct 2021
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?

Sign in to comment.

### Accepted Answer

Star Strider on 20 Oct 2021
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 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!

Translated by