MATLAB을 활용한 음성 신호 처리 및 버터워스 저역통과 필터 설계

디지털 필터의 기초 개념 및 분류

디지털 필터는 이산 시간 신호를 입력으로 받아 특정 주파수 성분을 강조하거나 억제하는 시스템을 의미합니다. 크게 고전적 필터와 현대적 필터로 나눌 수 있으며, 임펄스 응답의 길이에 따라 유한 임펄스 응답(FIR) 필터와 무한 임펄스 응답(IIR) 필터로 분류됩니다. 또한 주파수 선택 특성에 따라 저역통과, 고역통과, 대역통과, 대역저지 필터 등으로 구분됩니다.

아날로그 필터 설계와 버터워스 필터

디지털 IIR 필터를 설계할 때는 일반적으로 아날로그 필터 프로토타입을 설계한 후, 이를 디지털 영역으로 변환하는 방식을 사용합니다. 대표적인 아날로그 필터로는 버터워스(Butterworth), 체비셰프(Chebyshev), 타원(Elliptic) 필터 등이 있습니다. 이 중 버터워스 필터는 통과 대역에서 최대 평탄(Maximally Flat) 특성을 가지며, 위상 왜곡이 상대적으로 적어 음성 신호 처리와 같은 분야에서 널리 활용됩니다.

MATLAB을 활용한 음성 신호 스펙트럼 분석

음성 신호의 주파수 특성을 분석하기 위해 고속 푸리에 변환(FFT)을 수행합니다. 다음 코드는 오디오 파일을 로드하고 시간 영역 및 주파수 영역에서 신호를 시각화하는 과정을 보여줍니다.

% Initialize environment
clearvars;
clc;
close all;

% Load audio file
[audioSig, fs] = audioread('sample_audio.wav');
sigLength = length(audioSig);

% Play original audio
sound(audioSig, fs);

% Perform FFT
nPoints = sigLength;
fftResult = fft(audioSig, nPoints);

% Frequency axis generation
freqAxis = fs * (0:nPoints-1) / nPoints;

% Plotting
figure('Name', 'Original Audio Spectrum');
subplot(2,1,1);
plot(1:20000, abs(fftResult(1:20000)));
title('FFT Magnitude (Digital Frequency Index)');

subplot(2,1,2);
plot(freqAxis(1:20000), abs(fftResult(1:20000)));
title('Frequency Spectrum (Hz)');
xlabel('Frequency (Hz)');
ylabel('Magnitude');

고주파 노이즈 추가 및 신호 변형

필터의 성능을 검증하기 위해 원본 음성 신호에 고주파 노이즈를 인위적으로 첨가합니다. 아래 예제에서는 8kHz의 코사인 파형을 노이즈로 생성하여 원본 신호에 중첩합니다.

% Time vector for noise generation
timeVec = (0:sigLength-1) / fs;

% Generate high-frequency cosine noise (8 kHz)
noiseAmplitude = 0.03;
noiseFreq = 8000;
noiseSignal = noiseAmplitude * cos(2 * pi * noiseFreq * timeVec);

% Add noise to original signal
noisyAudio = audioSig + noiseSignal';

% Play noisy audio
sound(noisyAudio, fs);

% Plot time domain signals
figure('Name', 'Time Domain Comparison');
subplot(2,1,1);
plot(audioSig);
title('Original Audio Signal');
xlabel('Sample Index'); ylabel('Amplitude');

subplot(2,1,2);
plot(noisyAudio);
title('Noisy Audio Signal');
xlabel('Sample Index'); ylabel('Amplitude');

% FFT of noisy signal
noisyFFT = fft(noisyAudio, nPoints);
figure('Name', 'Noisy Audio Spectrum');
plot(freqAxis(1:20000), abs(noisyFFT(1:20000)));
title('Frequency Spectrum of Noisy Signal');
xlabel('Frequency (Hz)'); ylabel('Magnitude');

버터워스 저역통과 필터 설계

첨가된 고주파 노이즈를 제거하기 위해 버터워스 저역통과 필터를 설계합니다. 통과 대역과 저지 대역의 경계 주파수, 그리고 허용 리플과 감쇠량을 설정하여 최적의 필터 차수와 차단 주파수를 계산합니다.

% Filter specifications
passbandEdge = 4000; % Hz
stopbandEdge = 5000; % Hz
passbandRipple = 1;  % dB
stopbandAtten = 15;  % dB

% Calculate minimum filter order and cutoff frequency
[optOrder, wn] = buttord(passbandEdge/(fs/2), stopbandEdge/(fs/2), passbandRipple, stopbandAtten);

% Design Butterworth filter directly in digital domain
[numCoeffs, denCoeffs] = butter(optOrder, wn, 'low');

% Compute frequency response
[hResp, wResp] = freqz(numCoeffs, denCoeffs, 512, fs);

% Plot frequency response
figure('Name', 'Butterworth Filter Response');
plot(wResp, abs(hResp));
grid on;
title('Butterworth Low-Pass Filter Frequency Response');
xlabel('Frequency (Hz)');
ylabel('Magnitude');

필터링 적용 및 결과 검증

설계된 필터 계수를 사용하여 노이즈가 포함된 신호에 필터링을 적용합니다. 필터링 전후의 시간 영역 파형과 주파수 스펙트럼을 비교하여 고주파 노이즈가 효과적으로 제거되었는지 확인합니다.

% Apply the designed filter to the noisy signal
filteredAudio = filter(numCoeffs, denCoeffs, noisyAudio);

% Play filtered audio
sound(filteredAudio, fs);

% Plot time domain comparison
figure('Name', 'Filtering Result in Time Domain');
subplot(2,1,1);
plot(timeVec, noisyAudio);
title('Noisy Signal (Time Domain)');

subplot(2,1,2);
plot(timeVec, filteredAudio);
title('Filtered Signal (Time Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

% Frequency domain comparison
filteredFFT = fft(filteredAudio, nPoints);
figure('Name', 'Spectrum Comparison');
subplot(2,1,1);
plot(freqAxis(1:20000), abs(noisyFFT(1:20000)));
title('Spectrum Before Filtering');
xlabel('Frequency (Hz)'); ylabel('Magnitude');

subplot(2,1,2);
plot(freqAxis(1:20000), abs(filteredFFT(1:20000)));
title('Spectrum After Filtering');
xlabel('Frequency (Hz)'); ylabel('Magnitude');

태그: Matlab DigitalSignalProcessing ButterworthFilter LowPassFilter FFT

6월 20일 17:12에 게시됨