How to cut the desired signal?

5 ビュー (過去 30 日間)
Muhammad Hammad Malik
Muhammad Hammad Malik 2022 年 11 月 16 日
編集済み: Muhammad Hammad Malik 2022 年 11 月 17 日
Hello All. I need your guidance on how can i cut the signal and keep my desired signal only. I have a physiological signal. I just want to keep the part of the signal when it goes up and remove the begining and the end of the signal. I am attaching the signal image and the code used to generate it. Could you please guide me how to do this or is there any 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]);
  4 件のコメント
Mathieu NOE
Mathieu NOE 2022 年 11 月 16 日
well , the simplest approach is to define the time boundaries of the valid data to plot
assuming your data are t (time) and y (data), create the logical array idx :
% create dummy data
t = (0:0.25:4)
t = 1×17
0 0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000 2.2500 2.5000 2.7500 3.0000 3.2500 3.5000 3.7500 4.0000
y = zeros (size(t));
y(7:end) = 1-exp(-3*t(1:end-6));
% extract portion between 1.5 and 2.5 s
idx = (t>=1.5 & t <=2.5)
idx = 1×17 logical array
0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0
plot(t,y,'b',t(idx),y(idx),'-*r');
Muhammad Hammad Malik
Muhammad Hammad Malik 2022 年 11 月 16 日
Thanks for the response. i also attached the code above which i am using to generate the signal. Kindly have a look into it.

サインインしてコメントする。

採用された回答

Fangjun Jiang
Fangjun Jiang 2022 年 11 月 16 日
In general,
t=0:0.1:3.5;
signal=0:35;
index=and(t>=1.5, t<=2.0);
new_t=t(index);
new_signal=signal(index);
plot(new_t, new_signal)
  1 件のコメント
Muhammad Hammad Malik
Muhammad Hammad Malik 2022 年 11 月 16 日
編集済み: Muhammad Hammad Malik 2022 年 11 月 17 日
Thanks for the answer. In addition i also attached the code, which i used to generate the signal. can you have a look into this, how i can rewrite. kindly respond. thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by