I need your guidance on how I can cut the signal and keep my desired part of the signal only. I have a physiological signal. I just want to keep the part of the signal when it goes up (1.5 sec) and stop around 2.5 sec. And remove the beginning and the end of the signal. I am attaching the signal image and the code used to generate it. Could you please guide me on how to do this or is there any Matlab code to do? Looking forward to hearing from you. Thanks
cd 'D:\Research\TFR classification\DATI'
filenames=dir('*.txt');
Fs=500;
TextSize=24;
time_FIF=zeros(1,length(filenames));
for i= 24 %length(filenames)
%% Signal
%close all
fprintf(['\n\n\n *******************************************\n\n'...
' CODICE data set = ' filenames(i).name(1:end-4) '\n\n'...
' We are assuming a sampling rate of 500 Hz\n\n'...
' *******************************************\n\n'])
%% Import data from text file
opts = delimitedTextImportOptions("NumVariables", 25);
% Specify range and delimiter
opts.DataLines = [1, Inf];
opts.Delimiter = "\t";
% Specify column names and types
opts.VariableNames = ["Var1", "Var2", "Var3", "Var4", "Var5", "Var6", "Var7", "Var8",
"Var9", "Var10", "Var11", "Var12", "Var13", "Var14", "Var15", "Var16", "Var17", "Var18",
"Var19", "Var20", "Var21", "Var22", "Var23", "VarName24", "Var25"];
opts.SelectedVariableNames = "VarName24";
opts.VariableTypes = ["string", "string", "string", "string", "string", "string",
"string", "string", "string", "string", "string", "string", "string", "string",
"string", "string", "string", "string", "string", "string", "string", "string",
"string", "double", "string"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, ["Var1", "Var2", "Var3", "Var4", "Var5", "Var6", "Var7", "Var8",
"Var9", "Var10", "Var11", "Var12", "Var13", "Var14", "Var15", "Var16", "Var17", "Var18",
"Var19", "Var20", "Var21", "Var22", "Var23", "Var25"], "WhitespaceRule", "preserve");
opts = setvaropts(opts, ["Var1", "Var2", "Var3", "Var4", "Var5", "Var6", "Var7", "Var8",
"Var9", "Var10", "Var11", "Var12", "Var13", "Var14", "Var15", "Var16", "Var17", "Var18",
"Var19", "Var20", "Var21", "Var22", "Var23", "Var25"], "EmptyFieldRule", "auto");
opts = setvaropts(opts, "VarName24", "DecimalSeparator", ",");
% Import the data
s = readtable(filenames(i).name, opts);
s = table2array(s);
s = s(1420:3358);
%s = s(4.1*Fs:7.4*Fs);
%% Clear temporary variables
clear opts
%%
Fig=figure;
plot((1:length(s))/Fs,s,'k')
xlabel('time (s)')
title(['Signal ' filenames(i).name(1:end-4)])
set(gca,'fontsize', TextSize);
set(Fig,'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
CodePudding user response:
you have plotted
x=(1:length(s))/Fs;
plot((1:length(s))/Fs,s,'k');
So you can use something like this to filter between 1.5 and 2.5 secs
idx = (x>=1.5) & (x<=2.5);
x_cut = x(idx);
s_cut = s(idx);