How to find the frequencies of a time series which contain datetime ?
55 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Abderrahim. B
am 11 Aug. 2022
Bearbeitet: Abderrahim. B
am 11 Aug. 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 Kommentare
dpb
am 12 Aug. 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!
Weitere Antworten (1)
dpb
am 11 Aug. 2022
Bearbeitet: dpb
am 12 Aug. 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...
Siehe auch
Kategorien
Mehr zu Data Preprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!