Help needed with trying to speed up a script
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nicholas
am 20 Dez. 2016
Kommentiert: Star Strider
am 20 Dez. 2016
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
Akzeptierte Antwort
Star Strider
am 20 Dez. 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 Kommentare
Star Strider
am 20 Dez. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Digital Filter Design finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!