How to trim start and end of time series data?
24 次查看(过去 30 天)
显示 更早的评论
I have 234 points in a signal. I want to trim the start and end of the reconstructed signal i.e. I want to start the signal from 100 and end it at 200. How can I do that in my present signal? Below is my code. Please help
close all; clear all; clc;
X1= [0.978184526233207
1.09489935704680
1.59164669497844
1.04748369986280
0.333456859419425
-0.776374729851942
-1.77654791200448
-1.48977341070183
-1.19560578883582
-0.216216169866790
-0.669130828272027
-0.176959953605121
-0.970038307444731
-1.46480552961072
-1.62008734051190
-0.869510428389788
-0.583273608934337
0.177196159526092
-0.446730619635104
-0.228742243963847
0.203025211047556
0.503354882236360
1.39271941057077
1.64866067380047
1.19038693126125
1.03363708342700
0.424041450386524
0.439260802070332
0.600343029025588
-0.0306738251258923
0.0958539085936714
1.14918362652028
1.15391408947321
0.898540503972080
0.0472213466344582
0.00554562959786900
0.102035244743441
-0.249504759613057
-0.143324794565285
-0.0607968027841552
-0.339183146089067
-0.371455075889551
-0.160251860132050
0.132393073200215
0.938710469108145
0.239353883527975
0.185569511807904
-0.370020642471384
-0.996994900124399
-1.57174260492213
-1.48675651948153
-0.499165159505607
0.000116451587039918
0.246101189551887
0.409185790688870
-0.0313952638414288
-0.213801932159108
0.597498268609943
1.23024780780428
1.50500323997789
1.23638364680667
0.174718173502008
-0.937779454147309
-1.85031898085982
-1.68634602636543
-1.11070366695686
0.171444432824592
0.178524883821887
0.686946348939107
0.405014944526230
0.0489364761057079
-0.253870961209884
-0.187277641813404
-0.442643912693939
-0.653848117914339
-0.760214986268639
-1.31958071983592
-0.992551625949963
-1.48794872511749
-1.33879258050990
-0.856793441452986
-0.394408939345198
-0.589006703594641
-0.274862175225194
0.505079986687640
1.34603779666379
1.76719242084883
1.65796553032041
0.860392149042695
0.184734489994875
-0.791575725714462
-0.833021834564249
-0.233540847901951
0.438051905752895
0.719888942815665
1.06399332034039
0.974754245290287
0.266984272303734
-0.729320359247078
-0.744243620482325
-0.575839769213132
0.0342930803324412
0.431341625822876
1.56474643785566
1.66219038781816
1.07628705674092
0.00960040748809378
-1.26146670726756
-1.52472663287358
-1.26960375489921
-0.888750005807918
-0.320150534790412
1.19137773775656
1.18652374319566
0.757841690371203
-0.0812900199662216
-0.0737080084875141
-0.00367152998326807
-0.593387210797996
-0.740736628261915
-1.58669360678985
-1.54377485379439
-1.84344656563496
-1.15165538472024
-0.315439395511712
0.426080088299539
0.789262136299863
0.825390061142108
0.533927504032497
0.840270169210173
1.07231276429206
0.866660909031804
1.05499421128736
0.544246693106188
0.554892764190835
-0.125091702012162
-0.523958216708689
-0.471186093739212
-0.553505176240973
-0.471307834890186
0.255329511361375
0.443309968999109
0.531847363093168
0.539542288619972
0.531750081585950
0.483862231580577
0.945027379981078
1.16191571414102
0.886509781337565
1.45760913993651
1.74023166218482
1.45663110914463
1.37108609639611
0.927232494902915
0.677582600687758
0.828772608717250
-0.373156343165001
-0.897734171971235
-1.60272592455266
-2.74488192175295
-2.49310365976706
-1.30600932183767
-0.941072129426888
-0.0396666293298666
-0.000401990182564594
-0.747846741547528
-0.680077890685762
-0.345780729985813
0.226661747742711
1.37118037611648
1.27715094683531
0.463525878733334
-1.51526557898599
-2.67957880739113
-2.27925321917559
-1.62970884714424
-0.376263330231145
0.382687307404915
1.52808206930792
1.86628419456866
1.72842389966317
2.18592865006880
1.16364807188454
1.16043750739135
-0.191998864325526
-1.17989059055431
-1.40988398765226
-0.493116315847491
-0.727759810617587
-0.0581583652355533
0.199079551212408
-0.499029369075121
-0.694837778241995
-1.40316718622795
-0.360060349926195
1.07629252223562
2.30376353398820
2.19754776326396
1.82079414479445
1.03315969900616
0.491810249519456
-0.270410080497886
0.135118355485126
-0.101090351581757
-0.409845945421996
-0.839294673539560
-1.67123093873688
-1.48346638597601
-0.410737203021099
0.740659198972951
0.293016252080021
-1.10619719722397
-1.18664316827541
-1.12945427532509
-0.671918631269854
-0.287947673491579
-0.335792016783277
-0.587386687196651
-1.20431179904573
-0.669980798921371
-0.516398365917139
0.394277956967727
1.21512353239220
0.216692421479053
0.101783706338712
0.335111404288256
0.00107923844629068
-0.0104442258803883
0.957259068184531
1.50031210278973
1.84064040172912
0.364645903950982
-0.731000570030488
0.176413750203213];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Addnum1=10;%Num1er of additional data points in each time interval.
N1=Addnum1*length(X1); %Length of the reconstructed signal(the continuous signal);
Rec1=zeros([1,N1]);
Rate1=zeros([1,N1]);
nx1=zeros([1,N1]);
NX1=zeros([1,length(X1)]);
zeroline1=zeros([1,N1]);
index=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:N1
if mod(i,Addnum1)==1
index=index+1;
NX1(index)=i;
end
nx1(i)=i;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:N1
Rec1(i)=0;
Rate1(i)=0;
for j=1:length(X1)
Rec1(i)=Rec1(i)+X1(j)*sinc((1/Addnum1)*(i-Addnum1*(j-1)));
Rate1(i)=Rate1(i)+X1(j)*(cos((pi/Addnum1)*(i-Addnum1*(j-1)))/(i-Addnum1*(j-1))-sin((pi/Addnum1)*(i-Addnum1*(j-1)))/((pi/Addnum1)*(i-Addnum1*(j-1))^2));
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mean_X1=mean(X1);
X1=X1-mean_X1;
mean_Rec1=mean(Rec1);
Rec1=Rec1-mean_Rec1;
figure
plot(nx1,Rec1,'sg');
hold on
plot(nx1,zeroline1,'k');
plot(nx1,Rate1,'*b');
plot(NX1,X1,'or')
legend ('Reconstructed Signal X1','zeroline1','Rate Signal X1','BOLD Signal X1')
0 个评论
采纳的回答
Sulaymon Eshkabilov
2023-3-10
Here is how it can be done using an index option:
X1 = [0.978184526233207
1.09489935704680
1.59164669497844
1.04748369986280
0.333456859419425
-0.776374729851942
-1.77654791200448
-1.48977341070183
-1.19560578883582
-0.216216169866790
-0.669130828272027
-0.176959953605121
-0.970038307444731
-1.46480552961072
-1.62008734051190
-0.869510428389788
-0.583273608934337
0.177196159526092
-0.446730619635104
-0.228742243963847
0.203025211047556
0.503354882236360
1.39271941057077
1.64866067380047
1.19038693126125
1.03363708342700
0.424041450386524
0.439260802070332
0.600343029025588
-0.0306738251258923
0.0958539085936714
1.14918362652028
1.15391408947321
0.898540503972080
0.0472213466344582
0.00554562959786900
0.102035244743441
-0.249504759613057
-0.143324794565285
-0.0607968027841552
-0.339183146089067
-0.371455075889551
-0.160251860132050
0.132393073200215
0.938710469108145
0.239353883527975
0.185569511807904
-0.370020642471384
-0.996994900124399
-1.57174260492213
-1.48675651948153
-0.499165159505607
0.000116451587039918
0.246101189551887
0.409185790688870
-0.0313952638414288
-0.213801932159108
0.597498268609943
1.23024780780428
1.50500323997789
1.23638364680667
0.174718173502008
-0.937779454147309
-1.85031898085982
-1.68634602636543
-1.11070366695686
0.171444432824592
0.178524883821887
0.686946348939107
0.405014944526230
0.0489364761057079
-0.253870961209884
-0.187277641813404
-0.442643912693939
-0.653848117914339
-0.760214986268639
-1.31958071983592
-0.992551625949963
-1.48794872511749
-1.33879258050990
-0.856793441452986
-0.394408939345198
-0.589006703594641
-0.274862175225194
0.505079986687640
1.34603779666379
1.76719242084883
1.65796553032041
0.860392149042695
0.184734489994875
-0.791575725714462
-0.833021834564249
-0.233540847901951
0.438051905752895
0.719888942815665
1.06399332034039
0.974754245290287
0.266984272303734
-0.729320359247078
-0.744243620482325
-0.575839769213132
0.0342930803324412
0.431341625822876
1.56474643785566
1.66219038781816
1.07628705674092
0.00960040748809378
-1.26146670726756
-1.52472663287358
-1.26960375489921
-0.888750005807918
-0.320150534790412
1.19137773775656
1.18652374319566
0.757841690371203
-0.0812900199662216
-0.0737080084875141
-0.00367152998326807
-0.593387210797996
-0.740736628261915
-1.58669360678985
-1.54377485379439
-1.84344656563496
-1.15165538472024
-0.315439395511712
0.426080088299539
0.789262136299863
0.825390061142108
0.533927504032497
0.840270169210173
1.07231276429206
0.866660909031804
1.05499421128736
0.544246693106188
0.554892764190835
-0.125091702012162
-0.523958216708689
-0.471186093739212
-0.553505176240973
-0.471307834890186
0.255329511361375
0.443309968999109
0.531847363093168
0.539542288619972
0.531750081585950
0.483862231580577
0.945027379981078
1.16191571414102
0.886509781337565
1.45760913993651
1.74023166218482
1.45663110914463
1.37108609639611
0.927232494902915
0.677582600687758
0.828772608717250
-0.373156343165001
-0.897734171971235
-1.60272592455266
-2.74488192175295
-2.49310365976706
-1.30600932183767
-0.941072129426888
-0.0396666293298666
-0.000401990182564594
-0.747846741547528
-0.680077890685762
-0.345780729985813
0.226661747742711
1.37118037611648
1.27715094683531
0.463525878733334
-1.51526557898599
-2.67957880739113
-2.27925321917559
-1.62970884714424
-0.376263330231145
0.382687307404915
1.52808206930792
1.86628419456866
1.72842389966317
2.18592865006880
1.16364807188454
1.16043750739135
-0.191998864325526
-1.17989059055431
-1.40988398765226
-0.493116315847491
-0.727759810617587
-0.0581583652355533
0.199079551212408
-0.499029369075121
-0.694837778241995
-1.40316718622795
-0.360060349926195
1.07629252223562
2.30376353398820
2.19754776326396
1.82079414479445
1.03315969900616
0.491810249519456
-0.270410080497886
0.135118355485126
-0.101090351581757
-0.409845945421996
-0.839294673539560
-1.67123093873688
-1.48346638597601
-0.410737203021099
0.740659198972951
0.293016252080021
-1.10619719722397
-1.18664316827541
-1.12945427532509
-0.671918631269854
-0.287947673491579
-0.335792016783277
-0.587386687196651
-1.20431179904573
-0.669980798921371
-0.516398365917139
0.394277956967727
1.21512353239220
0.216692421479053
0.101783706338712
0.335111404288256
0.00107923844629068
-0.0104442258803883
0.957259068184531
1.50031210278973
1.84064040172912
0.364645903950982
-0.731000570030488
0.176413750203213];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Range = 100:200;
X1 = X1(Range); % Range
Addnum1=10;%Num1er of additional data points in each time interval.
N1=Addnum1*length(X1); %Length of the reconstructed signal(the continuous signal);
Rec1=zeros([1,N1]);
Rate1=zeros([1,N1]);
nx1=zeros([1,N1]);
NX1=zeros([1,length(X1)]);
zeroline1=zeros([1,N1]);
index=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:N1
if mod(i,Addnum1)==1
index=index+1;
NX1(index)=i;
end
nx1(i)=i;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:N1
Rec1(i)=0;
Rate1(i)=0;
for j=1:length(X1)
Rec1(i)=Rec1(i)+X1(j)*sinc((1/Addnum1)*(i-Addnum1*(j-1)));
Rate1(i)=Rate1(i)+X1(j)*(cos((pi/Addnum1)*(i-Addnum1*(j-1)))...
/(i-Addnum1*(j-1))-sin((pi/Addnum1)*(i-Addnum1*(j-1)))/((pi/Addnum1)*(i-Addnum1*(j-1))^2));
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mean_X1=mean(X1);
X1=X1-mean_X1;
mean_Rec1=mean(Rec1);
Rec1=Rec1-mean_Rec1;
figure
plot(nx1,Rec1,'sg');
hold on
plot(nx1,zeroline1,'k');
plot(nx1,Rate1,'*b');
plot(NX1,X1,'or')
legend ('Reconstructed Signal X1','zeroline1','Rate Signal X1','BOLD Signal X1')
axis tight
0 个评论
更多回答(2 个)
Arka
2023-3-10
Hi,
You can use array subscripting using the colon operator to achieve what you require.
In general, if you want to extract data from ith index to jth index, you can achieve that by doing so:
extracted = array(i:j);
So, in your case, to get the data from 100th index to 200th index, you can do:
extracted = Rec1(100:200);
If you wish to learn more about the colon operator, please go through the MathWorks documentation link below:
0 个评论
Sarvesh Kale
2023-3-10
If you only want the reconstructed signal to start from 100th index to 200 index juts use indexing for that, from your code I think Rec1 is the reconstructed signal, example code
x1 = Rec1(100:200); % get entries from 100 to 200
t = nx1(100:200) ;
plot(nx1,Rec1)
I hope I understood your question and this helps your query
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!