MATLAB: Code for signal analysis

electrical analysisImage Processing Toolboxsignal processingSignal Processing Toolbox

I trying to analyse some electric signal data but I'm still a Matlab beginner and need help. I use the code bellow just to plot time and signal, but i want to stract the repetition rate of the signal (Hz/number of pulses per second). I think this is possible if i delimite a threshold for the start. Other problem is: i have two signals together in the same file (one big, other little, a example in the figure). Its possible to calculate the repetition rate for each signal? Follow a example of my data.
Thanks for reading
file = 'filename';
signal=wavread(file); % signal
fs = 48000; % sample rate
t=[1/fs:1/fs:length(signal)/fs];
plot(t,signal);

Best Answer

I'd take the absolute value of the signal (to flip the bottom part up), then I'd threshold at 0.3 and 0.06 to get the two parts of the signal - the high spikes and the shorter spikes. Then use bwlabel to give an ID number to each spike and use regionprops to compute the centroid of each thresholded spike. Once you know that, you can get the average time between spikes, or whatever other information you might want. Untested code (because you didn't include your data) is below:
bigSpikes = abs(signal) > 0.3;
[labeledSpikes, numberOfSpikes] = bwlabel(bigSpikes);
props = regionprops(labeledSpikes, 'Centroid');
allCentroids = [props.Centroid];
xCentroids = allCentroids(1:2:end)
meanSpacingTall = diff(xCentroids)
Do the same for shortSpikes
shortSpikes = abs(signal) > 0.06;
[labeledSpikes, numberOfSpikes] = bwlabel(shortSpikes);
props = regionprops(labeledSpikes, 'Centroid');
allCentroids = [props.Centroid];
xCentroids = allCentroids(1:2:end)
meanSpacingShort = diff(xCentroids)
Related Question