简体   繁体   English

Matlab:44100 Hz数据的时间序列图

[英]Matlab: time series plot for 44100 hz data

I'm trying to plot a time series which has been collected at a rate of 44100 hz. 我正在尝试绘制一个以44100 Hz的速率收集的时间序列。 I would like to have the time (in seconds) and possibly the date on the x-axis. 我想在x轴上有时间(以秒为单位),也可能有日期。

Say I have data for one minute, ie 2646001 data points and assume, for simplicity, all data points are ones: 假设我有一分钟的数据,即2646001个数据点,为简单起见,假设所有数据点都是一个:

y=repmat(1,2646001,1);

I created a vector of date numbers by converting the start and end date into serial date numbers and then create a vector from the first time number to the last time number with rate 44100 hz: 我通过将开始日期和结束日期转换为序列日期编号创建了日期编号矢量,然后从第一个时间编号到最后一个时间编号创建了矢量,速率为44100 hz:

StartTimeNum    = datenum(2013,11,12,23,00,0);
EndTimeNum      = datenum(2013,11,12,23,01,0);

T               = EndTimeNum-StartTimeNum;

TimeNum         = StartTimeNum:(T/length(y)):EndTimeNum;

I then define the format I would like the date string to be in and convert the time number vector into time string. 然后,我定义希望日期字符串插入的格式,并将时间数字向量转换为时间字符串。

FormatOut       = 'dd/mm/yy, HH:MM:SS.FFF';

TimeStr= datestr(TimeNum, FormatOut);

but now TimeStr is a <2646001x22 char>, rather than a <2646001x1 char> which Matlab doesn't allow me to use as the input for the x-axis. 但现在TimeStr是<2646001x22 char>,而不是<2646001x1 char>,Matlab不允许我将其用作x轴的输入。

In another attempt I found the timeseries class ( http://www.mathworks.co.uk/help/matlab/ref/timeseries.plot.html ) which would be perfect, but because my data is in 44100 hz, I am not sure how to define the units (ts1.TimeInfo.Units), which are generally described as 'days', or 'hours' or 'seconds' but not in hz... 在另一种尝试中,我发现了时间序列类( http://www.mathworks.co.uk/help/matlab/ref/timeseries.plot.html )会很完美,但是因为我的数据在44100 hz中,所以我不是确保如何定义单位(ts1.TimeInfo.Units),通常将其描述为“天”,“小时”或“秒”,但不能以hz表示...

Is there any way around this? 有没有办法解决?

Thanks 谢谢

y=ones(2646001,1);  % use ones(m,n) for more efficiency

StartTimeNum    = datenum(2013,11,12,23,00,0);
EndTimeNum      = datenum(2013,11,12,23,01,0);

T               = EndTimeNum-StartTimeNum;

TimeNum         = StartTimeNum:(T/(length(y)-1)):EndTimeNum;  % length consistent
FormatOut       = 'dd/mm/yy, HH:MM:SS.FFF';
figure,plot(TimeNum, y),datetick('x',FormatOut)

Plot your data vs. TimeNum directly, then use datetick to set the labels: 直接绘制数据与TimeNum的关系图,然后使用datetick设置标签:

plot(TimeNum, y);
datetick('x', 'dd/mm/yy, HH:MM:SS.FFF');

Or try just datetick with no arguments. 或者尝试datetick带参数的datetick The default format might be better. 默认格式可能更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM