startup

Signal Processing + Control & Dynamics 중심의 Octave 학습 예제

startup.m

코드 인덱스로 돌아가기

카테고리

Project Starters

학습 소스 그룹

코드 길이

94

lines

작성자

-

날짜 정보 없음

패키지

io, signal

pkg load 기준

전체 코드

전체 코드를 복사해서 Octave에서 바로 실행할 수 있습니다.

% REPL(Read-Eval-Print Loop)은 대화형 환경이다.
% startup.m 파일은 프로젝트 루트에 위치한다.
% startup.m REPL 세션이 시작할 떄 가장 먼저 자동으로 실행된다.
% main.m 프로세스가 시작할 때 clear all 명령에 의해 무효화될 수 있다.
% 메인 코드에서 clear all 하면 pkg는 무효화되고 default param은 유지된다.

clc; clear all; close all; 
addpath(genpath("C:/dev/github-copy/octave-lib")); # never run in /users/user

pkg load io
pkg load signal
# pkg load statistics
# pkg load image
# pkg load optim
# pkg load control
# pkg load symbolic

# 환경변수에 colored 함수 사용 가능함을 기록함
# strcmp(getenv("COLORTEXT"), "true")  % 사용할 떄
setenv("COLORTEXT", "true");  % 기록할 때

printf(fmt("{mfilename} root - project\n", "#FF5733"));

fontsize = 14;

color_base = [
    hex2color("#69A1FA"), % 파란색
    hex2color("#CF87DA"), % 보라색
    hex2color("#00CC6A"), % 녹색
    hex2color("#FADB79"), % 노란색
    hex2color("#5678C5"), % 조금 더 진한 파란색
    hex2color("#A84AC5"), % 깊은 보라색
    hex2color("#00B85A"), % 진한 녹색
    hex2color("#E5C441"), % 진한 노란색
    hex2color("#508BD1"), % 회색이 섞인 파란색
    hex2color("#9A59D7")  % 고급스러운 보라색
];

% Position
screenSize = get(0, "ScreenSize"); % [x y width height]
screenWidth = screenSize(3);
screenHeight = screenSize(4);
windowWidth = floor(screenWidth / 3);
windowHeight = floor(screenHeight / 3);
left = (screenWidth - windowWidth) / 2;
bottom = (screenHeight - windowHeight) / 2;
position = [left, bottom, windowWidth, windowHeight];

% figure
set(0, "defaultFigurePosition", position);
set(0, "defaultFigureName", "Figure");
set(0, "defaultFigureColor", "#FFFFFF");
set(0, "defaultFigureNumberTitle", "off");

% axes
set(0, "defaultAxesFontSize", fontsize);
set(0, "defaultAxesLineWidth", 0.5);
set(0, "defaultAxesXGrid", "on");
set(0, "defaultAxesYGrid", "on");
set(0, "defaultAxesZGrid", "on");
set(0, "defaultAxesNextPlot", "add");
set(0, "defaultAxesColorOrder", color_base);

# set(0, "defaultAxesXlabel", "Time [sec]");  # 레전드축에도 적용된다.
# set(0, "defaultAxesYlabel", "Amplitude");  # 레전드축에도 적용된다.
# set(0, "defaultAxesXColor", "#FF0000");  # 일반적이지 않다.
# set(0, "defaultAxesYColor", "#00FF00");  # 일반적이지 않다.
# set(0, "defaultAxesZColor", "#0000FF");  # 일반적이지 않다.

% plot
set(0, "defaultLineLineWidth", 1.0);
# set(0, "defaultLineMarkerSize", 8);

% text
set(0, "defaultTextFontSize", fontsize);

# set(0, "defaultTextInterpreter", "none");
# set(0, "defaultTextColor", "#293134");
# set(0, "defaultTextUnits", "normalized");  # 레전드 텍스트가 이탈한다
# set(0, "defaultTextFontWeight", "bold");  # 너무 굵다

% patch
# set(0, "defaultPatchFaceColor", [1, 1, 1]);
# set(0, "defaultAxesColorOrder", color_base);

% legend
# set(0, "defaultLegendLocation", "northeast");
# set(0, "defaultLegendAutoUpdate", "on");
# set(0, "defaultLegendBox", "on");
# set(0, "defaultLegendColor", "none");
# set(0, "defaultLegendEdgeColor", "#C0C0C0");
# set(0, "defaultLegendFontSize", fontsize);
# set(0, "defaultLegendTextInterpreter", "none")

코드 해설

목적

Signal Processing + Control & Dynamics 중심의 Octave 학습 예제

입력

  • 스크립트 상단에서 정의한 파라미터/입력 데이터를 사용합니다.

출력

  • 그래프/figure 출력
  • 콘솔 텍스트 출력

실행 흐름

  1. plot

핵심 함수/주제

sethex2colorfloorscreenSizeaddpathfmtgenpathget

실습 과제

  • 샘플링 주파수나 입력 주파수를 바꿔 스펙트럼 변화를 비교해보세요.
  • 질량/감쇠/강성 또는 전달함수 계수를 바꿔 응답 변화를 확인해보세요.
  • 초기값을 2~3개 바꿔 최적해 수렴 차이를 기록해보세요.

학습 팁

  • 그래프 비교 시 축 범위(XLim/YLim)와 단위를 먼저 고정하면 해석 오류를 줄일 수 있습니다.
  • 입력 파일 경로가 현재 작업 디렉터리 기준인지 먼저 확인하세요.

같은 카테고리의 다른 코드