Help needed with trying to speed up a script
5 ビュー (過去 30 日間)
古いコメントを表示
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
採用された回答
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 件のコメント
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 Center および File Exchange で Digital Filter Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!