% MATLAB code implementation of the synthetic fetal ECG heart rate
% ***************************************************************@
clc
clear all
close all
%% Load the data and constrruct the simulated ta-ECG signals
load 'fECG.mat';
load 'mECG.mat';
% Preprocessing (removing the mean, normalizing by the maximum, removing
% the net noise (60Hz) and median filtering):
fs = 250;
fECG = bsxfun(@minus, fECG, mean(fECG));
fECG = bsxfun(@rdivide, fECG, 0.5*max(fECG));
mECG = bsxfun(@minus, mECG, mean(mECG));
mECG = bsxfun(@rdivide, mECG, 0.5*max(mECG));
notchFilt = fdesign.notch(4,60/(fs/2),1);
Hnotch = design(notchFilt);
fECG(:,2) = filter(Hnotch,fECG(:,2) - medfilt1(fECG(:,2),100));
fECG(:,3) = filter(Hnotch,fECG(:,3) - medfilt1(fECG(:,3),100));
mECG(:,3) = filter(Hnotch,mECG(:,3) - medfilt1(mECG(:,3),100));
% Upsampling the ECG representing the maternal signal by a factor of 4 and
% the ECG representing the fetal signal by a factor of 2 (fECG will be
% approximately 2 times faster than mECG)
mECGrs = resample(mECG(:,3), 4, 1);
fECGrs1 = resample(fECG(:,2), 2, 1);
fECGrs2 = resample(fECG(:,3), 2, 1);
fs = 1000;
% Constructing the ta-ECG signals:
len = 40000; % Number of samples to use in the analysis
sig_range = 1:len;
sig1 = 2*mECGrs(sig_range) - fECGrs1(sig_range);
sig2 = mECGrs(sig_range) - 0.5*fECGrs2(sig_range);
% Plotting Figure 4:
figure('Name','Figure 4');
lx(1) = subplot(2,1,1); plot(0:1/fs:(len/fs-1/fs),sig1,'k','LineWidth',1); xlabel('t [sec]'); ylabel({'Simulated Abdominal' ; 'ECG, lead 1'})
lx(2) = subplot(2,1,2); plot(0:1/fs:(len/fs-1/fs),sig2,'k','LineWidth',1); xlabel('t [sec]'); ylabel({'Simulated Abdominal' ; 'ECG, lead 2'})
linkaxes(lx,'x');
xlim([2,10.1]);
set(gcf,'Position',[800,400,1000,400]);
%% Construct a lagmap of the signal and reference data and construct the ground truth signals
lag = 12;
jump = lag/2;
% Lagmap of the ta-ECG simulated signals:
siglag1 = const_lag( sig1, lag, jump );
siglag2 = const_lag( sig2, lag, jump );
% Reference data lagmaps:
fECGmean = mean( const_lag( fECGrs1(sig_range), lag, jump ), 2);
% fECG values at points that will correspond to the eigenvector points of
% the diffusion maps operators and operators A and S
mECGmean = mean( const_lag( mECGrs(sig_range), lag, jump ), 2);
% fECG values at points that will correspond to the eigenvector points of
% the diffusion maps operators and operators A and S
% Ground truth of fECG beat locations and mECG beat locations:
fECGgt = fECGrs2(sig_range);
fECGgt = fECGgt>1;
fECGgt = sum( const_lag( fECGgt, lag, jump ), 2);
fECGgt(fECGgt>0) = 1;
mECGgt = mECGrs(sig_range);
mECGgt = mECGgt>1;
mECGgt = sum( const_lag( mECGgt, lag, jump ), 2);
mECGgt(mECGgt>0) = 1;
%% Calculate the diffusion maps kernels and eigenvectors
ep = 1;
[ V1, ~, K1 ] = dm( siglag1, ep );
[ V2, ~, K2 ] = dm( siglag2, ep );
%% Constructing the operators S and A and their eigenvectors
S = K1*K2.' + K2*K1.';
A = K1*K2.' - K2*K1.';
[VS, ES] = eigs(S,10);
[~, I] = sort(real(diag(ES)),'descend');
VS = real(VS(:,I));
[VA, EA] = eigs(A,10);
[~, I] = sort(imag(diag(EA)),'descend');
VA = VA(:,I);
%% Plotting Figure 5
fig5( V1, V2, VS, VA, mECGmean, fECGmean )
%% Plotting Figure 6
pltsig1 = mean(siglag1,2); % Signal to plot (length(pltsig1) = length(VA(:,1)))
cmap = [0.75,0.75,0.75; 0,0,0]; % Colormap to use in the plot (black\gray)
x = [(1:length(fECGmean))*jump/fs; (1:length(fECGmean))*jump/fs];
y = [pltsig1(:).'; pltsig1(:).'];
z = zeros(size(y));
c = [double((abs((VS(:,2))).')>1e-2); double((abs((VS(:,2))).')>1e-2)];
figure('Name','ta-ECG colored by a thresholded eigenvector of S')
surface(x,y,z,c,'facecolor','none','edgecolor','flat','LineWidth',2); colormap(cmap);
ax1 = gca;
yl = ax1.YLim;
hold on
line(repmat(find((mECGgt>0).')*jump/fs,10,1),repmat(linspace(yl(1),yl(2),10).',1,sum(mECGgt)),'Color' ,[0.3,0.3,0.3,0.3], 'LineStyle',':','LineWidth',1.5)
xlabel('t [sec]');
set(ax1,'YTick',[])
xlim([12.2,22.2]);
hold off;
set(gcf,'Position',[600,500,1200,250]);
c = [double((abs(imag(VA(:,2))).')>3e-2); double((abs(imag(VA(:,2))).')>3e-2)];
figure('Name','ta-ECG colored by a thresholded eigenvector of A')
surface(x,y,z,c,'facecolor','none','edgecolor','flat','LineWidth',2); colormap(cmap);
ax2 = gca;
yl = ax2.YLim;
hold on
line(repmat(find((fECGgt>0).')*jump/fs,10,1),repmat(linspace(yl(1),yl(2),10).',1,sum(fECGgt)),'Color' ,[0.3,0.3,0.3,0.3], 'LineStyle','--','LineWidth',1)
xlabel('t [sec]');
set(ax2,'YTick',[])
xlim([12.2,22.2]);
hold off;
set(gcf,'Position',[600,200,1200,250]);
linkaxes([ax1,ax2],'xy')
end
没有合适的资源?快使用搜索试试~ 我知道了~
基于matlab实现心率检测
共20个文件
jpg:14个
m:4个
mat:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 2 下载量 159 浏览量
2022-10-12
17:16:01
上传
评论 3
收藏 2.03MB ZIP 举报
温馨提示
1.版本:matlab2019a,不会运行可私信 2.领域:【心电信号】 3.内容:基于matlab实现心率检测 4.适合人群:本科,硕士等教研学习使用
资源推荐
资源详情
资源评论
收起资源包目录
【心电信号】基于matlab实现心率检测 上传.zip (20个子文件)
main.m 5KB
运行结果8.jpg 17KB
运行结果4.jpg 17KB
运行结果3.jpg 17KB
fECG.mat 1.26MB
运行结果9.jpg 19KB
运行结果10.jpg 17KB
运行结果6.jpg 16KB
运行结果11.jpg 17KB
fig5.m 2KB
运行结果1.jpg 55KB
运行结果12.jpg 15KB
mECG.mat 1.26MB
运行结果5.jpg 16KB
运行结果13.jpg 27KB
dm.m 744B
const_lag.m 379B
运行结果2.jpg 55KB
运行结果7.jpg 17KB
运行结果14.jpg 31KB
共 20 条
- 1
资源评论
- angle04052023-04-07怎么能有这么好的资源!只能用感激涕零来形容TAT...
- 2301_771407632024-03-22资源中能够借鉴的内容很多,值得学习的地方也很多,大家一起进步!
天天Matlab科研工作室
- 粉丝: 3w+
- 资源: 7258
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功