How to find the frequencies of a time series which contain datetime ?

19 次查看(过去 30 天)
How to find the frequencies of a time series which contain datetime, as in the following example ?
(Note: I did not find such an exmple in the Fast Fourier transform (fft) page)
a = {
'17-Jun-2021 12:00:00', 25
'18-Jun-2021 20:00:00', 21
'19-Jun-2021 06:00:00', 31
'20-Jun-2021 14:00:00', 35
'21-Jun-2021 17:00:00', 31
'22-Jun-2021 16:00:00', 41
'23-Jun-2021 16:00:00', 22
'24-Jun-2021 13:00:00', 22
'25-Jun-2021 15:00:00', 45
'26-Jun-2021 11:00:00', 20
'27-Jun-2021 19:00:00', 25
'28-Jun-2021 18:00:00', 25
'29-Jun-2021 15:00:00', 29
'30-Jun-2021 10:00:00', 31
'01-Jul-2021 15:00:00', 20
'02-Jul-2021 10:00:00', 28
'03-Jul-2021 14:00:00', 31
'04-Jul-2021 13:00:00', 24
'05-Jul-2021 09:00:00', 24
'06-Jul-2021 14:00:00', 25
'07-Jul-2021 15:00:00', 40}
plot(datetime(a(:,1)),cell2mat(a(:,2)))

采纳的回答

Issa
Issa 2022-8-11
编辑:Issa 2022-8-11
Hi!
You can use pspectrum function. It returns both power and frequency arrays.
% Your data
a = {
'17-Jun-2021 12:00:00', 25
'18-Jun-2021 20:00:00', 21
'19-Jun-2021 06:00:00', 31
'20-Jun-2021 14:00:00', 35
'21-Jun-2021 17:00:00', 31
'22-Jun-2021 16:00:00', 41
'23-Jun-2021 16:00:00', 22
'24-Jun-2021 13:00:00', 22
'25-Jun-2021 15:00:00', 45
'26-Jun-2021 11:00:00', 20
'27-Jun-2021 19:00:00', 25
'28-Jun-2021 18:00:00', 25
'29-Jun-2021 15:00:00', 29
'30-Jun-2021 10:00:00', 31
'01-Jul-2021 15:00:00', 20
'02-Jul-2021 10:00:00', 28
'03-Jul-2021 14:00:00', 31
'04-Jul-2021 13:00:00', 24
'05-Jul-2021 09:00:00', 24
'06-Jul-2021 14:00:00', 25
'07-Jul-2021 15:00:00', 40}
a = 21×2 cell array
{'17-Jun-2021 12:00:00'} {[25]} {'18-Jun-2021 20:00:00'} {[21]} {'19-Jun-2021 06:00:00'} {[31]} {'20-Jun-2021 14:00:00'} {[35]} {'21-Jun-2021 17:00:00'} {[31]} {'22-Jun-2021 16:00:00'} {[41]} {'23-Jun-2021 16:00:00'} {[22]} {'24-Jun-2021 13:00:00'} {[22]} {'25-Jun-2021 15:00:00'} {[45]} {'26-Jun-2021 11:00:00'} {[20]} {'27-Jun-2021 19:00:00'} {[25]} {'28-Jun-2021 18:00:00'} {[25]} {'29-Jun-2021 15:00:00'} {[29]} {'30-Jun-2021 10:00:00'} {[31]} {'01-Jul-2021 15:00:00'} {[20]} {'02-Jul-2021 10:00:00'} {[28]}
% Your plot
plot(datetime(a(:,1)),cell2mat(a(:,2)))
% convert to table, then to timetable
aTbl = cell2table(a) ;
aTbl.Properties.VariableNames = ["Time" , "timeSerie"] ;
aTbl.Time = datetime(aTbl.Time, "InputFormat","dd-MMM-uuuu HH:mm:ss") ;
aTimeTbl = table2timetable(aTbl) ;
% Some preprocessing
aTimeTBL_RETIME = retime(aTimeTbl, "hourly", "previous") ;
% spectrum : returns power and frequency vectors
[pow, freqs] = pspectrum(aTimeTBL_RETIME)
pow = 4096×1
1.0e+03 * 1.4474 1.4449 1.4373 1.4249 1.4077 1.3858 1.3595 1.3291 1.2947 1.2568
freqs = 4096×1
1.0e-03 * 0 0.0000 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0003 0.0003
% Plot power in log scale vs frequency
figure
semilogy(freqs, pow)
Hope this helps
  10 个评论

请先登录,再进行评论。

更多回答(1 个)

dpb
dpb 2022-8-11
编辑:dpb 2022-8-12
I think it's absurd to even think about peforming spectral analysis on such a intermittently-sampled signal, but the only thing even close to a dominant frequency would be at roughly 0.015/hr and could only be distinguished at all after detrending the trace to remove DC component.
To believe this would be of any real meaning, however, would be nuts...
  5 个评论

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by