필터 지우기
필터 지우기

Help needed with trying to speed up a script

조회 수: 6 (최근 30일)
Nicholas
Nicholas 2016년 12월 20일
댓글: Star Strider 2016년 12월 20일
Hi There,
I have a vector of length 2500 which represents a signal sampled at 250Hz.
I need to obtain the Z transformation of this vector. Unfortunately the code I have at the moment is very slow to run (see below).
Is anyone able to suggest some changes which may make the code quicker?
%%Band Pass Filtering
ECG = load('Testm.mat');
d = designfilt('bandpassiir','FilterOrder',10, ...
'PassbandFrequency1',0.5,'PassbandFrequency2',50, ...
'PassbandRipple',3, ...
'StopbandAttenuation1',40,'StopbandAttenuation2',40, ...
'SampleRate',250);
FD = filter(d,ECG.val(1,:));
fvtool(d,'Fs', 250)
%%Zero Padding
B = padarray(FD,4);
%%Unilateral Z transformation
syms z
l = length(FD)
for i=1:l
z_t(i) = FD(i)/(z^i)
end
sum(z_t)
pretty(ans)
kind regards
Dr. Nic
  댓글 수: 3
Star Strider
Star Strider 2016년 12월 20일
We will never do your homework for you on MATLAB Answers!

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 12월 20일
The z-transform are the transfer function filter coefficients calculated by designfilt. To get them, use the Signal Processing Toolbox tf function, or ‘d.Coefficients’. (I believe these are in terms of z, but you might check to be certain they are not in terms of z^-1.)
As for making the code quicker or faster, design your filter once, if the sampling frequency and frequency content of your other signals don’t change, and save ‘d’ to a ‘.mat’ file. Then load it to your workspace to use it afterwards for other signals in other runs.
There is absolutely no reason to zero-pad your EKG signal! (Pardon me, but that makes absolutely no sense!)
Also, use filtfilt rather than filter. The filtfilt function has a maximally flat phase response, so there will be no delays or phase distortion in the filtered signal.
A passband of 0.5 to 50 Hz will work for normal EKGs, but complex arrhythmias (such as AF) require an upper passband frequency of 100 Hz. If you have 50 Hz or 60 Hz mains frequency interference, you can easily ‘notch-out’ that with a separate FIR filter, or incorporate the notch filter in your bandpass filter. Your choice.
See the documentation on the various functions I mentioned here for information on how best to use them.
  댓글 수: 3
Nicholas
Nicholas 2016년 12월 20일
Sorry Star Strider - if you could clarify something I would appreciate it.
'd.Coefficients’ outputs a 5 by 4 matrix of values. Excuse me if I misunderstand, but when converting to the Z domain I thought one should expect 2500 values (ie, one for each value in the original vector). Where have I made a mistake?
Star Strider
Star Strider 2016년 12월 20일
My pleasure.
The default output for designfilt is the second-order-section implementation (this is desirable for filter stability). Depending on your options, designfilt will produce the transfer function if you want it to.
The tf option should work regardless.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by