Clear Filters
Clear Filters

ideas to find the amplitude from this graph?

66 views (last 30 days)
Max
Max on 6 Sep 2014
Commented: Star Strider on 10 Sep 2014
Hi,
Im tying to find the amplitude from that graph. I have the information for 300 points with the X and Y coordinates from that graph. One idea that i have is to find the local max and local minimum for every 2 zeros. And then, the amplitude would be the sum of local max and local min for every 2 zeros.
I think i can use the function "findpeaks" to find the locals but I'm having hard time to tell matlab to find the locals every 2 zeros.
As you see, the amplitude is changing so at the end i will have to take the average.
Any ideas would be really appreciate.
Thanks!
  1 Comment
Image Analyst
Image Analyst on 6 Sep 2014
I'm not clear on what you want. Do you want the "envelope" of the high frequency waveform? Do you want the running average, like you'd get from conv(), from all the data, or from the upper positive and lower negative peaks , or from the absolute value of the signal? It looks like averaging all the data would just average out to zero since it's like a modulated sine wave and there are negative points that are equal in number and amplitude to the positive points.

Sign in to comment.

Answers (2)

Guillaume
Guillaume on 6 Sep 2014
Edited: Guillaume on 6 Sep 2014
Would this work to find the locals every two zeros (I haven't got the SP toolbox)?
[peaks, locations] = findpeaks(signal); %all peaks and locations
allzeros = find(~signal);
%now divide the locations into bins whose upper bounds are allzeros(2:2:end) (every two zero)
%and find out which bin they land into:
[~, locbin] = histc(location, allzeros(2:2:end));
%use the location bins to distribute the peaks into each bin and find the max and min per bin:
maxpeaks = accumarray(locbin, peaks, [], @max);
minpeaks = accumarray(locbin, peaks, [], @min);
You may have to do some filtering if the curve is too noisy near zero.
  3 Comments
Guillaume
Guillaume on 6 Sep 2014
You made an error and some unnecessary changes when you copied my code. First,
allzeros = find(~vy);
The ~ is required to find the 0s. If you find it confusing you could also write it as:
allzeros = find(vy == 0);
After that instruction, allzeros contains the index of all the zeros of your function (maybe I should have called the variable allzeroindices), and therefore allzeros(2:2:end) is the indices of every 2nd zero. Note that I made the assumption that the first lot of peaks were between two zeros, which is probably wrong. So it may work better with allzeros(1:2:end).
Secondly, note that I discarded the first output of histc as you don't need it. You only care about find between which pair of zero the location belongs to and that's the 2nd output. You certainly don't want to assign the first output of histc to vy, your original variable. It still should be:
[~, locbin] = histc(locations, allzeros(2:2:end)); %or allzeros(1:2:end)
The third output to accumarray is the size of the output, it's certainly not vy, it's numel(locbin) which accumarray calculates automatically if you give it [], thus leave the lines as:
maxpeaks = accumarray(locbin, peaks, [], @max);
minpeaks = accumarray(locbin, peaks, [], @min);
Finally, according to the error you get you swapped some arguments of accumarray.
Note, the idea of the algorithm is to get the location of the peak and the location of every 2nd zero. histc is then used to bin the location between each 2nd zero. You only care to know in which been each location lands, not the population of the bin, hence why you only want the 2nd output. Finally, accumarray distributes the peaks in each bin and only keep the max or min per bin.
Max
Max on 7 Sep 2014
Thanks,
Well i fixed those errors that you told me but now when I'm running the code, i have seen that it only finds the positive peaks of my data, not the negatives, therefore my maxpeaks and minpeaks are the same.

Sign in to comment.


Star Strider
Star Strider on 6 Sep 2014
First, use a bandpass filter to eliminate the high-frequency noise and any baseline drift in all the channels. I would use a Butterworth design, using buttord, butter, convert to second-order-section (sos) representation, then use filtfilt.
Finding the amplitude and peaks of the signal itself is then easy with findpeaks as you’ve already discovered.
  9 Comments
Max
Max on 10 Sep 2014
Edited: Max on 10 Sep 2014
the total sample length is 30 seconds and it has steps of 0.1 seconds, 300 points in total.
But not every period has the same amount of data.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!