# cutting up the signal into repeating parts

48 views (last 30 days)

Show older comments

##### 1 Comment

per isakson
on 18 May 2018

### Accepted Answer

Star Strider
on 18 May 2018

Edited: Star Strider
on 18 May 2018

I seem to have seen this waveform somewhere else recently!

Try this:

D = xlsread('Star11.xls');

tv = D(:,1);

ap = D(:,2);

[pks, locs] = findpeaks(ap, 'MinPeakHeight',100, 'MinPeakDist',20); % 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)-10:locs(k1+1)-10); % Define MUAP Frames

tvc{k1} = tv(locs(k1)-10:locs(k1+1)-10);

end

figure(2)

hold all

for k1 = 1:numel(apc)

plot(tvc{k1}-tvc{k1}(1), apc{k1}) % Plot MUAP Frames

end

hold off

grid

That should get you started.

Experiment to get the result you want.

EDIT — Added plot:

### More Answers (1)

John BG
on 18 May 2018

Edited: John BG
on 18 May 2018

Hi Sara Bitarafan

please have a look at the attached script. .

1.-

Acquiring signal:

clear all;clc;close all

A=xlsread('Star11.xls')

t=A(:,1)'

s=A(:,2)'

figure(1)

plot(t,s);grid on

Removing DC

min_s=min(s)

s=s+abs(min_s)

center signal, closest to dominant cycle to a sin cos signal

max_s=max(s)

s=s-max_s/2

hold on

plot(t,s);grid on;axis tight

For this sample there's not much DC, but it may the case that without removing DC the sought eye diagram is difficult to get.

2.

Calculating the dominant cycle with fft:

.

S=fft(s)

absS=abs(S);

figure(2);

plot(absS);grid on;

max_absS=max(absS);

n_maxS=find(absS==max_absS)

.

2nd value is just FFT mirror

n_maxS=n_maxS(1)

.

If n_maxS = max_amount_cycles this would be the highest discernible requency, with the FFT: it would be just 2 time samples per cycle.

max_amount_cycles=floor(numel(t)/2)

.

n_maxS: amount of cycles

.

hold on;plot(n_maxS,max_absS,'ro')

.

nT: amount of samples per dominant cycle:

nT=floor(numel(t)/n_maxS)

.

dominant cycle T

t1=t([1:nT])

T=t1(end)

amount of lost samples ignoring .2

mod(nT,n_maxS) % samples lost, not a crisis

.

instead of a for loop:

% sc=zeros(n_maxS,T)

% for ,,

s2=s([1:1:end-(numel(t)-n_maxS*nT)])

.

But the dominant cycle is not that constant.

figure(3);

for k=1:1:3 % n_maxS

plot(s2(k*[1:nT]))

hold on;

end

% 003

.

For the same basic cycle t(nT) we see 1,2 and 3 peaks

This is caused by a 2nd tone almost half way the dominant tone in amplitude and really close to the dominant.

fft approach is more reliable when there's a clear frequency peak but no high tones anywhere, particular near the dominant.

Yet the variable nT is going to be useful in next point.

Also, assuming the single action potential refers to a single peak

3.-

When the dominant cycle is not that constant we can use squelch:

Set a threshold that includes all peaks above a given amplitude.

close all

s=A(:,2)'

th1=100

figure(1);plot(t,s);grid on

[pks,locs]=findpeaks(s,'MinPeakHeight',th1)

hold on

plot(t(locs),pks,'bd')

avoid false peaks imposing min distance between found peaks, that may be for instance: nT

.

[pks,locs]=findpeaks(s,'MinPeakHeight',th1,'MinPeakDistance',floor(nT/2))

hold on

plot(t(locs),pks,'rd')

% 004

.

So far what can we assert about this signal and the 'potential' events you have mentioned in the question?

How often do the events take place

mean(diff(locs))

.

How much jitter suffer such events understanding jitter ~ standard deviation of locs

var(diff(locs))^.5

4.-

Plotting the centered diagram with all events:

Let be dt the + - span left and right of each peak event

dt=floor(.5*mean(diff(locs)))

And the eye diagram:

sc2=zeros(numel(locs),2*dt+1) % + - window span around each peak

for k=1:1:numel(locs)

if locs(k)<dt % 1st cycle, with 1st peak closer than dt to beginning of signal.

s0=s([1:locs(k)+dt])

sc2(k,:)=[zeros(1,2*dt+1-numel(s0)) s0]

end

if locs(k)>numel(t)-dt % last cycle with peak closer than dt to end of signal.

sc2(k,:)=s([locs(k)-dt:end])

end

if locs(k)<numel(t)-dt && locs(k)>dt

sc2(k,:)=s([locs(k)-dt:locs(k)+dt])

end

end

% 4. and the eye diagram is:

figure(2);

for k=1:1:numel(locs)

plot(sc2(k,:))

hold on

end

grid on

% 005

.

.

Sara

if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?

To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link

thanks in advance for time and attention

John BG

### See Also

### Community Treasure Hunt

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

Start Hunting!