Calculate time period of a graph signal

19 views (last 30 days)
Hello guys , i am new to matlab .
I have a signal graph that i want to find the time period of it and the time in which the amplitude gets half of its starting value.
The singal is below :
Any help will be appreciated !
Thanks
  2 Comments
Sam Chak
Sam Chak on 27 Mar 2022
Okay, please provide the data to plot this signal.
Bill Kyriakidis
Bill Kyriakidis on 27 Mar 2022
Okey ,
I have 2 variables.The variable t ,which is time and zn which is amplitude .
The values of these two are in the text document i attach

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 27 Mar 2022
Edited: Star Strider on 27 Mar 2022
Use findpeaks to get the peak indices and then use the associated time vector to calculate the period. Use the envelope function to return the upper envelope of the waveform that can then be used to determine the rate of the decrease in the amplitude.
Alternatively, use the procedure described in Curve Fitting of large Data Measurement? to get the relevant parameters, and use those values to calculate the desired results.
EDIT — (27 Mar 2022 at 19:35)
The envelope turns out not to be a single exponential, so while treating it as such may work, any results derived from that assumption may have some inaccuracies.
There are beginning and trailing parts of the signal that I removed by finding the appropriate indices and the using only that part of the signal for the regression.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/942934/Signal_processing_Bill.txt', 'VariableNamingRule','preserve')
T1 = 1000×1 table
Calculate time period of a graph signal _______________________________________ 0.51485 -0.47324 -0.72355 0.13836 0.74797 0.18449 -0.66647 -0.47968 0.43007 0.644 -0.14748 -0.70913 -0.17036 0.60437 0.4239 -0.41766
x = linspace(0, numel(T1{:,1})-1, numel(T1{:,1}))';
[pks,locs] = findpeaks(T1{:,1});
Period = mean(diff(x(locs)))
Period = 4.6573
env = envelope(T1{:,1}, 5, 'peak');
figure
plot(x, T1{:,1})
hold on
plot(x,env)
hold off
grid
legend('Signal','Upper Envelope', 'Location','best')
yc(:,1) = T1{:,1};
[mv,ix] = max(yc);
lcs = find(islocalmax(yc(yc(:,1)>0), 'MinProminence',0.05));
lims = [ix max(lcs)];
yc = yc(lims(1):lims(2));
x = linspace(0, numel(yc)-1, numel(yc))';
vn = T1.Properties.VariableNames; % Variable Names
ttlstr = vn(1); % Variable Names Used In The Code
for k = 1:size(yc,2)
yk = yc(:,k);
y = yk;
% y = detrend(y);
ym = mean(y); % Estimate offset
y = y - ym;
yu = max(y);
yl = min(y);
yr = (yu-yl); % Range of ‘y’
yz = y-yu+(yr/2);
zci = @(v) find(diff(sign(v))); % Returns Approximate Zero-Crossing Indices Of Argument Vector
zt = x(zci(y));
per = 2*mean(diff(zt)) % Estimate period
fit = @(b,x) b(1) .* exp(b(2).*x) .* (sin(2*pi*x./b(3) + 2*pi/b(4))) + b(5); % Objective Function to fit
fcn = @(b) norm(fit(b,x) - yk); % Least-Squares cost function
s0 = [yr; -1E-2; per; -1; ym]; % Initial Parameter Estimates
[s,nmrs] = fminsearch(fcn, s0) % Minimise Least-Squares
xp = linspace(min(x),max(x), 500);
figure
plot(x,yk,':b', 'LineWidth',1.5)
hold on
plot(xp,fit(s,xp), '--r')
hold off
grid
xlabel('Time (s)')
ylabel('Amplitude')
title(ttlstr{k})
legend('Original Data', 'Fitted Curve')
text(0.1*max(xlim),0.7*min(ylim), sprintf('$y = %.3f\\cdot e^{%.3f\\cdot x}\\cdot sin(2\\pi\\cdot x\\cdot %.3f%+.3f) %+.4f$', [s(1:2); 1./s(3:4); s(5)]), 'Interpreter','latex')
end
per = 4.6602
s = 5×1
0.6171 -0.0047 4.6593 -1.3232 -0.0003
nmrs = 0.5517
.
  2 Comments
Bill Kyriakidis
Bill Kyriakidis on 27 Mar 2022
Edited: Bill Kyriakidis on 27 Mar 2022
Thank you very much!!
I apreciate your time spent for my problem !

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!