3. System Setting
3
Language & IDE
• Matlab Installation
• 학교에서 제공하는 사용자 가이드 파일을 기준으로 설치
(파일정보: [SWCON254] Exercise_02_Matlab Setting (MATLAB 설치 및 사용 가이드).pdf)
• 해당 파일의 ‘1-1. 개인 - MATLAB (Individual) 라이선스 설치’ 항목을 따라서 설치
• Reminders
• 경희대학교 전용 Matlab 포털 사이트
(https://kr.mathworks.com/academia/tah-portal/kyung-hee-university-31673140.html)
• 본 가이드의 경우 2023a버전으로 진행
4. System Setting
4
Language & IDE
• Matlab Installation
• 학교에서 제공하는 사용자 가이드 파일을 기준으로 설치
(파일정보: [SWCON254] Exercise_02_Matlab Setting (MATLAB 설치 및 사용 가이드).pdf)
• ‘1-1-d. MATLAB Online 실행 또는 인스톨러를 이용하여 데스크탑 버전 설치’ 항목에서 우측 그림의 Toolbox
추가
Reference: MATLAB 설치 및 사용 가이드 및 CWL 제공 제품 목록 2023, 2023. 경희대학교. & [SWCON254] Exercise_02_Matlab Setting (MATLAB 설치 및 사용 가이드).pdf
5. System Setting
5
Language & IDE
• ASIO4ALL
• ASIO (Audio Stream Input/Output) 프로토콜을 사용하기 위한 드라이버 설치
(링크: https://asio4all.org/about/download-asio4all/)
• 해당 링크에서 다운로드 후 더블 클릭하여 설치 설치 후 재부팅 필요!
• Matlab에서 ASIO관련 작업 시 Desktop 작업표시줄 (우하단 Tray)에 초록 혹은 파랑 아이콘 생성됨.
Reference: MATLAB 설치 및 사용 가이드 및 CWL 제공 제품 목록 2023, 2023. 경희대학교. & [SWCON254] Exercise_02_Matlab Setting (MATLAB 설치 및 사용 가이드).pdf
7. Basic Operations
7
Matlab
• Code & Description
Comment:
>> % This is a comment, it starts with a “%”
Arithmetic Operations:
>> y = 5*3 + 2^2; % simple arithmetic
Creating Vector:
>> x = [1 2 4 5 6]; % create the vector “x”
Element-wise Operation:
>> x1 = x.^2; % square each element in x
Indexing:
x2 = x(1:3); % Select first 3 elements in x
Reference: Jiyoung Jung. Circuit and Signals Lecture Note Spring 2021, Kyung Hee University, 2021. Jiyoung Jung.
8. Basic Operations
8
Matlab
• Code & Description
Signal Power & Energy:
>> E = sum(abs(x).^2); % Calculate signal energy
>> P = E/length(x); % Calculate av signal power
Plot:
>> t = 0:0.1:100; % Generate sampled time
>> x3=exp(-t).*cos(t); % Generate a discrete signal
>> plot(t, x3, ‘x’); % Plot points
Complex Number:
>> z = 1+i; % Create a complex number
>> a = real(z); % Pick off real part
>> b = imag(z); % Pick off imaginary part
Reference: Jiyoung Jung. Circuit and Signals Lecture Note Spring 2021, Kyung Hee University, 2021. Jiyoung Jung.
9. Basic Operations
9
Matlab
• Loop
• For Loop: Goes round the for loop 100 times, starting at i=1 and finishing at i=100
for i=1:100
sum = sum+i;
end
• While Loop: Similar, but uses a while loop instead of a for loop.
i=1;
while i<=100
sum = sum+i;
i = i+1;
end
Reference: Jiyoung Jung. Circuit and Signals Lecture Note Spring 2021, Kyung Hee University, 2021. Jiyoung Jung.
10. Basic Operations
10
Matlab
• DT Convolution in Matlab
Function: conv()
To see how this works, type ‘help{function name}’:
>> help conv
Example:
>> h = [1 1 1 0 0];
>> x = [0.5 2 0 0 0];
>> y = conv(x, h)
>> idx = [-1:1:numel(y)-1];
>> stem(idx, [0 y])
Reference: Jiyoung Jung. Circuit and Signals Lecture Note Spring 2021, Kyung Hee University, 2021. Jiyoung Jung.
11. Basic Operations
11
Matlab
• Matlab Audio Toolbox
Matlab offers variety of toolbox to support the variety of computations. Audio Toolbox offers may functions
to handle audio data and to process audio data (e.g., deep learning).
Audio Load & Metadata: 압축 포멧, 샘플레이트(Hz), 길이, 등의 메타 데이터를 확인 가능
>> audioFile="Recording.m4a";
>> [audioData,fs] = audioread("Recording.m4a");
>> audioInfo = audioinfo(filename)
Reference: Audio Toolbox Documentation- MathWorks 한국. (n.d.). https://kr.mathworks.com/help/audio/index.html?s_tid=CRUX_lftnav
12. Basic Operations
12
Matlab
• Audio Signal Processing
Audio Load & Metadata:
>> audioFile="Recording.m4a";
>> [audioData,fs] = audioread("Recording.m4a");
Audio Play:
>> soundsc(audioData,fs)
Audio Plot:
>> audioDur=length(audioData)/fs;
>> t=(0:1/fs:audioDur);
>> t(end)=[]; %Delete the last time index
>> plot(t, audioData)
Reference: Audio Toolbox Documentation- MathWorks 한국. (n.d.). https://kr.mathworks.com/help/audio/index.html?s_tid=CRUX_lftnav
Time (s)
14. Signal Acquisition
14
Audio Recording
• Window 10 음성녹음기
Window 10 음성녹음기 응용프로그램을 이용하여, 본인의 목소리를 녹음하기.
예: 소프트웨어 융합학과
녹음 버튼 클릭 후 녹음 ‘파일 위치 열기’ 클릭 저장 된 폴더로 이동 후 녹음 파일을 Matlab 작업 폴더로
복사
Reference: MATLAB 설치 및 사용 가이드 및 CWL 제공 제품 목록 2023, 2023. 경희대학교. & [SWCON254] Exercise_02_Matlab Setting (MATLAB 설치 및 사용 가이드).pdf
16. Signal Processing
16
Audio Signal Processing
• 내 목소리의 재생해보기
목표: Matlab의 내 목소리를 녹음한 파일을 재생하는 코드를 작성해본다.
Code:
clc % Workspace Initialization
clear
audioFile="Recording.m4a"; % File Loading
[audioData,fs] = audioread(audioFile);
audio_info = audioinfo(audioFile) % Print File Meta Data
soundsc(audioData,fs) % Play The File
Reference: MATLAB. (2022b, April 28). How to Do FFT in MATLAB. YouTube. https://www.youtube.com/watch?v=XEbV7WfoOSE
17. Signal Processing
17
Audio Signal Processing
• 내 목소리의 변조해보기 (Time Reversal & Scaling)
목표: Matlab의 내장함수를 이용하거나 혹은 개별 함수를 작성하여 내 목소리를 변조하는 코드를 작성해본
다.
Time Reversal:
𝑥 𝑛 → 𝑥 −𝑛
Use ‘flip’ function or own function to reverse the recorded data
Scaling:
𝑥 𝑛 → 𝑥 𝑎𝑛
𝑎. Please check the details of ‘resample’ function in Matlab for those interested in the content.
Reference: MATLAB. (2022b, April 28). How to Do FFT in MATLAB. YouTube. https://www.youtube.com/watch?v=XEbV7WfoOSE
18. Signal Processing
18
Audio Signal Processing
• 내 목소리의 변조해보기 (Filtering)
목표: Matlab의 Filter Designer를 이용하여 내 목소리를 변조하는 필터를 작성해본다.
• Step #1: 실행하기
Code: Matlab 명령창에 ‘filterDesigner’ 작성
>> filterDesigner
• Step #2: Parameter 넣기
(1) 필터 유형 결정: LPF, HPF, BPF
(2) 필터 종류 결정: FIR or IIR
(3) 주파수 관련 정보: sample rate, pass band, stop band 설정
• Step #3: Code 생성하기
[파일]-[MATLAB 코드생성]-[필터 설계 함수]를 차례대로 눌러서 필터를 root 폴더에 저장한다
Reference: MATLAB. (2022b, April 28). How to Do FFT in MATLAB. YouTube. https://www.youtube.com/watch?v=XEbV7WfoOSE
20. Signal Processing
20
Audio Signal Processing
• 내 목소리의 변조해보기 (Filtering)
• Step #4: 적용하기
Code:
>> [audioData,fs] = audioread(audioFile);
…
% Type the name of the filter script for the first argument of ‘filter’ function
>> audioFiltered = filter(FIR_Filter, audioData);
Reference: MATLAB. (2022b, April 28). How to Do FFT in MATLAB. YouTube. https://www.youtube.com/watch?v=XEbV7WfoOSE
Frequency (Hz)
Before
Frequency (Hz)
After
21. Signal Processing
21
Audio Signal Processing
• 내 방의 Impulse Response 측정해보기
목표: Matlab의 Impulse Response Measurer를 이용하여 내 방의 Impulse Response를 측정해본다.
(관련자료: https://kr.mathworks.com/help/audio/ref/impulseresponsemeasurer-
app.html?searchHighlight=impulse%20response&s_tid=srchtitle_impulse%20response_1)
• Step #1: 실행하기
Code: Matlab 명령창에 ‘impulseResponseMeasurer’ 작성
>> impulseResponseMeasurer
Reference: Audio Toolbox Documentation- MathWorks 한국. (n.d.). https://kr.mathworks.com/help/audio/index.html?s_tid=CRUX_lftnav
22. Signal Processing
22
Audio Signal Processing
• 내 방의 Impulse Response 측정해보기
• Step #2: 입출력 채널 확인
제어판 ’보기기준’ 큰 아이콘으로 변경 소리
재생 탭: 재생 탭에서 사용할 스피커 이외의 장치를 우클릭
하여,‘사용 안 함’으로 변경
녹음 탭: 녹음 탭에서 사용할 마이크 이외의 장치를 우클릭
하여,‘사용 안 함’으로 변경
Reference: Audio Toolbox Documentation- MathWorks 한국. (n.d.). https://kr.mathworks.com/help/audio/index.html?s_tid=CRUX_lftnav
23. Signal Processing
23
Audio Signal Processing
• 내 방의 Impulse Response 측정해보기
• Step #3: 디바이스 관련 셋팅
다음 슬라이드의 그림과 함께 보기
• (1) 출력 채널 설정: Audio Device = ASIO 4 All ; Player Channel = 1,2 ; Recorder Channel = 1;
• (2) Level Monitor 켜기
• (3) 출력 장치 확인: Level Monitor 에서 Pink Noise 선택 후 Play Button 클릭하여 소리가 재생되고 녹음 중인
지 확인.
재생: 스피커에서 소리가 들리는지 확인 & 녹음: 소리를 내서 Recorder의 바가 올라가는지 확인
재생이나 녹음이 안될 시에 ASIO4ALL 인터페이스에서 전원 모양 버튼을 켜고 끄면서
재생과 녹음이 가능한 디바이스 찾기. 이전 단계에서 제어판 소리에서 사용으로 설정한 디바이스를 찾기!
Reference: Audio Toolbox Documentation- MathWorks 한국. (n.d.). https://kr.mathworks.com/help/audio/index.html?s_tid=CRUX_lftnav
25. Signal Processing
25
Audio Signal Processing
• 내 방의 Impulse Response 측정해보기
• Step #3: 측정 관련 셋팅
다음 슬라이드의 그림과 함께 보기
• (1) Method: Exponential Swept Sine으로 변경
• (2) Display: Phase Response 추가
• (3) Capture: 녹음기 모양 버튼을 눌러서 예시와 같이 측정해보기
Reference: Audio Toolbox Documentation- MathWorks 한국. (n.d.). https://kr.mathworks.com/help/audio/index.html?s_tid=CRUX_lftnav