레이블이 Matlab인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Matlab인 게시물을 표시합니다. 모든 게시물 표시

2017년 12월 31일 일요일

Levinson-Durbin recursion

Matlab

levinson : Levinson-Durbin recursion

Syntax
a = levinson(r)
a = levinson(r, n)
[a, e] = levinson(r, n)
[a, e, k] = levinson(r, n)

Description
The Levinson-Durbin recursion is an algorithm for finding an all-pole IIR filter with a prescribed deterministic autocorrelation sequence. It has applications in filter design, coding, and spectral estimation. The filter that levinson produces is minimum phase.

a = levinson(r) finds the coefficients of a length(r)-1 order autoregressive linear process which has r as its autocorrelation sequence. r is a real or complex deterministic autocorrelation sequence. If r is a matrix, levinson finds the coefficients for each column of r and returns them in the rows of a. n=length(r)-1 is the default order of the denominator polynomial A(z); that is, a = [1 a(2) ... a(n+1)]. The filter coefficients are ordered in descending powers of z–1.

H(z) = 1/A(z)
A(z) = 1 + a(2)z^(−1) + ⋯ + a(n+1)z^(−n)

a = levinson(r,n) returns the coefficients for an autoregressive model of order n.
[a,e] = levinson(r,n) returns the prediction error, e, of order n.
[a,e,k] = levinson(r,n) returns the reflection coefficients k as a column vector of length n.

Example
>> data = [2, 2, 0, 0, -1, -1, 0, 0, 1, 1];
>> [r, lg] = xcorr(data, 'biased');
>> r(lg<0) = []
r =
1.2000  0.6000  0.0000  -0.3000  -0.6000  -0.3000  -0.0000  0.2000  0.4000  0.2000
>> [ar, e] = levinson(r, 3)
ar =
1.0000   -0.6250    0.2500    0.1250
e =
0.7875

출처 : <https://kr.mathworks.com/help/signal/ref/levinson.html>

Python

lazy_lpc Module : Linear Predictive Coding (LPC) module

github for AudioLazy : <https://github.com/danilobellini/audiolazy>
AudioLazy 0.6 Docs : <http://pythonhosted.org/audiolazy/index.html>

Module contents
ParCorError Error when trying to find the partial correlation coefficients (reflection
coefficients) and there’s no way to find them.
toeplitz Find the toeplitz matrix as a list of lists given its first line/column.
levinson_durbin Solve the Yule-Walker linear system of equations.
lpc This is a StrategyDict instance object called lpc. Strategies stored: 5.
parcor Find the partial correlation coefficients (PARCOR), or reflection
coefficients, relative to the lattice implementation of a given LTI FIR
LinearFilter with a constant denominator (i.e., LPC analysis filter, or
any filter without feedback).
parcor_stable Tests whether the given filter is stable or not by using the partial
correlation coefficients (reflection coefficients) of the given filter.
Find the Line Spectral Frequencies (LSF) from a given FIR filter.
lsf_stable Tests whether the given filter is stable or not by using the Line
Spectral Frequencies (LSF) of the given filter. Needs NumPy.

levinson_durbin(acdata, order=None)
acdata – Autocorrelation lag list, commonly the acorr function output.
order – The order of the resulting ZFilter object. Defaults to len(acdata) - 1.

Example
>>> data = [2, 2, 0, 0, -1, -1, 0, 0, 1, 1]
>>> acdata = acorr(data)
>>> acdata
[12, 6, 0, -3, -6, -3, 0, 2, 4, 2]
>>> ldfilt = levinson_durbin(acorr(data), 3)
>>> ldfilt
1 - 0.625 * z^-1 + 0.25 * z^-2 + 0.125 * z^-3
    >>> ldfilt.numerator
[1, - 0.625, 0.25, 0.125]
>>> ldfilt.error  # Squared! See lpc for more information about this
7.875


출처 : <http://pythonhosted.org/audiolazy/lazy_lpc.html#audiolazy.lazy_lpc.levinson_durbin>

2017년 11월 28일 화요일

감마톤 필터

A gammatone filter is a linear filter described by an impulse response that is the product of a gamma distributionand sinusoidal tone. It is a widely used model of auditory filters in the auditory system.


출처: <https://en.wikipedia.org/wiki/Gammatone_filter>

감마톤 필터 대역폭은 1.01일 때와 필터 차수 4일 때 청각 특성을 가장 잘 반영한다.(한국음향학회 논문). 아래 매트랩 툴박스의 감마톤 필터의 필터 차수는 4로, 대역폭은 1.019로 설정되어있다. (gammatoneFast.m파일 참고)

Matlab Toolbox - need to install

bm = gammatoneFast(x,cfs,fs) 
bm = gammatoneFast(...,align) 
[bm,env] = gammatoneFast(...) 
[bm,env,delay] = gammatoneFast(...)
NOTE: this function is now available from the IoSR Matlab Toolbox as iosr.auditory.gammatoneFast. 

<Example>
fs = 48000; % sample rate 
numchans = 8; % number of frequency channels 
t = -0.005:1/fs:0.025; % time (s)
% impulse 
imp = zeros(numel(t), 1); 
imp(t==0) = 1;
% centre frequencies 
cfs = iosr.auditory.makeErbCFs(500, 7500, numchans);
% calculate impulse response fine structure 
x1 = iosr.auditory.gammatoneFast(imp, cfs, fs); 
x2 = iosr.auditory.gammatoneFast(imp, cfs, fs, true);
% normalise each frequency for plotting 
for c = 1:numchans 
x1(:, c) = x1(:, c) ./ max(abs(x1(:, c))); 
x2(:, c) = x2(:, c) ./ max(abs(x2(:, c))); 
end
% draw 
figure 
% non-phase aligned 
subplot(1, 2, 1), iosr.figures.multiwaveplot(t*1000, 1:numchans, x1') 
h = gca; 
% phase aligned 
subplot(1, 2, 2), iosr.figures.multiwaveplot(t*1000, 1:numchans, x2') 
h(2) = gca; 
% plot settings 
set(h, 'yticklabel', num2str(round(cfs)')) 
for n = 1:2 
xlabel(h(n), 'Time [ms]'); 
ylabel(h(n), 'Frequency [Hz]'); 
end 
title(h(1), 'Non-phase-aligned gammatone filterbank') 
title(h(2), 'Phase-aligned gammatone filterbank')


출처: <https://kr.mathworks.com/matlabcentral/fileexchange/32212-gammatone-filterbank>

왜도(비대칭도)

확률 이론 및 통계학에서, 비대칭도(非對稱度, skewness) 또는 왜도(歪度)는 실수 값 확률 변수의 확률 분포 비대칭성을 나타내는 지표이다. 왜도의 값은 양수나 음수가 될 수 있으며 정의되지 않을 수도 있다. 왜도가 음수일 경우에는 확률밀도함수의 왼쪽 부분에 긴 꼬리를 가지며 중앙값을 포함한 자료가 오른쪽에 더 많이 분포해 있다. 왜도가 양수일 때는 확률밀도함수의 오른쪽 부분에 긴 꼬리를 가지며 자료가 왼쪽에 더 많이 분포해 있다는 것을 나타낸다. 평균과 중앙값이 같으면 왜도는 0이 된다.


출처: <https://ko.wikipedia.org/wiki/%EB%B9%84%EB%8C%80%EC%B9%AD%EB%8F%84>

Matlab document


출처: <https://kr.mathworks.com/help/releases/R2017a/stats/skewness.html> 

첨도

첨도(尖度, 영어: kurtosis 커토시스)는 확률분포의 뾰족한 정도를 나타내는 척도이다. 관측치들이 어느 정도 집중적으로 중심에 몰려 있는가를 측정할 때 사용된다. 첨도값(K)이 3에 가까우면 산포도가 정규분포에 가깝다. 3보다 작을 경우에는(K<3) 정규분포보다 더 완만하게 납작한 분포로 판단할 수 있으며, 첨도값이 3보다 큰 양수이면(K>3) 산포는 정규분포보다 더 뾰족한 분포로 생각할 수 있다.


출처: <https://ko.wikipedia.org/wiki/%EC%B2%A8%EB%8F%84>

Matlab document

출처: <https://www.mathworks.com/help/releases/R2017a/stats/kurtosis.html?doclanguage=ko-KR&nocookie=true&prodfilter=BI+CO+MJ+CT+CF+DA+DM+DS+EL+FL+GD+IP+IA+IC+MG+ML+ME+NN+OP+SG+SS+MS+SL+SD+SF+ST+SM+VP&addons=arduinoio&docviewer=helpbrowser&docrelease=R2017a&s_cid=pl_webdoc>


홈

람다 표현식 (Lambda expression)

람다 표현식(Lambda expression)  람다 표현식으로 함수를 정의하고, 이를 변수에 할당하여 변수를 함수처럼 사용한다. (1) 람다 표현식       lambda <매개변수> : 수식      ※ 람다식을 실행하...