%---------------------------------------------spectral analysis
%use resampling RR interval
clear all;close all;
dat=load('D:\toolbox\matlab\hc03-01.txt');fs=2;
dat=1000*dat;% convert to ms
figure(1); plot(dat);
%select data segment
%----------------------
p_num=2;
figure(2);plot(dat);hold on;
for j=1:p_num
[x_j,y_j]=ginput(1);plot(x_j,y_j,'r+','linewidth',2);hold on;x(j)=x_j;y(j)=y_j;
end;
x=round(x);
d=dat(x(1):x(2));
%-------------- removeartifacts
thr=150; % choose thresholdremove artifact
num_mean=60*2; % number of data points for calculating local mean
conti_num=10*2;
[ind_remove,d1]=remove_artifact_BF(d,num_mean,conti_num,thr);
close all; figure(1);subplot(2,1,1);plot(d);holdon;plot(ind_remove,d(ind_remove),'or');
subplot(2,1,2);plot(d1);
%-------------------------------- psd
fs=2;nfft=256;window=hanning(256);[p,f]=psd(d1,nfft,fs,window,128,'linear');
figure(2)
plot(log2(f),p,'+-');f_bound=[0.04,0.15,0.4];f_y=[0,0,0];
holdon;plot(log2(f_bound),f_y,'or');hold on;