HW 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

JSC “Kazakh-British Technical University”

Faculty of Information Technology

Practice work №1
Processing experimental data in Matlab

Prepared by: Dussekenov Elnar


Checked by: Svambayeva Aiym

Almaty, 2024
CONTENT

Introduction ......................................................................................................................... 3
1. Transform from a large size to a smaller one ..................................................................... 4
2. Data smoothing and noise reduction in time-series data ...................................................... 5
Conclusion .......................................................................................................................... 7
INTRODUCTION

In many scientific studies and amateur experiments, processing large volumes of


digital data is often required. For this task, MATLAB is an ideal choice. Unlike Excel,
which becomes cumbersome and inefficient when handling datasets containing tens of
thousands of numbers, MATLAB offers powerful tools and capabilities specifically
designed for managing, analyzing, and visualizing extensive datasets. With its
advanced functions and versatility, MATLAB is almost the only convenient option for
those dealing with complex data analysis needs, making it an indispensable tool in data-
driven research and experimentation.

3
1. Transform from a large size to a smaller one

I downloaded the experimental data from a repository on GitHub. The dataset


provided is a collection of real-world industrial vibration data collected from a
brownfield CNC milling machine. The acceleration has been measured using a tri-axial
accelerometer (Bosch CISS Sensor) mounted inside the machine. The X- Y- and Z-
axes of the accelerometer have been recorded using a sampling rate equal to 2 kHz.
The downloaded dataset was quickly imported into MATLAB, as shown in Figure 1.1.

Figure 1.1 – Importing data

This dataset is a large table with 3 rows. The table is named "vibration_data," so
I assumed that the resulting graph would resemble an oscillation. I wrote the following
code:
% Reading data from .h5 file
data = h5read('M03_Aug_2019_OP00_000.h5', '/vibration_data');
t = (1:length(data(:, 1)))./100; % time array
% Plotting a reduced data set
figure; % Opening a new window for the chart
plot(t, data);
grid on; % Создание сетки на графике
xlabel('Время, с'); % X-axis label
ylabel('Напряжение, мВ'); % Y-axis label

In this code, you can see that I used the pre-built function "h5read" to read the
given format. After running the code, I obtained the plot shown in Figure 1.2.

4
Figure 1.2 – Plotting graphs for each row of data

The graph exhibits significant oscillations and needs to be smoothed.

2. Data smoothing and noise reduction in time-series data

In this part, I used the method of finding the average and making the graph
smoother. The idea is to reduce noise and fluctuations in the data to see the clear plot.
Here is the code.
% Reading data from the .h5 file
data = h5read('M02_Aug_2019_OP03_009.h5', '/vibration_data');

% Selecting the first 100 elements from each row


data_subset = data(:, 1:100);

% Applying the moving average method to smooth the data


windowSize = 5; % Size of the window for moving average
smoothed_data_1 = movmean(data_subset(1, :), windowSize);
smoothed_data_2 = movmean(data_subset(2, :), windowSize);
smoothed_data_3 = movmean(data_subset(3, :), windowSize);

% Creating the time array for the first 100 points


t = (1:length(data_subset(1, :))) ./ 100; % Time array

% Plotting the smoothed data for each row


figure;
plot(t, smoothed_data_1); % First row of data
hold on;
plot(t, smoothed_data_2); % Second row of data
plot(t, smoothed_data_3); % Third row of data
hold off;

grid on; % Adding grid to the plot


xlabel('Time, s'); % X-axis label
ylabel('Voltage, mV'); % Y-axis label
legend('Row 1 (Smoothed)', 'Row 2 (Smoothed)', 'Row 3 (Smoothed)'); % Legend for smoothed plots

5
MATLAB function ‘movmean’ returns an array of local k-point mean values,
where each mean is calculated over a sliding window of length k across neighboring
elements of A. After running the code, I obtained the plot shown in Figure 2.1.

Figure 2.1 – Smoothed plots

Now, you can see the smoothed graphs. There are three graphs, with the first two
signals oscillating around 0, and the other one oscillating around -1000. Filtration is
one of the essential techniques in the automation industry for controlling processes in
a plant. For example, by applying this method, the operator can ensure that the sensor
displays accurate values without fluctuations.

There is another dataset used to train a new model. In this example, the data
represents the top universities in the world. Following the same principle as before,
the graph was plotted and is shown in Figure 2.2.

Figure 2.2 – Top Ranked Universities

6
CONCLUSION

In conclusion, MATLAB is a powerful tool that allows for reading large datasets
and training models. In our case, we used vibration data and wrote code to smooth it.
We used built-in functions to read and apply smoothing methods to the datasets.
MATLAB also provides clear presentation of graph plots with multiple colors, which
enhances data visualization. Firstly, the compilation took a long time before the
resulting plot appeared. The reason was that the dataset was slightly large, so it had to
be reduced for further operations. By simplifying all of this, the dataset can be prepared
for machine learning training.

You might also like