c語言的譜減法實現(xiàn)(Implementation of spectral subtraction in C)_第1頁
c語言的譜減法實現(xiàn)(Implementation of spectral subtraction in C)_第2頁
c語言的譜減法實現(xiàn)(Implementation of spectral subtraction in C)_第3頁
c語言的譜減法實現(xiàn)(Implementation of spectral subtraction in C)_第4頁
c語言的譜減法實現(xiàn)(Implementation of spectral subtraction in C)_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、c語言的譜減法實現(xiàn)(Implementation of spectral subtraction in C)The realization of.Txt18 spectral subtraction with honest C language, abandon the false; with honesty, to abandon the boring; with ease to abandon the impetuous, whether intentionally discarded, or accidental loss, as long as ever have, in some c

2、ases, generous abandon is also a kind of realm. C language to achieve spectral subtraction.Txt12 missing is a poem to let you in ordinary days to read out the rhythm; missing is a shower, let you dry up the moist days; missing is a sun, so that your days of gloomy clear up. #include #include #includ

3、e #define WL 256 / / window length#define P 10 / / prediction coefficient#undef pi#define PI 3.1415926535897932384626434#define PI 3.1415926#define winsize 256#define tempsize winsize/2#define buffsize winsize*10Typedef structDouble real;Double img;complex;Unsigned int f=0;Unsigned int c=0;Complex n

4、oisewinsize;Double buff_rbuffsize;Double buff_wbuffsize;Double temptempsize;Complex xwinsize;Complex ywinsize;Int hr=0;Complex Wwinsize;Complex W1winsize;Double x_abswinsize;Double y_abswinsize;Double noise_abswinsize;Void FFT (complex *x, int size_x, complex *W); / * * / fast Fourier transformVoid

5、IFFT (complex, *x, int, size_x, complex, *W1);Double angle (complex a); / /Void add (complex, complex, complex *); / * * / complex additionVoid mul (complex, complex, complex *); / * * / complex multiplicationVoid sub (complex, complex, complex *); / * * / plural subtractionVoid change (complex *x,

6、int size_x); / * * / array transposeDouble abs1 (complex a);Void Hamming (complex hw);/*int ReadWaveFile (char, *fn, int, *fs, short, *dat);Int ReadWaveFile (.Char *fn / / I: file nameInt *fs / / O: file sizeShort *dat / / O: voice data)FILE *fp;Int dsize;If (FP = fopen (FN, rb+) = = NULL) Fprintf (

7、stderr,%s:, No, file, n, such, FN); return (-1);Fseek (FP, 0L, SEEK_END);Dsize = fTell (FP) /2;Fseek (FP, 0L, SEEK_SET);(if (*dat = (short * malloc) (sizeof (short) *dsize) = = NULL) Fprintf (stderr, Memory, n, Error); return (-1);If (FREAD (*dat, sizeof (short), dsize, FP) = = (unsigned, int) dsize

8、) Free (*dat);Return (-1);Fclose (FP);*fs = dsize;Return (0);*/Void Hamming (complex hw)Double x;Int i;For (i=0; iWL; i+)Double cos (x);X=2*pi*i/ (WL-1);Hwi.real=hwi.real* (0.54-0.46*cos (x); /*32768;Void, FFT (complex, *x, int, size_x, complex, *W) Int, i=0, j=0, k=0, l=0, jk=0;Complex, up, down, p

9、roduct;Change (x, size_x);For (i=0; ilog (size_x) /log (2); i+) / * a butterfly.L=1i;For (j=0; jsize_x j+=; 2*l) / * * / a group of butterfly operationFor (k=0; kl; k+) / * * / a butterflyJk=j+k;Mul (xjk+l, Wsize_x*k/2/l, &product);Up.real=xjk.real+product.real;Up.img=xjk.img+product.img;Down.real=x

10、jk.real-product.real;Down.img=xjk.img-product.img;Xjk=up;Xjk+l=down;* index calculation, X (n) code bit inversion.Void change (complex, *x, int, size_x) Complex temp;無符號短i0,j0,k0;雙T;為(i = 0;i 0)J1;J | =(K 1);kk 1;如果(j i)溫度 x ;我;x =溫度;無效的IFFT(復雜* x,int size_x,復雜* W1)int i0,j0,k0,l0,JK0;復雜的上、下、產(chǎn)品;改變(x

11、,size_x);為(i = 0;i 日志(size_x)/日志(2);i+)/ * * /一級蝶形運算l = 1 我;為(J = 0;J size_x;J = 2 * L)/ * * /一組蝶形運算為(k = 0;KL;K +) /*一個蝶形運算*/JK = k;穆爾(x JK + L,W1 size_x * K2L ,及產(chǎn)品);起來。房= x 克房+ product.real;了。IMG = x 克。IMG + product.img;下來。房= x 克。real-product.real;下來。img = x 克。img-product.img;x = JK;x;為(i = 0;i 房=

12、 A. + b.real;C - img = a.img + b.img;無效的多(復雜的,復雜的,復雜的* C)C -房= A. * b.real - a.img * b.img;C - img = A. * b.img + a.img * b.real;空子(復數(shù)A,復數(shù)b,復數(shù)*)C -房= a.real-b.real;C - img = a.img-b.img;雙ABS1(復雜的)雙T;T =(A.)*(A.)+(a.img)*(a.img);返回(雙)sqrt(T);/ *主程序* /空主(空)雙吉他WavOut 7680 , 7680 ;復數(shù)S 60 256 ,語音 256 ;復雜

13、噪聲1 256 ;雙noise_foward15frame 15 256 ;雙am_noise 256 ;int = 8000;雙筆 15 256 ,voice_timedomain 60 256 ;雙相 256 ;雙am_signal 256 ;雙am_voice 256 ;國際frame_len = 256,step_len = 128,n_frame = 15,wav_length = 7680,I,J,size_x = 256,nifrm,ifrm;int = 0,n1;為(i = 0;i wav_length;i+)那我 =我;開關(guān)(fs)案例8000:frame_len = 256

14、;step_len = 128;突破;案例10000:frame_len = 400;step_len = 200;突破;案例12000:frame_len = 480;step_len = 240;突破;案例16000:frame_len = 640;step_len = 320;突破;案例44100:frame_len = 1800;step_len = 900;突破;違約:frame_len = 1800;step_len = 900;突破;n_frame =(wav_length-frame_len)/ step_len + 1;為(i = 0;i n_frame;i+)/分幀整數(shù)n,

15、n2;N1 =我step_len;N2 =我step_len + frame_len;對于(j = N1;jn2;j + +)我的 j-n1 。房=飄揚J.;我的 j-n1 。img = 0;為(i = 0;i winSize;i+)/初始化W數(shù)組W 我。房= cos(2/ size_x *我);W 我。img = 1 *罪(2PI / size_x *我);為(i = 0;i winSize;i+)/初始化W數(shù)組W1 我。房= cos(2/ size_x *我);W1 我。img = sin(2/ size_x *我);It is (nifrm = 0; nifrm 15; nifrm +

16、+)Hamming (s nifrm);For (I = 0; I frame _ len; I + +)Noise1 i.Real = s nifrm i.Real;Noise1 i img = 0.0;FFT (noise1256, w);For (I = 0; I frame _ len; I + +)Noise _ foward15frame nifrm i = abs1 (noise1 i); / / noise _ foward15frame保存前15幀的噪音短時傅立葉變換幅度結(jié)果For (J = 0, J frame _ len; j + +)Double w = 0.0;For

17、 (I = 0; I 15; I + +)W = w + noise _ foward15frame i J.Am _ noise J = w / 15;It is (ifrm = 0; ifrm n _ frame; ifrm + +)Hamming (s ifrm);For (I = 0; I frame _ len; I + +)Sum ifrm i = s ifrm i.Real; / / sum _ timedomain保存整個語音信號的時域和的結(jié)果FFT (s ifrm, 256, w); / / 快速傅里葉變換參數(shù)For (I = 0; I frame _ len; I + +)

18、Phase angle (s i = ifrm i); / / 保存這幀語音信號的傅立葉變換的結(jié)果的相位For (I = 0; I frame _ len; I + +)Am _ signal i = abs1 (s ifrm i); / / 保存這幀語音信號的傅立葉變換的結(jié)果的幅度For (I = 0; I frame _ len; I + +)Am _ voice i = am _ signal i; / / - am _ noise i; / / 譜減% 用信號的幅度減去噪聲的幅度得到純凈語音的幅度For (I = 0; I frame _ len; I + +)If (am _ voice i 0)Am _ voice i = 0.0;For (I = 0; I frame _ len; I + +)Voice i.Real = am _ voice i; / / 組合相位與幅度得到去噪后的

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論