I have this matlab code  which calculates the autocorellation of data. I want the timespan over which the autocrrelation is lower than 50% of the maxmimum value how can I get that

DataTbl=readtable('6smaalbasorber10ssweeptimeusedthis.csv');

[Ro,Co]=size(DataTbl);

Data=table2array(DataTbl);

Time=Data(:,1);

S21Mag=Data(:,2);

S21Ang=Data(:,3);

%%% DAta Preperation %%%%%%

[Re,Im]=pol2cart(S21Ang,S21Mag);

CmpLx=complex(Re,Im);

ampitude=sqrt((Re .^2)+(Im .^2)); % amplitude value

ampitudedB= 20*log10(ampitude); % amplitude in dB

plot (Time,ampitudedB); %Amplitudein db verus time

y1 = ampitude;

%# autocorrelation

maxlag = 10; %# set a max lag value here

[c,lags] = xcorr(detrend(y1), maxlag, 'biased');

Cmax =max(c);

halfmax=0.5*Cmax; % calculates half of the maximum

% Here I need to add something such that I will get the timelag where

%the autocorrelations drops to 50% of maximum

%# plot

plot(lags,c), xlabel('lags [seconds]'), ylabel('autocorrelation')

More Vikesh Shivik's questions See All
Similar questions and discussions