Skip to content
MathWorks - Mobile View
  • MathWorks 계정에 로그인합니다.MathWorks 계정에 로그인합니다.
  • Access your MathWorks Account
    • 내 계정
    • 나의 커뮤니티 프로필
    • 라이선스를 계정에 연결
    • 로그아웃
  • 제품
  • 솔루션
  • 아카데미아
  • 지원
  • 커뮤니티
  • 이벤트
  • MATLAB 받기
MathWorks
  • 제품
  • 솔루션
  • 아카데미아
  • 지원
  • 커뮤니티
  • 이벤트
  • MATLAB 받기
  • MathWorks 계정에 로그인합니다.MathWorks 계정에 로그인합니다.
  • Access your MathWorks Account
    • 내 계정
    • 나의 커뮤니티 프로필
    • 라이선스를 계정에 연결
    • 로그아웃

비디오 및 웨비나

  • MathWorks
  • 비디오
  • 비디오 홈
  • 검색
  • 비디오 홈
  • 검색
  • 영업 담당 문의
  • 평가판 신청
5:44 Video length is 5:44.
  • Description
  • Full Transcript
  • Related Resources

How to Preprocess Time Series Data with MATLAB

In this video we demonstrate how you can process and clean time series data stored in Excel sheets, in multiple formats, and with multiple sampling rates in MATLAB®. We start with importing data from Excel sheets using the Import Tool. Next, we focus on how to prepare the data to convert to the timetable datatype.

We then explore the preprocessing functions available with timetables including synchronizing the data sets to a common time reference, assessing data quality, and dealing with duplicate and missing data. At the end, we show the stacked plot of variables with row times.

Introduction

In data science it is always said that 80% of the time is spent in preparing data and 20% of time is spent complaining about the need to prepare data. So let’s try solving this issue by preparing and preprocessing time series data in less time and with a few lines of code in MATLAB.

DEMO

For this example, we will be using data from Phasor Measurement Units (PMUs)

  • We have 15 PMUs which are measuring the voltage magnitude, voltage angle, and frequency synchronized to a GPS clock system
  • They are in 3 time zones in Australia – Eastern Daylight Savings time zone, Central Daylight Savings time zone, and Eastern Standard time
  • The PMUs were sampled at 3 different sampling rates: 30, 60, 120Hz
  • This occurred at different time offsets as the PMUs did not start recording at the same time

So yes, we have data that needs to be aligned and cleaned for any further analysis.

Our data is in three Excel spreadsheets, one for each of the three time zones, and we will be importing the data using the Import Tool. If we open the spreadsheet in MATLAB it, by default, opens in the Import Tool. Click on import data. The data is then stored in the workspace as a table.

For processing the time series data and working on time-specific functions, MATLAB has a datatype timetable that makes the processing easier. To convert the table into timetable our time should be in datetime format.

So now we will extract the time column from each table and convert it into datetime using the datetime function. In the same line of code, we are addressing the first challenge of our dataset; that the data is in three different time zones with different offsets. So, in the same step we align the time zones by giving the time zones as the options: Australia/Sydney for Eastern Daylight time, Australia/Adelaide for Central Daylight time and Australia/Brisbane for Eastern Standard time.

Let’s plot our frequency measurement with the time from each PMU to visually confirm the time alignment. As we see frequencies overlap. Hence, we have our time alignment correct.

Once our time columns are in datetime format and aligned we convert all our three tables into timetables by using the function table2timetable. We now have our three tables in the format of timetables.

Next, we proceed to cleaning the data. As we can see in this linked MATLAB documentation that we can handle and clean timetables using various workflows like finding and removing the missing data, sorting and removing duplicates, etc.

Here we demonstrate one way of working with duplicate times. First, with the unique function we create a vector UniqueTime which returns the unique and sorted rows of the time variable. This vector does not contain the duplicate row times. Just for verification we check here that we have seven duplicate row rimes. To handle that we use the retime function to calculate the mean for all other variables with duplicate row times. Hence now we have a new table UniquedataACDT with no duplicate row times. We do a similar process for the other two tables.  We will now work with the three new tables.

Missing data can be processed in different ways. For a single timetable we can use the rmissing function and remove all the rows with missing data. As we do here for the UniquedataACDT table.

The other method is using interpolation while joining the tables.

We join all the three tables into one timetable using the synchronize function. Synchronize collects the variables from all input timetables and outputs a single timetable with all the variables concatenated horizontally.

Here we specify union to synchronize on a time vector that includes times from all three timetables. And linear to fill in missing timetable elements with linear interpolation.

Hence now we have a Total table consisting of all the three clean timetables.  

Once we have our data all cleaned up, we can do some visual analysis by plotting the data.

Here we show one example using the stackedplot function. Stackedplot plots the variables of a timetable against row times. We plot the voltage magnitudes VM6, VM1, and VM11 against the row times from the total combined table.

Please look at the description to see more resources on data preprocessing and download the code to try it with your datasets.

Thank you.

Related Products

  • MATLAB

Learn More

Download code
Preprocessing Time Series Data with MATLAB
MATLAB for Data Analysis
Preprocessing Data

Bridging Wireless Communications Design and Testing with MATLAB

Read white paper

Feedback

Featured Product

MATLAB

  • Request Trial
  • Get Pricing

Up Next:

33:26
Developing Forecast Models from Time-Series Data in MATLAB...

Related Videos:

27:37
Developing Forecast Models from Time-Series Data in MATLAB...
4:15
How to Label a Series of Points on a Plot in MATLAB
3:40
Visualizing Retention Data over Time in MATLAB
2:09
How to Store a Series of Vectors from a for Loop

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (简体中文)
  • 中国 (English)

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • 영업 담당 문의
  • 평가판 신청

MathWorks

Accelerating the pace of engineering and science

MathWorks는 엔지니어와 과학자들을 위한 테크니컬 컴퓨팅 소프트웨어 분야의 선도적인 개발업체입니다.

활용 분야 …

제품 소개

  • MATLAB
  • Simulink
  • 학생용 소프트웨어
  • 하드웨어 지원
  • File Exchange

다운로드 및 구매

  • 다운로드
  • 평가판 신청
  • 영업 상담
  • 가격 및 라이선스
  • MathWorks 스토어

사용 방법

  • 문서
  • 튜토리얼
  • 예제
  • 비디오 및 웨비나
  • 교육

지원

  • 설치 도움말
  • MATLAB Answers
  • 컨설팅
  • 라이선스 센터
  • 지원 문의

회사 정보

  • 채용
  • 뉴스 룸
  • 사회적 미션
  • 고객 사례
  • 회사 정보
  • Select a Web Site United States
  • 신뢰 센터
  • 등록 상표
  • 정보 취급 방침
  • 불법 복제 방지
  • 애플리케이션 상태
  • 매스웍스코리아 유한회사
  • 주소: 서울시 강남구 삼성동 테헤란로 521 파르나스타워 14층
  • 전화번호: 02-6006-5100
  • 대표자 : 이종민
  • 사업자 등록번호 : 120-86-60062

© 1994-2022 The MathWorks, Inc.

  • Naver
  • Facebook
  • Twitter
  • YouTube
  • LinkedIn
  • RSS

대화에 참여하기