How to find the frequencies of a time series which contain datetime ?
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How to find the frequencies of a time series which contain datetime, as in the following example ?
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)))

0 commentaires
Réponse acceptée
Abderrahim. B
le 11 Août 2022
Modifié(e) : Abderrahim. B
le 11 Août 2022
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}
% 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)
% Plot power in log scale vs frequency
figure
semilogy(freqs, pow)
Hope this helps
10 commentaires
Plus de réponses (1)
dpb
le 11 Août 2022
Modifié(e) : dpb
le 12 Août 2022
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 commentaires
Voir également
Catégories
En savoir plus sur Spectral Measurements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!