Using FFT analysis/synthesis/filtering

Download Report

Transcript Using FFT analysis/synthesis/filtering

Using FFT
analysis/synthesis/filtering
9th of October
Today’s issues
• Basic signal theory
• Frequency-domain signal analysis
– Using Discrete Fourier Transformation (DFT)
• Analysis and Synthesis
– Using overlap and add method
• Introducing DSPLIB
– Implementation of FFT and other DSP algorithms
• Building Frequency domain Digital filter
– Using DSPLIB
주기 신호의 표현
• 주기 신호 (Periodic signal)
– 일정한 시간 간격으로 똑같은 모양의 신호가 반복 (1/
주기 = 기본주파수)
• 100Hz sinewave
– 사인(sine) 모양의 파형이 초당 100번 반복
• 200Hz 구형파
– 계단 모양의 파형이 1/200초 간격만큼 동일하게 반복
• 퓨리어 급수 이론
– For any periodic function
• Composed of its harmonic sinusoidals
• Fundamental frequency = 1/T
푸리어 급수
T
F0=1/T
2F0
3F0
4F0
주기 신호의 스펙트럼
T
• 기본주파수(=1/주기)
의 정수배 되는 위치에
서만 존재
T(sec)
– 선스펙트럼
(line spectrum)
– 또는 불연속스펙트럼
(discrete spectrum)
F0 = 1/T
F (Hz)
0
F0 2F0 3F0 4F0 5F0
비주기 신호의 스펙트럼
• 비주기 신호

T
– 주기가 무한대( )
– 기본주파수는 1/주기
에서 “0” 으로 수렴
– 스펙트럼은 연속스펙
트럼 (continuous
spectrum) 형태를 갖음.
T(sec)
F (Hz)
“0”
Time domain signal의 구분
• 결정 신호 (Deterministic signal)
– 수학적으로 정의될 수 있는 신호
• Sinewave : Amplitude/Phase/Frequency에 의해 완벽하게 정
의될 수 있다.
• Impulse train : 펄스의 간격, 펄스의 크기에 의해 완벽하게 정
의됨.
• 랜덤 신호 (Stochastic or Random signal)
– 수학적으로 정의 할 수 없지만 모델링 가능한 신호
• 백색 가우시안 잡음 : 분산/평균으로 정의됨.
Stochastic signal의 예
분산
평균
Time-to-Frequency mapping
Well-known T-to-F mapping
• Fourier Series
– 주기 신호에 대한 시간주파수 변환
• Fourier Transform
– 주기/비주기 신호에 대
한 시간-주파수 변환
Joseph Fourier (1768~1830, France)
Another T-to-F mapping
• Laplace transformation
– FT보다 더 일반화된 형태
– 신호의 감소율도 고려
Pierre-Simon Laplace
(1749~1827, France)
Fourier transform; Review
Fourier series -> 주기신호에 대해
f (t ) 

 dne
n  
jnt
,
1
dn 
TP
TP / 2

TP / 2
f (t )e  jnt dt
Fourier transform -> 비주기신호에 대해
d n  d ( ) as TP  
d 
 j t
d ( ) 
f
(
t
)
e
dt



2

d ( )
 F ( j )   f (t )e  jt dt

d / 2
Discrete Fourier Transform (DFT)
• 퓨리어 변환은 무한대의 길이를 갖는 신호에 대해
정의된다.
• 실제적인 이산 신호는 신호의 길이가 제한되어 있
다. -> 퓨리어 변환이 불가능?
• 따라서, 제한된 길이의 신호를 무한대의 길이를
갖는 신호로 변환해야 된다.
• 제한된 길이의 신호가 반복적으로 나타난다고 가
정하여 퓨리어 변환
– 이산 퓨리어 변환은 퓨리어 시리즈와 같은 의미
DFT; Time & Frequency domain
Spectrum analysis;
practical issue
a

무한 길이에 대한 DFT
Frame N-1 Frame N
DFT
DFT
Ping/Pong buffer에서 windowing
Ping buffer
Pong buffer
첫번째 프레임
두번째 프레임
세번째 프레임
네번째 프레임
이전 buffer의 일부
데이터를 저장
첫번째 프레임은 이전
buffer의 마지막 데이터
들을 꺼내온다.
Windowing effect
(=Gibbs effect)
DFT
Window 함수와 주파수 응답
Short-time FT analysis and
synthesis
Frame N-1 Frame N
Input signal
DFT
processing
DFT
Output signal
IDFT
processing
IDFT
Short-time signal 로 부터 continuous
signal을 합성하는 방법
Short-time signal 1
Short-time signal 2
•실질적으로 window 함수가 두 번 곱해졌으므로 window의
제곱값으로 overlap 된 값으로 나누어 준다.
Over-Lap and Add Source code
void
OverLapAdd(Int16 *out, float *st_da,
Int16 *pre_da, float *pre_win, float *win, float *swin)
{
int i;
Int16 temp_val;
프레임이동 만큼 데이터
출력 = overlap & add 사용
for(i=0; i<FRAME_LEN; i++) {
if ( i<FRAME_SHIFT ) {
temp_val=(pre_da[i]+st_da[i*2]*win[i])/(pre_win[i]+swin[i]);
out[i]=(temp_val>MAX_INT16)?MAX_INT16:temp_val;
}
나머지 부분은 과거 데이
else {
터 저장용 버퍼에 overlap
pre_da[i-FR_RATE]=pre_da[i]+fftb[i*2]*win[i];
& add 를 수행하여 저장함.
pre_win[i-FR_RATE]=pre_win[i]+swin[i];
}
Window함수에 대해서도
}
똑같이 overlap & add 수행
}
DSPLIB
• An optimized floating-point DSP Function Library
– for C programmers using TI DSPs.
• Includes general-purpose signal-processing routines
– C-callable, assembly-optimized
– typically used in computationally intensive real-time applications
where optimal execution speed is critical.
• Execution speeds considerably faster than equivalent
code written in standard ANSI C language.
• Providing ready-to-use DSP functions
DSPLIB에서 제공되는 함수
Adaptive
Filtering
Correlation
FFT
Filtering and convolution
Math
Matrix
Misc
DSPF_sp_lms
DSPF_sp_autoco
r
DSPF_sp_bitrev_cplx
DSPF_sp_fir_cplx
DSPF_sp_dotp_sqr
DSPF_sp_mat_mul
DSPF_sp_blk_move
DSPF_dp_lms
DSPF_dp_autoco
r
DSPF_sp_cfftr4_dif
DSPF_sp_fir_gen
DSPF_sp_dotprod
DSPF_sp_mat_trans
DSPF_sp_blk_eswap16
DSPF_sp_cfftr2_dit
DSPF_sp_fir_r2
DSPF_sp_dotp_cplx
DSPF_sp_mat_mul_cplx
DSPF_sp_blk_eswap32
DSPF_sp_fftSPxSP
DSPF_sp_fircirc
DSPF_sp_maxval
DSPF_dp_mat_mul
DSPF_sp_blk_eswap64
DSPF_sp_ifftSPxSP
DSPF_sp_biquad
DSPF_sp_maxidx
DSPF_dp_mat_trans
DSPF_sp_fltoq15
DSPF_sp_icfftr2_dif
DSPF_sp_iir
DSPF_sp_minval
DSPF_dp_mat_mul_cpl
x
DSPF_sp_q15tofl
DSPF_dp_bitrev_cpl
x
DSPF_sp_iirlat
DSPF_sp_vecrecip
DSPF_sp_minerror
DSPF_dp_cfftr4_dif
DSPF_sp_convol
DSPF_sp_vecsum_sq
DSPF_dp_blk_move
DSPF_dp_cfftr2
DSPF_dp_cfftr4_dif
DSPF_sp_w_vec
DSPF_dp_icfftr2
DSPF_dp_cfftr2
DSPF_sp_vecmul
DSPF_dp_fir_cplx
DSPF_dp_dotp_sqr
DSPF_dp_fir_gen
DSPF_dp_dotprod
DSPF_dp_fir_r2
DSPF_dp_dotp_cplx
DSPF_dp_fircirc
DSPF_dp_maxval
DSPF_dp_biquad
DSPF_dp_maxidx
DSPF_dp_iir
DSPF_dp_minval
DSPF_dp_iirlat
DSPF_dp_vecrecip
DSPF_dp_convol
DSPF_dp_vecsum_s
q
DSPF_dp_w_vec
DSPF_dp_vecmul
How to get/update DSPLIB?
DSPLIB에 포함된 내용
• C6700을 위한 각종 파일
– \CCStudio\c6700\dsplib\bin
• FFT 연산을 수행하기 위한 각종 파라메터 생성 프로그램
– \CCStudio\c6700\dsplib\include
• 함수에 대한 헤더 파일
– \CCStudio\c6700\dsplib\lib
• 라이브러리 파일 (소스 코드 포함)
– \CCStudio\c6700\dsplib\support
• FFT 연산을 위한 각종 보조 함수들
• 각 함수에 대한 사용 설명
– \CCStudio\docs\pdf\SPRU657B.pdf
DSPLIB을 사용하기 위한 준비(1)
• 라이브러리 소스의 컴파일
– Download시 이미 67X 계열의 DSP로 compile이 된
library 라면 컴파일 불필요
– 만일 그대로 사용시 building error 가 발생하는 경우
• 다른 계열 (특히 62X 계열) 의 DSP로 compile된 경우임.
– mk6x –mv6710 dsp67x.src –l dsp67x.lib
• mk6x : library build tool
• -mv6710 : 6710 DSP 용으로 컴파일
• dsp67x.src : \CCStudio\c6700\dsplib\lib 에 포함된 library
source code
• dsp67x.lib : 출력될 binary library file
DSPLIB을 사용하기 위한 준비(2)
DSPLIB용 header
file이 저장된
directory 지정
DSPLIB을 사용하기 위한 준비(3)
DSPLIB용 library
file이 저장된
directory 지정
FFT 관련 함수의 사용법(1)
• DSPF_sp_cfftr2_dit
– Single-precision floating point radix-2 FFT for complex input
– Void DSPF_sp_cfftr2_dit(float *x, float *w, short n)
• x : pointer to complex data input
• w : pointer to complex twiddle factor in bit-reverse order
• n : length of FFT in complex samples
– Must be power of 2 such that 32<=n<=32K
FFT 를 위한 complex array 구조
Imag[x(0)]
Imag[x(1)]
Real[x(0)] Real[x(1)]
Imag[x(N-1)]
Real[x(N-1)]
FFT 관련 함수의 사용법(2)
FFT 수행시 필요
한 twiddle factor
를 계산, look up
table에 저장
FFT 수행시 필요
한 비트역순 인덱
스 테이블 생성
FFT loop-back 예제
실습1
• Build FFT loop-back program
–
–
–
–
Windowing->FFT->IFFT->OverLapAdd
FFT_SIZE : 512 또는 256
Stereo data -> Mono data 로 변환 (optional)
DIP switch에 의해 FFT/IFFT 결과 또는 original data를
선택
• CCS의 insert graphic 기능 이용, FFT 결과의 plot
Overlap and Add 방법의 원리
Void OverLapAdd(short *out, float *fftb, short *pre_da)
{
int i;
for(i=0; i<FR_LEN; i++) {
if ( i<FR_RATE )
out[i]=pre_da[i]+fftb[i*2];
else
pre_da[i-FR_RATE]=pre_da[i]+fftb[i*2];
}
}
Fast Fourier Transform
N 1
X (m)   x(n) exp[
n 0
1
x ( n) 
N
N 1
j 2nm
] , 0  m  N  1 : Forward DFT
N
 X (m) exp[
m 0
j 2nm
] , 0  m  N  1 : InverseFFT
N
•High computational complexities -> too many addition and multiplication
 N 2 (e.g.N  1024pointDFT  106 Mul/Add)
•Fast DFT algorithm (by Turkey &
Cooley)
 N log N (e.g.N  1024pointFFT  104 Mul/Add)
•Size must be power of 2
•Results are bit-reverse ordered
Bit-reversal order의 확인
Frequency domain Digital Filter 구
현
N=16 pt
FFT 결과
X(0)=DC
Complex conjugate
X(n)=X*(N/2-n)
Filtering 후
FT계수가 항
상 대칭이 되
도록 한다.
Frequency response (LPF)
FFT 결과와 절대주파수값간의
계
N=16 pt
FFT 결과
X(0)=0Hz (DC)
?
X(FFT_SIZE/2)=Fs/2
N-번째 FFT 계수는 몇 Hz에 해당?
-> 비례식을 이용
Fs
FFT _SIZE
: x
:n
2
2
Fs
x
n (Hz)
FFT _SIZE
FFT _SIZE
n
x
Fs
관
An Example of Frequency index
function
// Compute Frequency index for a given (real) frequency (in Hz)
// fid = f_real *(FFT_SIZE/Fs)
// Where Fs = Sampling frequency
// Note : 0 <= f_real <= Fs/2
int
{
Get_Freq_id(int Freal, int Fs)
return Freal*((float)FFT_SIZE/Fs);
}
void
{
LPF(float *fftb)
int
i, fidL, fidH;
fidL=Get_Freq_id(500, 32000);
fidH=Get_Freq_id(5000, 32000);
// -> should be matched with AIC Fs setting..
for(i=0; i<FFT_SIZE_2; i++) {
if ( !(fidL <= i && i <= fidH) )
fftb[i*2]=fftb[i*2+1]=0.;
}
for(i=1; i<FFT_SIZE_2; i++) {
fftb[(i+FFT_SIZE_2)*2]=fftb[(FFT_SIZE_2-i)*2];
fftb[(i+FFT_SIZE_2)*2+1]=-fftb[(FFT_SIZE_2-i)*2+1];
}
}
Frequency-domain digital filter; flow
chart
Windowing
FFT
두 신호간 시간
영역에서 비교
Bit-reversing
Taking lower frequency components
Bit-reversing
IFFT
이전 time-domain digital filter의 결과 와 비교
두 신호간 주파수
영역에서 비교
실습2
• Build frequency-domain digital filter
– Using FFT/IFFT
– Yesterday (time-domain digital filter) 와 비교
– Filtering 전/후 스펙트럼 비교
• Using insert graphic function
– 다양한 형태의 필터 구현
• LPF, HPF, BPF 등