MATLAB: Calculating Time Period of a Displacement Signal

frequencygraphMATLAB

Hi,
I have signal data in the form of a sinusoidal wave, decreasing in amplitude and increasing in frequency.
Is there a way to calculate the frequency or time period of a signal in the time domain?
Signal Data
Below is the outcome I am hoping for
Thanks
Conor

Best Answer

The easiest way is to calculate the exact zero crossings and invert them to get the instantaneous frequency. I don’t have your data so I created some to test this. You will probably need to tweak it a bit to work correctly with your data.
The Code:
t = linspace(0, 60, 10000); % Create Data

y = sin(2*pi*(t/10).^3) .* exp(-t/10); % Create Data
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
yidx = zci(y); % Approximate Zero Crossing Indices
for k1 = 2:length(yidx)-1
tc(k1) = interp1(y(yidx(k1)+[-1:1]), t(yidx(k1)+[-1:1]), 0, 'linear'); % ‘Exact’ Zero Crossings
end
frq = 1./gradient(tc); % Approximate Frequency
figure(1)
subplot(2,1,1)
plot(t, y)
title('Original Signal')
grid
subplot(2,1,2)
plot(tc, frq)
title('Frequency')
grid