Detecting and changing the polarity of signals
16 views (last 30 days)
Show older comments
Hi every one;
I have hundred of data files (signals) of equal length. I am interested in the highest peak (maximum) and location in each signal but want to have them with positive polarity. Now the problem is that, randomly, some signals have highest peak as positive polarity and some have negative. I want all of the signals with the positive polarity. Manually, I can just plot and if find negative, I multiple with -1, then find maximum and its location but my question is that can I do some thing that, it sees if highest value appears as negative, it converts the signal to positive. I will appreciate your help.
7 Comments
Adam Danz
on 27 Sep 2018
Edited: Adam Danz
on 27 Sep 2018
I looked at the plot in the pdf file. If you have an estimate of the baseline (~-0.75 in these data) I'd go with my first option proposed in my answer. Subtract that from the signal so the new baseline is 0. Then you can just take max(abs()) + baseline.
Accepted Answer
Adam Danz
on 27 Sep 2018
(Continuing from comments under the question) I think the best solution would be subtract the baseline value and then take the absolute value of your signal. Then you just need to find the max. I don't have your data but it would look something like this:
[maxVal, maxIdx] = max(abs(signal-baseline));
An alternative is to find the max and min, determine which has the greater magnitude, and then multiply the value by the sign of that number. If the sign is positive, the value will remain positive. If the sign is negative, multiplying two negatives will turn it positive. That would look something like this:
Assuming you have the peak value ( peakVal ) and its location ( peakIdx ),
peakVal * sign(data(peakIdx))
3 Comments
Adam Danz
on 16 Oct 2018
The method below finds which element of the vector data1 has the largest magnitude (positive or negative) by using the absolute value and the n multiplies it by the sign of that number so negative peaks remain negative.
data1 = [-3 3 -2 -20 4 -1 -2 1 -2 -1];
[peak, peakIdx] = max(abs(data1));
peak = peak * sign(data1(peakIdx));
peak =
-20
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!