일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 그람-슈미트 과정#gram-schmidt process
- reflection matrix
- weighted least-squares
- 계수내림법#reduction of order#wronskian#론스키안#아벨항등식#abel's identity
- 여인자
- 변수분리#동차 미분방정식#완전 미분방정식
- 푸리에 정리
- 선형독립#기저벡터#선형확장#span#basis
- dirichlet
- 선형변환#contraction#expansions#shears#projections#reflection
- 상태천이행렬#적분인자법#미정계수법#케일리-헤밀톤 정리
- 정규직교행렬
- 선형 상수계수 미분방정식#lccode#sinusoidal input
- 추정문제#normal equation#직교방정식#정사영#정사영행렬#정사영 변환
- 미분방정식 #선형 미분방정식 #상미분 방정식
- 직교행렬#정규직교행렬#orthonormal#reflection matrix#dcm
- 비제차#제차해#일반해#적분인자#적분인자법#homogeneous sol#nonhomogeneous sol#integrating factor
- 가중 최소제곱법
- 2계미방#모드#mod#특성방정식#characteristic eq#제차해
- 선형시스템연산자#라이프니츠 법칙#fundamental theorem of algebra#erf
- 내적 공간#적분
- 푸리에 급수
- 최소자승#least-square#목적함수#양한정#정점조건#최소조건
- 여인수 행렬
- 부분 분수분해
- 베르누이 미분방정식
- 오일러-코시 미방#계수내림법
- 내적#duality#쌍대성#dot product
- 멱급수법
- linespectra#feurierseries#푸리에 급수
Archives
OnlyOne
Practice[MAF] 본문
Practice[MAF]
Intro
In this practice, I will get data from Lida in the Txt file and filter the moving average filter.
Header File
/*====================================================================================
Handong Global University
--------------------------------------------------------------------------------------
Name: Taesan Kim
ID: 22300203
Create: 2024.07.17
Modifire: 2024.07.17
--------------------------------------------------------------------------------------
레이더 자료를 가져와서 MAF를 적용한 뒤, 새로운 파일에 저장한다.
====================================================================================*/
#ifndef MYLIDAR_H
#define MYLIDAR_H
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/**
* @breif 레이더 파일 열기
* 레이더 파일을 열어서 정보를 가공한다.
* @param num1: 복소수1
* @param num2: 복소수2
*
* @return: 복소수1과 복소수2를 더한 값
*/
typedef struct _LIDAR
{
double* range;
double* angle;
int size;
} LIDAR;
typedef struct _STRUCTURE
{
double* x;
double* y;
int size;
} STRUCTURE;
void read_file(const char* file_name, LIDAR* data);
void save_file(const char* file_name, STRUCTURE* data);
void clear_buffer(LIDAR* data);
void clear_structure_buffer(STRUCTURE* data);
/**
* @breif MAF연산기능
* MAF연산을 돕는다.
* @param buffer: MAF의 버퍼값
* @param array[]: MAF를 적용할 리스트 이름
* @param size: array리스트의 요소 개수
*
* @return: 없음, array리스트에 MAF를 적용한 데이터를 넣어준다.
*/
void maf(int buffer, LIDAR* data);
#endif //MYLIDAR_H
Source File
#include "../include/myLIDAR.h"
void read_file(const char* file_name, LIDAR* data) {
FILE* file;
errno_t err = fopen_s(&file, file_name, "r");
if (err != 0) {
perror("Error opening file");
return;
}
if (file == NULL) {
perror("Error opening file");
return;
}
int word;
int line_count = 0;
do {
word = fgetc(file);
if (word == '\n') line_count++;
} while (word != EOF);
if (line_count < 1) {
fclose(file);
return;
}
data->range = (double*)malloc(sizeof(double) * line_count);
data->angle = (double*)malloc(sizeof(double) * line_count);
data->size = line_count;
fseek(file, 0, SEEK_SET);
for (int line = 0; line < line_count; line++) {
fscanf_s(file, "%lf\t%lf\n", data->range + line, data->angle + line);
}
fclose(file);
}
void save_file(const char* file_name, STRUCTURE* data) {
FILE* file;
errno_t err = fopen_s(&file, file_name, "w+t");
if (err != 0) {
perror("Error opening file");
return;
}
if (file == NULL) {
perror("Error opening file");
return;
}
for (int i = 0; i < data->size; i++) {
fprintf_s(file, "%f\t%f\n", data->x[i], data->y[i]);
}
fclose(file);
}
void clear_buffer(LIDAR* data)
{
if (data->range != NULL) {
free(data->range);
data->range = NULL;
}
if (data->angle != NULL) {
free(data->angle);
data->angle = NULL;
}
}
void clear_structure_buffer(STRUCTURE* data) {
if (data->x != NULL) {
free(data->x);
data->x = NULL;
}
if (data->y != NULL) {
free(data->y);
data->y = NULL;
}
}
void maf(int buffer, LIDAR* data)
{
data->size;
int data_size = (*data).size;
if (buffer > data_size) {
printf("Buffer cannot bigger than List size!!");
return;
}
for (int i = 0; i < data_size; i++) {
float sum = 0.0;
int count = 0;
for (int j = i; j >= 0 && count < buffer; j--) {
sum += data->range[j];
count++;
}
data->range[i] = sum / count;
}
}
Main
#include "include/myLIDAR.h"
int main() {
const char* filepath = "lidar_rawdata.txt";
LIDAR data;
STRUCTURE data_result;
STRUCTURE maf_data_result;
read_file(filepath, &data);
for (int i = 0; i < data.size; i++) {
printf("Range: %lf, Angle: %lf\n", data.range[i], data.angle[i]);
}
data_result.size = data.size;
data_result.x = (double*)malloc(data.size * sizeof(double));
data_result.y = (double*)malloc(data.size * sizeof(double));
for (int j = 0; j < data.size; j++) {
data_result.x[j] = data.range[j] * cos(data.angle[j]);
data_result.y[j] = data.range[j] * sin(data.angle[j]);
}
save_file("output.txt", &data_result);
clear_structure_buffer(&data_result);
// 버퍼 크기 입력
int buffer = 5;
maf(buffer, &data);
maf_data_result.size = data.size;
maf_data_result.x = (double*)malloc(data.size * sizeof(double));
maf_data_result.y = (double*)malloc(data.size * sizeof(double));
for (int j = 0; j < data.size; j++) {
maf_data_result.x[j] = data.range[j] * cos(data.angle[j]);
maf_data_result.y[j] = data.range[j] * sin(data.angle[j]);
}
save_file("maf_output.txt", &maf_data_result);
clear_buffer(&data);
clear_structure_buffer(&maf_data_result);
return 0;
}
* You should set the txt file in the same folder as the main.cpp file.
'Control Engineering > C Programming' 카테고리의 다른 글
Function&Array (0) | 2024.09.04 |
---|---|
배열(Array) 기초 (0) | 2024.09.04 |
Practice[Integral] (0) | 2024.09.04 |
Practice[Root Formula] (0) | 2024.09.04 |
구조체(Derived Type) (0) | 2024.09.04 |