How to find the frequencies of a time series which contain datetime ?
55 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sim
el 11 de Ag. de 2022
Comentada: Sim
el 16 de Ag. de 2022
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 comentarios
Respuesta aceptada
Abderrahim. B
el 11 de Ag. de 2022
Editada: Abderrahim. B
el 11 de Ag. de 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 comentarios
dpb
el 12 de Ag. de 2022
Oh, why didn't you say so!!! :) Wouldn't have gotten so uptight on trying to prevent a perhaps egregious blunder... :)
OK, for pedgogical purposes, I'd suggest to look at the sample datasets with MATLAB used in the documentation as starters...there's a sunspot dataset that looks at longer-time calendar data -- although it's not in datetime format (its inclusion having preceded its introduction by 30 years), you could convert the yearly data to datetimes and to a timetable if you wanted practice using the newfangled datetime and other features as well...although truthfully for spectral and time-series analysis, the reversion back to plain doubles is often more convenient because all the signal processing routines haven't been converted to know anything about datetimes or durations. timetable has, but not necessarily the core Signal Processing routines.
As far as figuring out the frequency of the low-sampling frequency signals, to see have it right you can always convert the times to seconds and deal in Hz and then scale the resulting frequencies back to the longer time frames afterwards. It is easy to get confused with days and years in those locations instead, granted.
But, remember and commit to memory the base fundamental relationships in data sampling/signal analysis -- if you remember these, you can always get it right --
Fs = 1/dt - Sampling frequency is 1/delta-t
Fmax = 1/(2*dt) (= Fs/2) - Fmax (Nyquist) is one-half sampling rate
T = N*dt (= 1/df) - Sample time span is number samples * dt
df = Fmax/(N/2) - frequency resolution is Fmax over half the number samples
Applying those will get you out of the morass; if one of them doesn't hold you've made a mistake somewhere!
Más respuestas (1)
dpb
el 11 de Ag. de 2022
Editada: dpb
el 12 de Ag. de 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...
Ver también
Categorías
Más información sobre Data Preprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!