1
%-------------------------------------------------------------------

% Function to Generate ECG of 1 heart beat signal

function [Heartbeat,t1] = ECG_Gen (HR,pulse_width,Amp)

Fs = 48000;

delay = ((60/HR)/2)-(0.5*pulse_width);

t1 = -delay:(1/Fs):delay;

Heartbeat = Amp*tripuls (t1,pulse_width);

%-------------------------------------------------------------------
%Test Circuit configuration

function [FECG_MECG,Mixed_ECG,fastTime] = Test_Circuit (FHR,MHR)

Fs = 48000;
%FHR = 150;
%MHR = 60;
Fpulse_width = 30e-3;
Mpulse_width = 60e-3;
FAmp = 0.2;
MAmp = 0.5;

% Fetal ECG Gen
%------------------------------------------------

[FECG,FHR_Delay]= ECG_Gen (FHR,Fpulse_width,FAmp);

% Maternal ECG Gen
%------------------------------------------------

[MECG,MHR_Delay]= ECG_Gen (MHR,Mpulse_width,MAmp);

% Composite signal implementation
%------------------------------------------------

% Set parameters for Composite signal Algorithms

if length (MECG) > length (FECG)        % Check for time sequences for both ECG signal
    slowECG = FECG;                     % Set interpolation to slower rate
    fastECG = MECG;
    timeSeg = length(MECG);
    fastTime = MHR_Delay;               % Set sampling times
    slowTime = FHR_Delay;    
else 
    slowECG = MECG;
    fastECG = FECG;
    timeSeg = length(FECG);
    fastTime = FHR_Delay;              
    slowTime = MHR_Delay;
end

FECG_MECG = zeros (timeSeg,2);    % To hold stereo output

FECG_MECG(:,2) =  fastECG(1,:);        % Assign higher rate signal to one channel

% Interpolation on the slower rater sampled ECG

slowECGInterp = interp1 (slowTime,slowECG,fastTime);

slowECG = num2cell(slowECGInterp);          % Conversion to cell Array in order to remove NaN

slowECG(cellfun(@(slowECG) any(isnan(slowECG)),slowECG)) = [];

slowECG = cell2mat(slowECG);

j = 1;

for i = 1:timeSeg

    FECG_MECG(i,1) =  slowECG(1,j);   

     if j == length(slowECG)
         j = 0;
     end     

    j = j+1; 
end

Mixed_ECG  =  FECG_MECG(:,1) + FECG_MECG(:,2);      % to hold mono output






 %while (1)
  %sound(Mixed_ECG ,Fs);
%end

%-------------------------------------------------------------------
% Test Wave script

clear all
%clc
clc
Fs = 48000;

%for i = 1:3
%toc

MHR = 60;
FHR = 200;

% Obtain ECG interpolated signal and composite
[FECG_MECG,Mixed_ECG,fastTime] = Test_Circuit (FHR,MHR);

% for test purposes
[MECG,MHR_Delay]= ECG_Gen (60,60e-3,0.5);

%t = timer ('TimerFcn','stat=false','Period',2.0);
wavwrite (FECG_MECG(:,2),Fs,'ECGwav.wav');
i = 0;
a = 1;
tic
while (1)

while (toc < 20*a)

sound (MECG,Fs);

end
toc
a = a+1;
[MECG,MHR_Delay]= ECG_Gen (60*a,60e-3,0.5);

if a > 4
    break
end

end

%start(t)
%tic
%t = cputime;

%y = wavread('ECGwav.wav');


%while (1)
%    sound(y,Fs);
%end
%toc

嘿,非常感谢您回复我,我已经使用了您的插值,但从监视器获得的读数仍然存在一些小问题。首先,假设我有一个固定时间段的恒定信号,比如 0.8 秒,我想添加 0.3 秒的复合信号,我已经设法使用你的插值方法以我 0.8 的速率对 0.3 秒的信号进行采样s 信号。我想我已经解决了这个问题。第二个问题涉及如何组合我设法以某种方式完成的两个信号,但是当我使用 while 循环来重复复合信号时说超过 20 秒,从声音输出中获得的信号并不完全符合我的预期,因为它探测存储的复合信号数组,其中包含(0.8s 的信号 = 0.3s 的 slowInterp 信号)。我已经包含了所有的代码和功能。基本上,

4

1 回答 1

0

很难准确说出您需要什么,但可能对以较慢速率采样的序列进行插值对您的应用程序有用。

如果t1s是您的较快序列中的时间,并且是t2s较慢序列中的时间,并且slow是您较慢的序列,那么请执行以下操作:

slowInterp = interp1(t2s, slow, t1s);

现在您将以slow更快的速度对序列进行采样。

这仅对显示时间序列有用。如果您正在进行任何光谱分析,这将引入伪影,但这是一个更高级的主题。

使用resample信号处理工具箱中的功能也很有用。

于 2013-06-28T19:14:53.713 回答