FBG Data Processing and Plotting Method Based on Matlab
Matlab processes FBG data, solves the problems of complex and large errors in Excel operations, and realizes fast and efficient data conversion and batch drawing, improving data processing efficiency and accuracy.
Patent Information
- Application Number
- CN202411443569.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2044-10-16
AI Technical Summary
In the prior art, the operation is complicated when using Excel to process FBG data, and artificial operation errors are prone to occur, and data processing efficiency is low.
Matlab is used to process FBG data, convert the txt file into a csv file by filtering valid information, calculate the wavelength difference and perform temperature compensation conversion, and finally convert the data into strain data, and batch drawing is performed.
It realizes fast and efficient data filtering and file format conversion, reduces human operation errors, saves human resources, and supports batch processing and visual drawing.
Smart Images

Figure CN119337610B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of FBG data processing, and particularly relates to a method for processing and plotting FBG data based on Matlab. Background Art
[0002] Currently, when processing the data obtained from fiber Bragg grating (FBG) sensors and performing graphical analysis, the prior art often uses Excel to process a large amount of spectral data generated by FBG monitoring. However, traditional Excel tools are complex to operate, and many processing steps need to be performed manually, with a rather cumbersome process, resulting in low data processing efficiency. Moreover, a large number of files need to be processed manually. For example, when calculating the wavelength difference, the traditional Excel processing method requires selecting corresponding data for subtraction and performing formula conversion for a single file, consuming a large amount of manpower and being prone to human operation errors. At the same time, during the plotting setting process, users need to click one by one to select the data range, set the calculation formula, and adjust the chart options, with complex operations. These repetitive tasks consume a large amount of human resources and are prone to errors.
[0003] Matlab, as a high-performance numerical calculation and data analysis software, has powerful functions in data processing and graph plotting, making it an ideal tool for processing FBG data. However, how to use Matlab to process FBG data is an urgent problem to be solved. Summary of the Invention
[0004] The purpose of the present invention is to provide a method for processing and plotting FBG data based on Matlab, which solves the problems of complex operation and prone to human operation errors when using Excel to process FBG data in the prior art.
[0005] The technical solution adopted by the present invention is a method for processing and plotting FBG data based on Matlab, including the following steps:
[0006] Step 1: Collect a txt file containing wavelength data through an FBG device, and filter out valid information through Matlab to convert the txt file into a csv file;
[0007] Step 2: Traverse all csv files in Step 1 through Matlab, subtract the wavelength data at all monitoring point positions from the wavelength data at the initial monitoring position to obtain wavelength difference data;
[0008] Step 3: Perform temperature compensation conversion through Matlab to calculate the true wavelength difference data;
[0009] Step 4: Convert the true wavelength difference data obtained in Step 3 into strain data through Matlab and save it in the corresponding position folder;
[0010] Step 5: Read the strain data strain curve graph obtained in Step 4 through Matlab, and save the processed strain curve graph to another specified folder.
[0011] The features of the present invention also lie in:
[0012] The specific process of Step 1 is as follows:
[0013] Step 1.1: Define the source folder path: folder_path, and the new folder path: new_folder_path, and check again whether the new folder exists. If it does not exist, recreate the new folder;
[0014] Step 1.2: Use the dir function in Matlab to obtain the file list of all txt files in the source folder, traverse the file list of all txt files, filter out valid data and convert it into a csv file.
[0015] The specific steps of Step 1.2 are as follows:
[0016] Step 1.2.1: Traverse all txt files in the source folder;
[0017] Step 1.2.2: Obtain the file name of each txt file;
[0018] Step 1.2.3: Construct the complete file path of the txt file;
[0019] Step 1.2.4: Use the fopen function in Matlab to open the txt file and read the content;
[0020] Step 1.2.5: Use the textscan function in Matlab to split the text content of the txt file by line;
[0021] Step 1.2.6: Close the txt file;
[0022] Step 1.2.7: Delete the useless data corresponding to the device id and date;
[0023] Step 1.2.8: Construct a new file name and path;
[0024] Step 1.2.9: Use the fopen function in Matlab to open the new file in Step 1.2.8 in write mode;
[0025] Step 1.2.10: Use the fprintf function in Matlab to write the data processed in Step 1.2.7 into the new file to generate a csv file;
[0026] Step 1.2.11: Close the csv file.
[0027] The specific steps of Step 2 are as follows:
[0028] Step 2.1: Read the content of all csv files in Step 1, and customize the interception of data in the csv files so that the data size in each csv file is the same;
[0029] Step 2.2: Traverse all the csv files intercepted in Step 1, calculate the difference between the wavelength data in each csv file and the wavelength data at the initial monitoring position, and retain the data related to time in the first and second columns of each csv file. The wavelength data at the initial monitoring position is specifically the data collected at the position of the first grating during the monitoring process;
[0030] Step 2.3: Except for the data in the first and second columns of the csv files in Step 2.2, number the remaining column data in ascending order, and the number of numbers is equal to the number of gratings arranged. Then generate a new csv file as the wavelength difference file and store it in the specified new folder.
[0031] The specific steps of Step 3 are as follows:
[0032] Step 3.1: Traverse the new folder in Step 2;
[0033] Step 3.2: Read each wavelength difference file.
[0034] Step 3.3: Subtract the remaining column data in the wavelength difference file except for the data in the first and second columns related to time from the independently set temperature compensation column data. The independently set temperature compensation column data is obtained by collecting data at independent grating monitoring points.
[0035] Step 3.4: Rename the wavelength difference file in Step 3.3 to the true wavelength difference file.
[0036] Step 3.5: Generate a new csv file according to the true wavelength difference file in Step 3.4 and store it in the specified new folder.
[0037] Step 3.6: Delete the folder where the wavelength difference file in Step 2 is located.
[0038] The specific steps of Step 4 are as follows:
[0039] Step 4.1: Use the uigetdir function in Matlab to pop up a dialog box, select the new folder in Step 3.4, and generate another new folder for storing the newly generated files;
[0040] Step 4.2: Use the dir function in Matlab to list all csv files containing the true wavelength difference and traverse them, and convert the true wavelength difference data into strain data.
[0041] The specific steps of Step 4.2 are as follows:
[0042] Step 4.2.1: Use the fullfile function in Matlab to construct the full file path of the csv file containing the true wavelength difference;
[0043] Step 4.2.2: Use the readtable function in Matlab to read the csv file containing the true wavelength difference and convert it into a table format;
[0044] Step 4.2.3: Except for the first and second column data related to time in the csv file in Step 4.2.2, multiply the remaining column data by K;
[0045] In Step 4.2.3, K represents the strain sensitivity coefficient of the relative wavelength drift of the fiber grating, and the specific calculation formula is as follows:
[0046]
[0047] Among them, and represent the elasto-optic coefficient of the material, v represents the Poisson's ratio, represents the effective refractive index, is the Bragg center wavelength difference, is the Lame constant, is the longitudinal expansion strain of the optical fiber.
[0048] Step 4.2.4: After the processing in 4.2.3, the data in the csv file is converted from the true wavelength difference data into strain data. Use the fileparts function in Matlab to decompose the file path of the true wavelength difference csv file in Step 4.2.3, obtain the file name and modify the file name to the strain data csv file through the strrep function;
[0049] Step 4.2.5: Use the fullfile function in Matlab to construct the new csv file path, including the new file name and extension;
[0050] Step 4.2.6: Use the writetable function in Matlab to write the processed table data into the new csv file.
[0051] The specific process of Step 5 is as follows:
[0052] Step 5.1: Use the uigetdir function in Matlab to pop up a dialog box, select the folder containing the strain data in Step 4 as the data source, and create another new folder to store the line charts.
[0053] Step 5.2: Use the dir function in Matlab to list all csv files in the data source, and traverse each csv file to obtain the strain data and plot the line charts.
[0054] In Step 5.2, traverse each csv file, obtain the strain data, and plot the line charts. The specific operations are as follows:
[0055] Step 5.2.1: Create a new figure window and use the fullfile function in Matlab to construct the complete csv file path.
[0056] Step 5.2.2: Use the readtable function in Matlab to read the csv file to obtain the strain data.
[0057] Step 5.2.3: Obtain the time data, where each row represents 0.001 seconds;
[0058] Step 5.2.4: Plot the line charts for each column of data;
[0059] Step 5.2.5: Set the figure properties, specifically including the horizontal axis label, vertical axis label, title, and legend;
[0060] Step 5.2.6: Save the figure as a PNG format file and rename the file according to the user's requirements;
[0061] Step 5.2.7: Close the figure window, and after all files are processed, display a message indicating that all line charts have been saved.
[0062] The beneficial effects of the present invention are:
[0063] The present invention provides a method for FBG data processing and graphing based on Matlab. This method reads all data by traversing the folder, can artificially set the effective information screening range, converts the txt format data collected by FBG into csv format data that is convenient for processing. The operation is simple, and it can quickly and efficiently implement the preprocessing process of data screening and file format conversion; at the same time, this method can calculate the wavelength difference in batches and convert the data into strain values. The entire process is fully implemented based on Matlab, with simple operation, saving a large amount of human resources, and not containing human operation errors. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 is a flowchart of the method for FBG data processing and graphing based on Matlab of the present invention;
[0065] Figure 2 It is the layout diagram of the FBG sensor with a total length of 15.14 m and the pipeline test system in Comparative Example 1 of the present invention;
[0066] Figure 3 It is the summary diagram of the FBG data file collected in 1 minute in Comparative Example 1 of the present invention;
[0067] Figure 4 It is the display diagram of the size of a single FBG file in Comparative Example 1 of the present invention;
[0068] Figure 5 It is the summary diagram of the total time consumed in the processing flow in Embodiment 1 of the present invention;
[0069] Figure 6 It is the line graph of the change of the data in the first column of the csv file containing strain data over time in Embodiment 1 of the present invention;
[0070] Figure 7 It is the line graph of the change of the data in the third and fourth columns of the csv file containing strain data over time in Embodiment 1 of the present invention;
[0071] Figure 8 It is the line graph of the change of the data in the third to fifth columns of the csv file containing strain data over time in Embodiment 1 of the present invention;
[0072] Figure 9 It is the layout diagram of the FBG sensor with a total length of 130 m and the pipeline test system in Comparative Example 2 of the present invention;
[0073] Figure 10 It is the summary diagram of the FBG data file collected in 5 minutes in Comparative Example 2 of the present invention;
[0074] Figure 11 It is the display diagram of the size of a single FBG file in Comparative Example 2 of the present invention;
[0075] Figure 12 It is the summary diagram of the total time consumed in the processing flow in Embodiment 2 of the present invention;
[0076] Figure 13 It is the line graph of the change of the data in the third to eighth columns of the csv file containing strain data over time in Embodiment 2 of the present invention. Detailed implementation manners
[0077] The present invention will be described in detail below in conjunction with the accompanying drawings and specific implementation manners.
[0078] The FBG data processing and graphing method based on Matlab of the present invention includes the following steps:
[0079] Step 1: Collect a txt file containing wavelength data through an FBG device, and use Matlab to filter out valid information and convert the txt file into a csv file;
[0080] The specific process of Step 1 is as follows:
[0081] Step 1.1: Define the source folder path: folder_path, and the new folder path: new_folder_path, and check again whether the new folder exists. If it does not exist, create a new folder;
[0082] Step 1.2: Use the dir function in Matlab to obtain the file list of all txt files in the source folder, traverse the file list of all txt files, filter out valid data and convert it into a csv file;
[0083] The specific steps of Step 1.2 are as follows:
[0084] Step 1.2.1: Traverse all txt files in the source folder;
[0085] Step 1.2.2: Obtain the file name of each txt file;
[0086] Step 1.2.3: Construct the complete file path of the txt file;
[0087] Step 1.2.4: Use the fopen function in Matlab to open the txt file and read the text content;
[0088] Step 1.2.5: Use the textscan function in Matlab to split the text content of the txt file by line;
[0089] Step 1.2.6: Close the txt file;
[0090] Step 1.2.7: Delete the useless data corresponding to the device id and date; Since the data collected by FBG has the same format, the device id information and date information contained in it are usually regarded as useless information and do not participate in the data processing process. Therefore, after removing the device id information and date information in the data, it is saved;
[0091] Step 1.2.8: Construct a new file name and path;
[0092] Step 1.2.9: Use the fopen function in Matlab to open the new file in Step 1.2.8 in write mode;
[0093] Step 1.2.10: Use the fprintf function in Matlab to write the processed data in Step 1.2.7 into the new file to generate a csv file;
[0094] Step 1.2.11: Close the csv file.
[0095] Step 2: Traverse all the csv files in Step 1 through Matlab, subtract the wavelength data at all monitoring point positions from the initial monitoring position data to obtain the wavelength difference data.
[0096] The specific steps of Step 2 are as follows:
[0097] Step 2.1: Read the content of all csv files in Step 1 and customize the interception of data in the csv files so that the data sizes in each csv file are the same.
[0098] Step 2.2: Traverse all the csv files intercepted in Step 1, calculate the difference between the wavelength data in each csv file and the wavelength data at the initial monitoring position. Retain the data related to time in the first and second columns of each csv file. The wavelength data at the initial monitoring position is specifically the data collected at the position of the first grating during the monitoring process.
[0099] Step 2.3: Except for the data in the first and second columns of the csv files in Step 2.2, number the remaining column data in ascending order. The number of numbers is equal to the number of grating layouts. Then generate a new csv file as the wavelength difference file and store it in the specified new folder.
[0100] Step 3: Perform temperature compensation conversion through Matlab to calculate the true wavelength difference data.
[0101] The specific steps of Step 3 are as follows:
[0102] Step 3.1: Traverse the new folder in Step 2.4.
[0103] Step 3.2: Read each wavelength difference file.
[0104] Step 3.3: Subtract the data in the remaining columns of the wavelength difference file from the independently set temperature compensation column data, except for the data in the first and second columns related to time. The independently set temperature compensation column data is obtained by collecting data at independent grating monitoring positions. Specifically, since FBG sensors are sensitive to temperature, changes in the ambient temperature will directly affect the accuracy of strain measurement. Therefore, an independent grating monitoring position needs to be set up as the temperature compensation data collection point. Through effective temperature compensation, the accuracy and stability of data measurement can be ensured, avoiding data misreading caused by temperature fluctuations, and thus providing more reliable and accurate data support.
[0105] Step 3.4: Rename the wavelength difference file in Step 3.3 as the true wavelength difference file.
[0106] Step 3.5: Generate a new csv file based on the true wavelength difference file in Step 3.4 and store it in the specified new folder.
[0107] Step 3.6: Delete the folder where the wavelength difference file is located in Step 2.
[0108] Step 4: Use Matlab to convert the true wavelength difference data obtained in Step 3 into strain data and save it in the corresponding location folder. Converting the wavelength difference data after temperature compensation into strain data can further enhance the illustration of the data and more intuitively meet the actual requirements.
[0109] Step 4.1: Use the uigetdir function in Matlab to pop up a dialog box, select the new folder in Step 3.4, and generate another new folder for storing the newly generated files.
[0110] Step 4.2: Use the dir function in Matlab to list all csv files containing the true wavelength difference and traverse them to convert the true wavelength difference data into strain data.
[0111] The specific steps of Step 4.2 are as follows:
[0112] Step 4.2.1: Use the fullfile function in Matlab to construct the complete file path of the csv file containing the true wavelength difference.
[0113] Step 4.2.2: Use the readtable function in Matlab to read the csv file containing the true wavelength difference and convert it into a table format.
[0114] Step 4.2.3: Exclude the first and second columns of data related to time in the csv file in Step 4.2.2, and multiply the remaining column data by K.
[0115] In Step 4.2.3, K represents the strain sensitivity coefficient of the relative wavelength drift of the fiber grating. The specific calculation formula is as follows:
[0116]
[0117] Among them, and represent the elasto-optic coefficients of the material, v represents the Poisson's ratio, represents the effective refractive index, is the Bragg center wavelength difference, is the Lame constant, is the longitudinal expansion strain of the optical fiber.
[0118] Step 4.2.4: After the processing in 4.2.3, the data in the csv file is converted from the true wavelength difference data to strain data. Use the fileparts function in Matlab to decompose the file path of the true wavelength difference csv file in Step 4.2.3, obtain the file name, and modify the file name to the strain data csv file through the strrep function.
[0119] Step 4.2.5: Use the fullfile function in Matlab to construct a new csv file path, including the new file name and extension.
[0120] Step 4.2.6: Use the writetable function in Matlab to write the processed tabular data into the new csv file.
[0121] Step 5: Select the saved strain data and plot the strain curve graphs corresponding to each channel.
[0122] Step 5.1: Use the uigetdir function in Matlab to pop up a dialog box, select the folder containing the strain data in Step 4 as the data source, and create another new folder to store the line graphs.
[0123] Step 5.2: Use the dir function in Matlab to list all csv files in the data source, and traverse each csv file to obtain the strain data and plot the line graph.
[0124] The specific operation of traversing each csv file and obtaining the strain data to plot the line graph in Step 5.2 is as follows:
[0125] Step 5.2.1: Create a new figure window and use the fullfile function in Matlab to construct the complete csv file path.
[0126] Step 5.2.2: Use the readtable function in Matlab to read the csv file to obtain the strain data.
[0127] Step 5.2.3: Obtain the time data, where each row represents 0.001 seconds.
[0128] Step 5.2.4: Plot the line graph of each column of data.
[0129] Step 5.2.5: Set the figure properties, specifically including the horizontal axis label, vertical axis label, title, and legend.
[0130] Step 5.2.6: Save the figure as a PNG format file and rename the file according to the user's requirements.
[0131] Step 5.2.7: Close the graph window, and after all files are processed, display a message indicating that all line graphs have been saved.
[0132] The FBG data processing and graphing method based on Matlab of the present invention reads all data by traversing folders, can artificially set the effective information screening range, converts the txt - format data collected by FBG into csv - format data for convenient processing, is easy to operate, and can quickly and efficiently implement the data screening and file - format pre - processing process; at the same time, it can calculate the wavelength difference in batches and convert the data into strain values. The whole process is implemented entirely based on Matlab, is easy to operate, saves a large amount of human resources, and does not contain human operation errors. At the same time, the processing process based on Matlab can implement the graphing function, select different data regions for visual graphing or save files.
[0133] The FBG data processing and graphing method based on Matlab of the present invention has the following specific embodiments:
[0134] Comparative Example 1
[0135] Carry out a grouting pipeline blockage simulation test, and use FBG sensors for monitoring. The total length of the test system is 15.14 m, and a total of 6 FBG sensors are arranged. Specifically, as Figure 2 shown in the figure, the grouting pump provides power for the entire grouting pipeline blockage simulation system. Mixing barrels 1 and 2 evenly mix the slurry to ensure that the slurry can be normally transported in the pipeline. The outlet of the grouting pump is connected to the pipeline inlet A of the metal pipeline through a high - pressure hose (DN32). The pipeline outlet B of the metal pipeline is connected to the inlet of mixing barrel 2 through a high - pressure hose (DN32). Between mixing barrel 2 and mixing barrel 1, and between the grouting pump are all connected through high - pressure hoses (DN32). The metal pipeline is fixed by several clamps. A main valve, a flowmeter, and a pressure gauge are arranged at the outlet of the grouting pump. The slurry flows from the outlet of the grouting pump along the high - pressure hose into the metal pipe, into mixing barrel 2, mixing barrel 1, and finally only into the grouting pump through the inlet of the grouting pump. Several FBG sensors are arranged on the metal pipeline between pipeline inlet A and pipeline outlet B, and a valve is arranged at the blockage point set on the metal pipeline. Specifically as follows:
[0136] Simulate different degrees of blockage states by closing the valve at the blockage point by different turns, and collect data through FBG. Tests of closing the valve at the blockage point by 2, 4, 6, 8, 10, and 12 turns are carried out respectively to simulate the working conditions under different blockage degrees. The monitoring duration is set to 1 min, and the data collected by FBG are summarized:
[0137] The summary graph of the FBG data files collected in 1 min is as Figure 3As shown, when the data acquisition duration is 1 min and the test pipeline length is 15.14 m, the file size collected for a single valve with a single blockage degree is about 300 KB, and the data volume is about 2,920 lines.
[0138] Meanwhile, the display graph of the size of a single FBG file, as Figure 4 shown, the experiment is based on the working condition of a pipeline length of 15.14 m and a data acquisition duration of 1 min. At this time, although the method of manually processing data using Excel tools is feasible, there is a hidden danger of errors in manual operations.
[0139] Example 1
[0140] On the basis of the above Comparative Example 1, the FBG data processing and graphing method based on Matlab of the present invention is used for post-processing of data. The process includes: batch reading of the txt files collected by FBG, screening valid data and converting it into csv files, calculating the wavelength difference, temperature compensation conversion, strain conversion, and batch graphing. Since the size of each file is not the same, normalization processing is required, that is, custom intercepting the data in the csv file to make the data size in each csv file the same. Here, taking 1,500 lines as the valid data, a total of 5-step processing procedures are performed on the above 7 files with a total size of about 2 MB, and the program response duration is output.
[0141] The summary graph of the total time consumed by the processing process, as Figure 5 shown, for a pipeline with a length of 15.14 m, taking 7 files with a collection duration of 1 min and 1,500 lines as the valid data, from batch reading, screening valid data and converting it into csv files, to wavelength difference calculation, temperature compensation conversion, strain conversion, and batch graphing, when all processes are completed, the total time is about:
[0142] 1.24 s + 51.39 s + 16.33 s + 6.67 s = 75.63 s
[0143] This method has no errors in manual operations, is simple to operate, and shows extremely high processing efficiency. Finally, the drawn strain curve graph, as Figures 6 - 8 shown, Figure 6 is a line graph of the change of the data in the third column of the csv file containing strain data over time, Figure 7 is a line graph of the change of the data in the third and fourth columns of the csv file containing strain data over time, Figure 8 is a line graph of the change of the data in the third to fifth columns of the csv file containing strain data over time, realizing batch graphing.
[0144] Comparative Example 2
[0145] Due to the small amount of data in Comparative Example 1, in order to verify the versatility of the method, a larger-scale grouting pipeline blockage simulation test was further carried out. The total length of the test system was increased to 130 m, and the number of FBG sensors was increased to 32. The schematic diagram of the FBG sensor layout and the pipeline test system are specifically as follows Figure 9 shown in the figure. In the figure, the grouting pump provides power for the entire grouting pipeline blockage simulation system. Mixing tanks 1 and 2 evenly mix the slurry to ensure that the slurry can be normally transported in the high-pressure hose. The outlet of the grouting pump is connected to the pipeline inlet A of the metal pipeline through a high-pressure hose. The pipeline outlet B of the metal pipeline is connected to the inlet of mixing tank 2 through a high-pressure hose. Mixing tank 2 to mixing tank 1 and the grouting pump are all connected through high-pressure hoses. The metal pipeline is fixed by several clamps. A valve 1, an electromagnetic flowmeter, and a pressure gauge are provided at the outlet of the grouting pump. A valve 9 is provided at the inlet of mixing tank 2. The slurry flows from the outlet of the grouting pump along the high-pressure hose into the metal pipe, into mixing tank 2, mixing tank 1, and finally only into the grouting pump at the inlet of the grouting pump. There are 7 valves on the metal pipeline between pipeline inlet A and pipeline outlet B, including: angle clamp valve knife gate valve A and angle clamp valve knife gate valve B, and the metal pipeline includes an electromagnetic flowmeter, a pressure gauge, and several FBG sensors. Specifically as follows:
[0146] Still, different degrees of blockage states are simulated by closing the valves in different numbers of turns, and data is collected through FBG. Tests of closing from 1 turn to 10 turns are carried out at the blockage point valve 2 to simulate the working conditions under different blockage degrees. The monitoring duration is extended to 5 min, and the data collected by FBG is summarized:
[0147] The summary diagram of the FBG data files collected in 5 min is as follows Figure 10 shown. When the data collection duration is 5 min and the test pipeline length is 130 m, the file size collected for a single valve with a single blockage degree has reached about 270 MB, and the data volume has reached 680,000 lines. Since a single file occupies too much system memory, the system often crashes during file operations, greatly reducing the efficiency of manual processing.
[0148] At the same time, the display diagram of the size of a single FBG file is as follows Figure 11 shown. The experiment is based on the working conditions of a pipeline length of 130 m and a data collection duration of 5 min. When this test system is applied to on-site engineering tests, it will face pipeline lengths of several kilometers and longer monitoring times. Therefore, it is basically infeasible to use Excel tools for manual data processing.
[0149] Example 2
[0150] Based on the above Comparative Example 2, the entire post-processing process of data is still carried out using the Matlab-based FBG data processing and plotting method of the present invention. The process includes: batch reading of the txt files collected by FBG, screening valid data and converting it into csv files, calculating the wavelength difference, temperature compensation conversion, strain conversion, and batch plotting. Since the size of each file is not the same, normalization processing is required. Here, taking 200,000 lines as the valid data, the above 10 files with a total size of about 2.7G are processed through a total of 5 steps, and the program response duration is output.
[0151] The summary graph of the total time consumption of the processing process is shown in Figure 12 As shown, for a pipeline with a length of 89.71m, 10 files with a collection duration of 5 minutes are taken. Taking 200,000 lines as the valid data, from batch reading, screening valid data and converting it into csv files, to wavelength difference calculation, temperature compensation conversion, strain conversion, and batch plotting, the entire process is completed. The total time is approximately:
[0152] 343.22s + 129.02s + 44.96s + 19.32s = 536.52s
[0153] For extremely large amounts of data, this method can still show extremely high processing efficiency through a simple processing process and finally draw a curve graph of strain, as shown in Figure 13 As shown. The line graph of the change of the data in columns 3 - 8 of the csv file containing strain data over time. Each column of data is the data collected by one FBG. Through the Matlab software, the txt files collected by FBG are batch read, valid data is retained and converted into csv files, then the wavelength difference is calculated, the temperature compensation factor is eliminated, and finally the wavelength difference is converted into strain data and batch plotted, effectively solving the problems of complex operation, low data processing efficiency, and human operation errors when using Excel tools.
Claims
1. A method for FBG data processing and graphing based on Matlab, characterized in that, It includes the following steps: Step 1: Collect a txt file containing wavelength data through an FBG device, and filter out the valid information through Matlab to convert the txt file into a csv file; Step 2: Traverse all the csv files in Step 1 through Matlab, subtract the wavelength data at all monitoring point positions from the initial monitoring position data to obtain the wavelength difference data; Step 3: Perform temperature compensation conversion through Matlab to calculate the true wavelength difference data; Step 4: Convert the true wavelength difference data obtained in Step 3 into strain data through Matlab and save it in the corresponding position folder; Step 5: Read the strain curve graph of the strain data obtained in Step 4 through Matlab and save the processed strain curve graph to another specified folder; The specific process of Step 1 is as follows: Step 1.1: Define the source folder path: folder_path, and the new folder path: new_folder_path, and check again whether the new folder exists. If it does not exist, recreate the new folder; Step 1.2: Use the dir function in Matlab to obtain the file list of all txt files in the source folder, traverse the file list of all txt files, filter out the valid data and convert it into a csv file; The specific steps of Step 1.2 are as follows: Step 1.2.1: Traverse all txt files in the source folder; Step 1.2.2: Obtain the file name of each txt file; Step 1.2.3: Construct the complete file path of the txt file; Step 1.2.4: Use the fopen function in Matlab to open the txt file and read the content; Step 1.2.5: Use the textscan function in Matlab to split the text content of the txt file by line; Step 1.2.6: Close the txt file; Step 1.2.7: Delete the useless data corresponding to the device id and date; Step 1.2.8: Construct a new file name and path; Step 1.2.9: Use the fopen function in Matlab to open the new file in Step 1.2.8 in write mode; Step 1.2.10: Use the fprintf function in Matlab to write the data processed in Step 1.2.7 into the new file to generate a csv file; Step 1.2.11: Close the csv file; The specific steps of Step 2 are as follows: Step 2.1: Read the content of all csv files in Step 1 and customize the interception of the data in the csv files to make the data size in each csv file consistent; Step 2.2: Traverse all the csv files intercepted in Step 1, calculate the difference between the wavelength data in each csv file and the wavelength data at the initial monitoring position, and retain the data related to time in the first and second columns of each csv file. The wavelength data at the initial monitoring position is specifically the data collected at the position of the first grating during the monitoring process; Step 2.3: Excluding the data in the first and second columns of the csv file in Step 2.2, number the remaining column data in ascending order, with the number of numbers being equal to the number of grating layouts. Then generate a new csv file as the wavelength difference file and store it in the specified new folder.
2. The FBG data processing and plotting method based on Matlab according to claim 1, wherein The specific steps of Step 3 are as follows: Step 3.1: Traverse the new folder in Step 2; Step 3.2: Read each wavelength difference file; Step 3.3: Excluding the data in the first and second columns related to time in the wavelength difference file, subtract the remaining column data from the independently set temperature compensation column data, and the independently set temperature compensation column data is obtained by collecting data from independent grating monitoring points; Step 3.4: Rename the wavelength difference file in Step 3.3 to the true wavelength difference file; Step 3.5: Generate a new csv file based on the true wavelength difference file in Step 3.4 and store it in the specified new folder; Step 3.6: Delete the folder where the wavelength difference file is located in Step 2.
3. The FBG data processing and plotting method based on Matlab according to claim 1, characterized in that, The specific steps of Step 4 are as follows: Step 4.1: Use the uigetdir function in Matlab to pop up a dialog box, select the new folder in Step 3.4, and create another new folder for storing the newly generated files; Step 4.2: Use the dir function in Matlab to list and traverse all csv files containing the true wavelength difference, and convert the true wavelength difference data into strain data.
4. The FBG data processing and graphing method based on Matlab according to claim 3, wherein, The specific steps of Step 4.2 are as follows: Step 4.2.1: Use the fullfile function in Matlab to construct the full file path of the csv file containing the true wavelength difference; Step 4.2.2: Use the readtable function in Matlab to read the csv file containing the true wavelength difference and convert it into a table format; Step 4.2.3: Excluding the data in the first and second columns related to time in the csv file in Step 4.2.2, multiply the remaining column data by K; Step 4.2.4: After being processed in 4.2.3, the data in the csv file is converted from the true wavelength difference data into strain data. Use the fileparts function in Matlab to decompose the file path of the true wavelength difference csv file in Step 4.2.3, obtain the file name, and modify the file name to the strain data csv file through the strrep function; Step 4.2.5: Use the fullfile function in Matlab to construct the new csv file path, including the new file name and extension; Step 4.2.6: Use the writetable function in Matlab to write the processed table data into the new csv file.
5. The FBG data processing and plotting method based on Matlab according to claim 4, characterized in that The K in Step 4.2.3 represents the strain sensitivity coefficient of the relative wavelength drift of the fiber grating, and the specific calculation formula is as follows: Among them, and represent the photoelastic coefficient of the material, v represents the Poisson's ratio, represents the effective refractive index, is the Bragg center wavelength difference, is the Lame constant, is the longitudinal expansion and contraction strain of the optical fiber.
6. The FBG data processing and plotting method based on Matlab according to claim 1, wherein, The specific process of Step 5 is as follows: Step 5.1: Use the uigetdir function in Matlab to pop up a dialog box, select the folder containing the strain data in Step 4 as the data source, and create another new folder for storing the line chart; Step 5.2: Use the dir function in Matlab to list all csv files in the data source, and traverse each csv file to obtain strain data and plot a line chart.
7. The FBG data processing and plotting method based on Matlab according to claim 6, wherein As described in Step 5.2, traverse each csv file to obtain strain data and plot a line chart. The specific operations are as follows: Step 5.2.1: Create a new figure window and use the fullfile function in Matlab to construct the complete csv file path; Step 5.2.2: Use the readtable function in Matlab to read the csv file to obtain strain data; Step 5.2.3: Obtain time data, where each row represents 0.001 seconds; Step 5.2.4: Plot a line chart for each column of data; Step 5.2.5: Set the figure properties, specifically including the horizontal axis label, vertical axis label, title, and legend; Step 5.2.6: Save the figure as a PNG format file and rename the file according to the user's needs; Step 5.2.7: Close the figure window, and after all files are processed, display a message indicating that all line charts have been saved.