You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Average of Wave from 10 waves in single graph
15 views (last 30 days)
Show older comments
Hello Everyone,
I have a doubt concerning the average of the wave from a set of waves from sinlge dataset. I need to get a single average curve from all the curves from the figure. I am new to matlab and can not figure it out and have not been able to do so for a long time. I need you to help and it would be great for me. Thanks in advance.
3 Comments
Jan
on 20 Nov 2019
Please calm down. Posting a question twice will confuse the ones who want to help you and maybe waste their time, when they type an answer, which has been given already. Therefore I have cleaned up your identical former question.
You cannot expect the voluntary helpers to post an answer in some minutes. Mentioning, that the problem is "urgent" is counterproductive. See: https://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
There is only one curve in the image, so asking for an average is not meaningful. I guess, you mean that te curve is almost periodic and you want an average period. Then please explain, what the inputs are. It is easier to suggest a matching code, if we do not guess tis detail.
Lokeswara reddy pamulapate
on 20 Nov 2019
I have the data attched to this. Actually it is the wave of radial artery bloop pressure wave. I want to take the average of all the data to get one average curve from those data.
Accepted Answer
Star Strider
on 20 Nov 2019
Try this:
D = load('P_191005_000.mat');
ap = D.b;
Ts = 1E-3; % Assume Sampling Interval
tv = linspace(0, 1, numel(ap))*Ts; % Create Time Vector
[pks, locs] = findpeaks(-ap, 'MinPeakDist',250, 'MinPeakHeight',-85 ); % Determine Peaks & Indices
figure(1)
plot(tv, ap)
hold on
plot(tv(locs), -pks, '+r')
hold off
grid
for k1 = 1:numel(locs)-1
apc{k1} = ap(locs(k1):locs(k1+1)); % Define Frames
tvc{k1} = tv(locs(k1):locs(k1+1));
len(k1) = numel(locs(k1):locs(k1+1));
end
enstrim = cellfun(@(x)x(1:min(len)), apc, 'Uni',0); % Trim Records To Shortest Length
ensavg = mean([enstrim{:}],2); % Ensemble Average
figure(2)
hold all
for k1 = 1:numel(apc)
plot(tvc{k1}-tvc{k1}(1), apc{k1}) % Plot Frames
end
plot(tv(1:numel(ensavg)), ensavg.', '-r', 'LineWidth',2)
hold off
grid
producing:
31 Comments
Lokeswara reddy pamulapate
on 20 Nov 2019
ThankYou very much. It's working.
I am really thankful to you.
Lokeswara reddy pamulapate
on 22 Nov 2019
Hi I have data of aorata, in which I want to remove the noise and identify the pe
aks and interference. After that I want to separate the each cycles
from starting point of peak to the end of the peak for total signal present.
Can you please help me how to proceed on.
Thank you very much for your time.
Star Strider
on 22 Nov 2019
I can clean that up to an extent, however you need to do the rest of the processing, then use my posted code to do the ensemble averages. You will need to make some choices as to what constitutes valid data, and correct for what appears to me to be significant arrhythmias. The arrythmias are going to make it very difficult to do a reliable ensemble average.
Preprocessing —
D = load('16Zi239231227Z11201Z0Z0Z0');
sig = D.column1(:,1);
Fs = 1;
Ts = 1/Fs;
Fn = Fs/2;
L = size(sig,1);
sigm = sig - mean(sig);
FTsig = fft(sigm)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTsig(Iv))*2)
grid
xlim([0 0.025])
siglpf = lowpass(sig, 0.003, Fs); % Lowpass Filter
[pks1,locs1] = findpeaks(siglpf, 'MinPeakHeight',100, 'MinPeakDistance',250);
[pks2,locs2] = findpeaks(siglpf, 'MinPeakHeight',170);
pks = setdiff(pks1,pks2);
locs = setdiff(locs1,locs2);
tv = 0:(L-1); % Time Vector
figure
plot(tv, siglpf)
hold on
plot(tv(locs), siglpf(locs), '+r')
hold off
grid
xlim([locs(1) L])
To eliminate the leading zero values and transients, select the signal as ‘((locs(1)-100):end)’. Lacking a true time vector of sampling times means that you can only get approximate statistics.
To see a representative sample of the filtered signal, use this xlim call:
xlim([locs(1)-100 locs(10)+160])
The filter passband appears to be appropriate, so there is no need to change it.
Experiment to get different results.
Lokeswara reddy pamulapate
on 22 Nov 2019
Ya it is working, with it. I will clean the rest and how can we divide the each wavefrom starting of the peak to the end of the peak in total signal.
I am really thankfull to you.
Lokeswara reddy pamulapate
on 23 Nov 2019
Caan you please help me with: how to seperate each curve in the signal. I want to seperate the each signals in the total output. This is my final research in my university please can you help me. I am learning matlab and dont have time for my research I should submit by this month end. Please help me with this cleaning the data and seperating the each curve. I have around 500 patients to carry out with this data. Please help me with some code.
Star Strider
on 23 Nov 2019
@Lokeswara reddy pamulapate — I looked at those files when you posted them in your other Question. They are so corrupted with noise that I could not recover them with a frequency-selective filter.
@Jan — Thank you!
Lokeswara reddy pamulapate
on 25 Nov 2019
How can we do that any examples? It is too tough to get the outputs please let me know.
Thank you
Lokeswara reddy pamulapate
on 25 Nov 2019
@Jan - I was asking for help beacuse I dontknow Matlab and till now I was doing it with machine learning my univeristy said I have to carry out this in Matlab beacuse of patients data. Beacuse of that issue I was asking to help me. Please try to understand.
Lokeswara reddy pamulapate
on 25 Nov 2019
@Star Strider Please help me how to proceed on. I really need your help. Please understand my situation. after this step i need to go on with biomarkers and correlate the models I have and implement it in Machine learning.
It would be graet and it means a lot to me with your help and suggetions.
Thankyou very much for you help.
Star Strider
on 25 Nov 2019
@Lokeswara reddy pamulapate — I wish I could. You may need to consult with signal processing professors at your university to see if they have any ideas on how best to extract useful information from your signals.
Unlike the file you initially presented here, there is nothing in these files that look to me like a pulse waveform. (I am a Board Certified Internal Medicine physician and biomedical engineer, and I cannot figure out a way to salvage those data.)
You may need to look very carefuly at your instrumentation, since that is quite likely at least part of the problem (and perhaps the entire problem), then repeat those studies.
(Parenthetically, in your original radial pulse waveform, I do not see a dicrotic notch. It should be present, since it is present in fingertip pulse plethysmograms of healthy individuals. It would appear that the subject as aortic insufficiency.)
Lokeswara reddy pamulapate
on 25 Nov 2019
Edited: Lokeswara reddy pamulapate
on 25 Nov 2019
It is aorata wave data. It is not radial artery data. those data are collected with other sensors, because of that the data not proper. Can you tell what chenges should I make in the code povided by you to get good results.
Star Strider
on 25 Nov 2019
I remember thet the new data are aortic waveforms and the initial data were radial artery waveforms. The radial artery waveforms appeared to be correct, although the pressures may require checking.
The problem is that there is something wrong with the aorta data, and I cannot figure out what the problem is. Something in the instrumentation is creating unusable data, whether it is bubbles in the transducer or problems with the catheter, or something else. If you know what the problem is, there might be a way to salvage the correct waveforms from those data, however in the absence of that information, there is not. The amplitudes are also suspicious. You will most likely have to abandon those data if you cannot figure out what the problem is so that some method of recovering the correct waveforms is possible. The aorta data are currently unusable.
When you collect new data, first be absolutely certain that the entire system is bubble-free, that the transducers are correctly calibrated and in the correct position relative to the subject, and that you have at least one recording of an impulse and step or square-wave input with the recorded inputs and outputs. This will allow you to correct for any nonlinearities and other problems in the physiological data you collect. It may also be necessary to put diluted heparin in the catheter fluid to prevent the catheter tip from clotting.
Lokeswara reddy pamulapate
on 25 Nov 2019
Edited: Lokeswara reddy pamulapate
on 26 Nov 2019
when calling the fuction of BP_annotate.m
I am getting these error can anyone help me?
using the function of BP_annotate how can I use this function in
- 16Zi239231227Z11201Z0Z0Z0.mat file
Thanks in advance
>> BP_annotate
Annotating blood pressure...
Not enough input arguments.
Error in BP_annotate (line 75)
inWaveform = inWaveform(:);
Star Strider
on 26 Nov 2019
You have not shown your code that calls ‘BP_annotate.m’.
In the files you have posted thus far, there were never any corresponding time vectors that would permit plotting the signals as functions of time, and from which the sampling interval could be computed and the sampling frequency could be estimated. I suspect you are not providing ‘inFs’ to ‘BP_annotate’ either.
Lokeswara reddy pamulapate
on 27 Nov 2019
The code you have provided previously uses low pass filter can we try with bandpass filter
Star Strider
on 27 Nov 2019
Yes.
Change the lowpass call to bandpass, and provide the lower and upper passband frequencies. See the documentation on bandpass for details. Use the Fourier transform in figure(1):
figure
plot(Fv, abs(FTsig(Iv))*2)
grid
xlim([0 0.025])
to select your frequencies of interest for the filter. (Change the xlim limits as necessary to view the appropriate range. I woukd keep it in the code because it allows you to ‘zoom’ in on an appropriate range of frequencies.)
Lokeswara reddy pamulapate
on 9 Dec 2019
@Star Strider I have data of aorta signals of patients in which I have to remove the noise which is present in the middle of the signals. I want a clean signal in which I should identify systolic peaks, diastolic peaks and so on (for this I have a function to identify). Can anyone help me out to remove or delete permanently the noise from the existing signal? I want to remove the gaps in the signal and there are some huge peaks lines that I want to remove as well.
Thank you for your help and your time.
I appreciate the help.
Please help me
Please
Lokeswara reddy pamulapate
on 10 Dec 2019
Please help me I could not figure it out how to move on from here. I am trying many codes and could not find out the solution. I used fft on my data but it is not showing the mirror image also. I am strucked and tried many ways but could not figure it out. Please help me to find the solution. As you are some experts in matlab you can help me to find solution which will help me a lot.
Thankyou.
Star Strider
on 11 Dec 2019
This shouldl get you started:
D = load('2023Zi1410Zi2520112201227Z11201Z0Z0Z0.mat');
Ao = D.x;
t = linspace(0, numel(Ao), numel(Ao));
[Syspks,Syslocs] = findpeaks(Ao, 'MinPeakDistance', 150, 'MinPeakHeight',150); % Systolic Peak
[Dcntch,Dcnlocs] = findpeaks(-Ao, 'MinPeakDistance', 50, 'MinPeakHeight',-150); % Dicrotic Notch
[Dispks,Dislocs] = findpeaks(-Ao, 'MinPeakDistance', 150, 'MinPeakHeight',0); % Systolic Peak
Dcnlocs = Dcnlocs(Ao(Dcnlocs)>0);
figure
plot(t, Ao)
hold on
plot(t(Syslocs), Syspks, '^r')
plot(t(Dcnlocs), Ao(Dcnlocs), 'vg')
plot(t(Dislocs), Ao(Dislocs), 'vk')
hold off
grid
xlim([0 5000])
legend('Trace','Systolic Peaks', 'Dicrotic Notch', 'Diastolic Nadir', 'Location','best')
I identified and plotted the systolic peak, the dicrotic notch, and the diastolic trough for the first 5000 sampling points in this code. That will not work for the entire trace, since the pulse pressure appears to change significantly after the intial 60K samples, and the trace is also discontinuous.
The signal is actually not very noisy, as this Fourier transform demonstrates:
L = numel(Ao);
Fs = 1;
Fn = Fs/2;
Aom = Ao - mean(Ao);
FTAo = fft(Ao)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTAo(Iv))*2)
grid
xlim([0 0.0001])
I must defer to you to deal with the discontinuities. This is not a reliable trace because of the discontinuities and the wide variation in the absolute pressures and the pulse pressure, so any inferences you get from it are likely to be unreliable.
Lokeswara reddy pamulapate
on 11 Dec 2019
Edited: Lokeswara reddy pamulapate
on 11 Dec 2019
@Star Strider I am really very thankfull to you. For identifying the systolic peaks and diastolic peaks I have a function and is working perfectly. The code which you have provided is working as well but not for entire signal as you told. The main problem is to delete the noise which is present in the signal. I have tried to delete the noise by my self by looking where the noise is by zooming it manually and deleting the noise manually but it is taking too much time to clean approx 3hrs per signal. Do I need to delete it manually by looking where the noise is to get the good signal with out any noise. If there is any code that could help me to delete the noise that would save so much of time. Just I need to remove the noise in the signal to get good signal wihich are sutable for detecting the peaks and notch. I have attached the signal which I have cleaned manually, but in this signal also there is a bit noise which I have to delete furthur. if there is any code for deleteing the entire noise of signal for the signal provided before that would help me.
I am really tankfull to you.
Thankyou very much.
Star Strider
on 11 Dec 2019
There is not much noise.
I would use:
Ao = lowpass(Ao, 0.007, Fs);
or:
Fs = 1; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = 0.007/Fn; % Stopband Frequency (Normalised)
Ws = 1.2*Wp; % Passband Frequency (Normalised)
Rp = 1; % Passband Ripple
Rs = 60; % Passband Ripple (Attenuation)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptic Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp,'low'); % Elliptic Filter Design: Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
figure
freqz(sos, 2^18, Fs) % Filter Bode Plot
set(subplot(2,1,1), 'XLim',[0 Fs/5]) % Optional
set(subplot(2,1,2), 'XLim',[0 Fs/5]) % Optional
Ao_filt = filtfilt(sos, g, Ao); % Filter Signal
Both work, and eliminate some of the high-frequency components of the signal. (You need to decide if this is acceptable, since they could eliminate some data that would allow you to characterise the frequency response if the vascular system.)
As for the discontinuities, you need to decide how to deal with those. Records that have such significant discontinuities may not be acceptable data. There are other problems with the signals, as well, especially with regard to the step changes in absolute pressure and pulse pressure. This may be due to amplifier gain changes or other changes in the instrumentation, something that is definitely not advisable during a recording.
Lokeswara reddy pamulapate
on 8 Feb 2020
@Star Strider I have a doubt, can you please help me.
I have the data of Aorta and femoral signal in which I have to measure the systolic peak, diastolic peak, foot index, augmentation pressure and time. I identified the systolic peak, diastolic peak, foot index, notch index, and time by doing the 2nd derivative. As the signal is Aorta and femoral it will have a reflection in the pulse wave so I need to measure from these the augmentation pressure, from the systolic peak. I need just the idea how to measure the augmentation pressure of both Aorta and femoral how to identify the augmentation pressure(AP) and pulse pressure (PP) points in the data I have, for both feomral and aorta. please help me for only one step my work would be finished. this is for aorta the picture i have attached. If i identify the systolic peak, augmentation pressure point and pulse pressure point my work would be finished by this please help me. I can see no one better than you to help me. Please help me. Thankyou. Have a good day.
Lokeswara reddy pamulapate
on 16 Feb 2020
@Star Strider please can you help me with this? how to calculate the augmented pressure.
Star Strider
on 19 Feb 2020
The pulse pressure is the difference between the systolic and diastolic values, so that is straightforward to calculate. There is no distinct dicrotic notch in the aortic trace (this is worrison=me, since it likely indicates aortic insufficiency), and certainly none in the femoral trace. Since it defines one of the parameters you are interested in, find that point, then find the pressure that corresponds to it. You might be able to identify it in the aortic trace by using the gradient function and looking for changes in the derivative, however it does not exist in the femoral trace.
Lokeswara reddy pamulapate
on 19 Feb 2020
Hi, the pulse pressure can be calculated but I need to calculate the Augmented pressure(Anacrotic notch). from these Aorta and femoral.
Star Strider
on 19 Feb 2020
For each pulse, identify the dicrotic notch (that appears to define it), as a point in time using the derivative (or whatever technique you choose), then get the pressure at that point in time.
More Answers (1)
KALYAN ACHARJYA
on 20 Nov 2019
Edited: KALYAN ACHARJYA
on 20 Nov 2019
Lets say wave are y1,y2,y3.....up to y10..assuming all are having in same x scale
aveg_data=(y1+y2+y3...+y10)/10;
plot(x,aveg_data)
5 Comments
Lokeswara reddy pamulapate
on 20 Nov 2019
I need to get only one single wave which is the average of all these waves. I have tried this but I am actually getting the same. Its reducing the Y-axis. I have 4000 rows wth 1 column.
KALYAN ACHARJYA
on 20 Nov 2019
Yes aveg_data gives the average of all waves, just read the wave data and do averaging as mentioned
Lokeswara reddy pamulapate
on 20 Nov 2019
Edited: Lokeswara reddy pamulapate
on 20 Nov 2019
actuall it is madical data of patients. its radial artery blood pressure. i have alredy attched the data above. I tried what you said but its is giving a whole average number. But I need the average graph of those in a single graph(curve).
KALYAN ACHARJYA
on 20 Nov 2019
Edited: KALYAN ACHARJYA
on 20 Nov 2019
Can you share two sample data, so that I can test on it?
See Also
Categories
Find more on Parametric Spectral Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)