Help needed with trying to speed up a script

6 views (last 30 days)
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 Comments
Star Strider
Star Strider on 20 Dec 2016
We will never do your homework for you on MATLAB Answers!

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 20 Dec 2016
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 Comments
Nicholas
Nicholas on 20 Dec 2016
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 on 20 Dec 2016
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!