(381877808) 102054282 5-listing-program

Please download to get full document.

View again

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
 8
 
  1. LISTING PROGRAM FILTER PENGHAPUS NOISE ADAPTIF FIR LMS DENGAN MEMANFAATKAN TMS320C613 //Filter PEnghapus Noise Adaptif FIR LMS //Struktur Filter FIR : x1_topi +=…
Related documents
Share
Transcript
  • 1. LISTING PROGRAM FILTER PENGHAPUS NOISE ADAPTIF FIR LMS DENGAN MEMANFAATKAN TMS320C613 //Filter PEnghapus Noise Adaptif FIR LMS //Struktur Filter FIR : x1_topi += w[n]*x[n] //Sinyal_error=output_sistem : sinyal_e(n) = sinyal_campur - x1_topi; //UPdate Koefisien Menggunakan Algoritma LMS : w[i]+=miu*sinyal_e(n)*x[n]; //miu bervariasi berdasarkan pendekatan rumus step size maks : 1/NPx //noise yang dipakai noise sinusoida 100 Hz dan noise Bor // //codec-DSK(TMS320C6713) #include "DSK6713_AIC23.h" // //sampling Uint32 fs=DSK6713_AIC23_FREQ_48KHZ; #include <stdio.h> // //panjang elemen filter #define N 30 // //definisi kanal kiri line input #define LEFT 0 // //definisi kanal kanan line output #define RIGHT 1 // //nilai bobot koefisien filter untuk panjang element N float w[N];// //input ke buffer untuk panjang elemen N pada filter FIR float delay[N]; // //output TMS320C6713 short output; //tipe output pilihan jenis keluaran short jenis_keluaran = 1; // //
  • 2. //deskripsi masukan 2kanal line input volatile union{unsigned int uint; short channel[2];}AIC23_data; // //ISR interrupt void c_int11() { short i; float yn=0, En=0,campur=0, noise=0; //masukan 32bit dari line input AIC23_data.uint = input_sample(); //definisi noise untuk masukan line kiri noise =(AIC23_data.channel[LEFT]); //definisi noise untuk masukan line kanan campur = (AIC23_data.channel[RIGHT]); //noise sebagai masukan buffer ke-0 untuk FIR delay[0] = noise; //FIR for (i = 0; i < N; i++) //keluaran filter FIR yn += (w[i] * delay[i]); //sinyal selisih suara campuran dengan noise keluaran filter FIR En = campur - yn; //update koefisien filter dan delay FIR for (i = N-1; i >= 0; i--) { //update koefisien(LMS algoritma) w[i] = w[i] + 0.0000000003*En*delay[i]; //update sample delay delay[i] = delay[i-1]; } //bila pilihan menu jenis keluaran dalam posisi 1 if(jenis_keluaran == 1)
  • 3. //jenis_keluaran = sinyal asli output=((short)campur); //bila pilihan menu jenis keluaran dalam posisi 2 else if(jenis_keluaran==2) //jenis_keluaran = sinyal noise output=((short)noise); //bila pilihan menu keluaran dalam posisi 3 else if(jenis_keluaran==3) //jenis keluaran = sinyal campuran output=((short)campur); //bila pilihan menu keluaran dalam posisi 4 else if(jenis_keluaran==4) //jenis keluaran=sinyal filter noise FIR output=((short)yn); //bila pilihan menu keluaran dalam posisi 5 else if(jenis_keluaran==5) //jenis_keluaran = sinyal selisih error output=((short)En); //bila pilihan menu keluaran dalam posisi 6 else if(jenis_keluaran==6) //jenis_keluaran=sinyal suara tanpa noise output=((short)En); output_sample(output); return; } void main() { short T=0; for (T = 0; T < 30; T++) { //inisialisasi buffer untuk bobot koefisien filter w[T] = 0; //inisialisasi buffer untuk sample delay delay[T] = 0; } comm_intr(); while(1); }
  • 4. LISTING PROGRAM TOMBOL PILIHAN OUTPUT (SLIDE GEL) /*pilihan jenis keluaran TMS320C6713*/ /*pilihan sebanyak 6 buah yaitu untuk keluaran sinyal asli, sinyal noise, sinyal noise hasil filtering, sinyal campur, sinyal e(n), sinyal output system*/ /*Nama menu adalah jenis keluaran*/ menuitem "jenis_keluaran" /*slide macam-macam keluaran*/ /*(nilai awal, nilai akhir, nilai kenaikan, nilai default, nama variable)*/ slider jenis_keluaran(1,6,1,1,keluaran){ /*slide keluaran sama dengan nilai variabel*/ jenis_keluaran = keluaran; }
  • 5. LISTING PROGRAM FILE SUPPORT “dsk6713.h” /* * Copyright 2002 by Spectrum Digital Incorporated. * All rights reserved. Property of Spectrum Digital Incorporated. */ /* * ======== dsk6713.h ======== * * This files contains DSK6713 board specific I/O registers * define for the CPLD. */ #ifndef DSK6713_ #define DSK6713_ #ifdef __cplusplus extern "C" { #endif #include <csl.h> /* * Note: Bit definitions for each register field * needs to be supplied here for the CPLD * and other board periperals. */ /* Compatability definitions */ #define NULL 0 /* CPLD address definitions */ #define DSK6713_CPLD_BASE 0x90080000 /* CPLD Register Indices */ #define DSK6713_USER_REG 0 #define DSK6713_DC_REG 1 #define DSK6713_VERSION 4
  • 6. #define DSK6713_MISC 6 /* CPLD Register Bits */ #define DC_DET 0x80 #define DC_STAT1 0x20 #define DC_STAT0 0x10 #define DC_CNTL1 0x02 #define DC_CNTL0 0x01 #define TIN1SEL 0x08 #define TIN0SEL 0x04 #define MCBSP2SEL 0x02 #define MCBSP1SEL 0x01 /* Initialize all board APIs */ void DSK6713_init (); /* Read an 8-bit value from a CPLD register */ Uint8 DSK6713_rget(Int16 regnum); /* Write an 8-bit value to a CPLD register */ void DSK6713_rset(Int16 regnum, Uint8 regval); /* Spin in a delay loop for delay iterations */ void DSK6713_wait(Uint32 delay); /* Spin in a delay loop for delay microseconds */ void DSK6713_waitusec(Uint32 delay); /* Get the DSK version */ Int16 DSK6713_getVers ion(); #ifdef __cplusplus } #endif #endif
  • 7. LISTING PROGRAM FILE SUPPORT “dsk6713_aic23.h” /* * Copyright 2002 by Spectrum Digital Incorporated. * All rights reserved. Property of Spectrum Digital Incorporated. */ /* * ======== dsk6713.h ======== * * This files contains DSK6713 board specific I/O registers * define for the CPLD. */ #ifndef DSK6713_ #define DSK6713_ #ifdef __cplusplus extern "C" { #endif #include <csl.h> /* * Note: Bit definitions for each register field * needs to be supplied here for the CPLD * and other board periperals. */ /* Compatability definitions */ #define NULL 0 /* CPLD address definitions */ #define DSK6713_CPLD_BASE 0x90080000 /* CPLD Register Indices */ #define DSK6713_USER_REG 0 #define DSK6713_DC_REG 1
  • 8. #define DSK6713_VERSION 4 #define DSK6713_MISC 6 /* CPLD Register Bits */ #define DC_DET 0x80 #define DC_STAT1 0x20 #define DC_STAT0 0x10 #define DC_CNTL1 0x02 #define DC_CNTL0 0x01 #define TIN1SEL 0x08 #define TIN0SEL 0x04 #define MCBSP2SEL 0x02 #define MCBSP1SEL 0x01 /* Initialize all board APIs */ void DSK6713_init (); /* Read an 8-bit value from a CPLD register */ Uint8 DSK6713_rget(Int16 regnum); /* Write an 8-bit value to a CPLD register */ void DSK6713_rset(Int16 regnum, Uint8 regval); /* Spin in a delay loop for delay iterations */ void DSK6713_wait(Uint32 delay); /* Spin in a delay loop for delay microseconds */ void DSK6713_waitusec(Uint32 delay); /* Get the DSK version */ Int16 DSK6713_getVers ion(); #ifdef __cplusplus } #endif #endif
  • 9. LISTING PROGRAM FILE SUPPORT “c6713init.c” //C6713dskinit.c Includes functions from TI in the C6713 CSL and C6713DSK BSL #include "C6713dskinit .h" #define using_bios //if BIOS don't use top of vector table extern Uint32 fs; //for sampling frequency void c6713_dsk_init() //dsp-peripheral initializat ion { DSK6713_init(); //call BSL to init DSK-EMIF,PLL) hAIC23_handle=DSK6713_AIC23_openCodec(0, &config);//handle(pointer) to codec DSK6713_AIC23_setFreq(hAIC23_handle, fs); //set sample rate MCBSP_config(DSK6713_AIC23_DATAHANDLE,&AIC23CfgData);// interface 32 bits toAIC23 MCBSP_start(DSK6713_AIC23_DATAHANDLE, MCBSP_XMIT_START | MCBSP_RCV_START | MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC, 220);//start data channel again } void comm_poll() //added for communication/init using polling { poll=1; //1 if using polling c6713_dsk_init(); //init DSP and codec } void comm_intr() //for communication/init using interrupt { poll=0; //0 since not polling IRQ_globalDisable(); //disable interrupts c6713_dsk_init(); //init DSP and codec
  • 10. CODECEventId=MCBSP_getXmtEventId(DSK6713_AIC23_codecdatahandle);//McB SP1 Xmit #ifndef using_bios //do not need to point to vector table IRQ_setVecs(vectors); //point to the IRQ vector table #endif //since interrupt vector handles this IRQ_map(CODECEventId, 11); //map McBSP1 Xmit to INT11 IRQ_reset(CODECEventId); //reset codec INT 11 IRQ_globalEnable(); //globally enable interrupts IRQ_nmiEnable(); //enable NMI interrupt IRQ_enable(CODECEventId); //enable CODEC eventXmit INT11 output_sample(0); //start McBSP interrupt outputting a sample } void output_sample(int out_data) //for out to Left and Right channels { short CHANNEL_data; AIC_data.uint=0; //clear data structure AIC_data.uint=out_data; //32-bit data -->data structure //The existing interface defaults to right channel. To default instead to the //left channel and use output_sample(short), left and right channels are swapped //In main source program use LEFT 0 and RIGHT 1 (opposite of what is used here) CHANNEL_data=AIC_data.channel[RIGHT]; //swap left and right channels AIC_data.channel[RIGHT]=AIC_data.channel[LEFT]; AIC_data.channel[LEFT]=CHANNEL_data; if (poll) while(!MCBSP_xrdy(DSK6713_AIC23_DATAHANDLE));//if ready to transmit MCBSP_write(DSK6713_AIC23_DATAHANDLE,AIC_data.uint);//write/output data }
  • 11. void output_left_sample(short out_data) //for output from left channel { AIC_data.uint=0; //clear data structure AIC_data.channel[LEFT]=out_data; //data from Left channel -->data structure transmit channel } if (poll) while(!MCBSP_xrdy(DSK6713_AIC23_DATAHANDLE));// if ready to MCBSP_write(DSK6713_AIC23_DATAHANDLE,AIC_data.uint);//output left void output_right_sample(short out_data) //for output from right channel { AIC_data.uint=0; //clear data structure AIC_data.channel[RIGHT]=out_data; //data from Right channel -->data structure transmit if (poll) while(!MCBSP_xrdy(DSK6713_AIC23_DATAHANDLE));// if ready to MCBSP_write(DSK6713_AIC23_DATAHANDLE,AIC_data.uint);//output right channel } Uint32 input_sample() //for 32-bit input { short CHANNEL_data; receive if (poll) while(!MCBSP_rrdy(DSK6713_AIC23_DATAHANDLE));//if ready to AIC_data.uint=MCBSP_read(DSK6713_AIC23_DATAHANDLE);//read data //Swapping left and right channels (see comments in output_sample()) CHANNEL_data=AIC_data.channel[RIGHT]; //swap left and right channel AIC_data.channel[RIGHT]=AIC_data.channel[LEFT]; AIC_data.channel[LEFT]=CHANNEL_data; return(AIC_data.uint);
  • 12. } short input_left_sample() //input to left channel { receive channel if (poll) while(!MCBSP_rrdy(DSK6713_AIC23_DATAHANDLE));//if ready to AIC_data.uint=MCBSP_read(DSK6713_AIC23_DATAHANDLE);//read into left return(AIC_data.channel[LEFT]); //return left channel data } short input_right_sample() //input to right channel { receive channel data } if (poll) while(!MCBSP_rrdy(DSK6713_AIC23_DATAHANDLE));//if ready to AIC_data.uint=MCBSP_read(DSK6713_AIC23_DATAHANDLE);//read into right return(AIC_data.channel[RIGHT]); //return right channel
  • 13. LISTING PROGRAM FILE SUPPORT “vector_intr.as m” *Vectors_intr.asm Vector file for interrupt INT11 .global _vectors ;global symbols .global _c_int00 .global _vector1 .global _vector2 .global _vector3 .global _vector4 .global _vector5 .global _vector6 .global _vector7 .global _vector8 .global _vector9 .global _vector10 .global _c_int11 ;for INT11 .global _vector12 .global _vector13 .global _vector14 .global _vector15 .ref _c_int00 ;entry address VEC_ENTRY .macro addr ;macro for ISR STW B0,*--B15 MVKL addr,B0 MVKH addr,B0 B B0 LDW *B15++,B0 NOP 2 NOP NOP .endm _vec_dummy: B B3 NOP 5
  • 14. .sect ".vecs" ;aligned IST section .align 1024 _vectors: _vector0: VEC_ENTRY _c_int00 ;RESET _vector1: VEC_ENTRY _vec_dummy ;NMI _vector2: VEC_ENTRY _vec_dummy ;RSVD _vector3: VEC_ENTRY _vec_dummy _vector4: VEC_ENTRY _vec_dummy _vector5: VEC_ENTRY _vec_dummy _vector6: VEC_ENTRY _vec_dummy _vector7: VEC_ENTRY _vec_dummy _vector8: VEC_ENTRY _vec_dummy _vector9: VEC_ENTRY _vec_dummy _vector10: VEC_ENTRY _vec_dummy _vector11: VEC_ENTRY _c_int11 ;ISR address _vector12: VEC_ENTRY _vec_dummy _vector13: VEC_ENTRY _vec_dummy _vector14: VEC_ENTRY _vec_dummy _vector15: VEC_ENTRY _vec_dummy
  • 15. LISTING PROGRAM PLOT SINYAL DAN FREKUENSI MATLAB x=wavread(‘file1.wav'); y=wavread('file2.wav'); fs=10000; % plot sinyal 1 t=(0:length(x)-1)/fs; % sampling %gambar 1 merupakan gambar plotting sinyal 1 figure(1) %sub gambar untuk sinyal kontinyu 1 subplot(2,1,1) plot(t,x) title(Sinyal 1 (Domain Waktu)') xlabel('Waktu (s)') ylabel('Amplitudo') axis([min(t) max(t) min(2*x) max(2*x)]) saveas(gcf, 'sinyal1', 'jpg') % fourier transform X1=fft(x); % plot spektrum dibawah 200Hz Hz200=200*length(X1)/fs; f=(0:hz200)*fs/length(X1); %sub gambar sinyal fungsi frekuensi subplot(2,1,2) a=20*log10(abs(X1(1:length(f)))+eps); plot(f,abs(a)) grid on title(sinyal 1 (Domain Frekuensi)') xlabel('Frekuensi (Hz)') ylabel('Magnitude (dB)') %Plot sinyal 2 t2=(0:length(y)-1)/fs; % sampling %gambar 2 untuk plotting sinyal 2 figure(2)
  • 16. %subgambar untuk plot sinyal 2 kontinyu subplot(2,1,1) plot(t2,y) title('Sinyal 2 (Domain Waktu)') xlabel('Waktu (s)') ylabel('Amplitudo') axis([min(t2) max(t2) min(2*y) max(2*y)]) saveas(gcf, 'sinyal 2', 'jpg') % fourier transform Y1=fft(y); % plot spektrum dibawah 100Hz hz100=100*length(Y1)/fs; f2=(0:hz100)*fs/length(Y1); %subgambar sinyal 2 domain frekuensi subplot(2,1,2) a2=20*log10(abs(Y1(1:length(f2)))+eps); plot(f2,abs(a2)) grid on title(Sinyal 2(Domain Frekuensi)') xlabel('Frekuensi (Hz)') ylabel('Magnitude (dB)') % %Gambar 3 untuk plot 3 subgambar figure(3) subplot(3,1,1) plot(t2,y,'r') title('Sinyal1(Domain Waktu)') xlabel('Waktu (s)') ylabel('Amplitudo') axis([min(t2) max(t2) min(1.5*y) max(1.5*y)]) subplot(3,1,2) plot(t,x) title('Sinyal2(Domain Waktu)') xlabel('Waktu (s)') ylabel('Amplitudo') axis([min(t) max(t) min(1.5*x) max(1.5*x)])
  • 17. subplot(3,1,3) plot(f,abs(a),'b',f2,abs(a2),'r') grid on title('Sinyal1&sinyal2(Domain Frekuensi)') legend('sinyal1','sinyal2',0); xlabel('Frekuensi (Hz)') ylabel('Magnitude (dB)') saveas(gcf, '3gbr', 'jpg') %gambar 4 untuk plotting gabungan sinyal1 dan 2 domain frekuensi figure(4) plot(f,abs(a),'b',f2,abs(a2),'r','linewidth',1.5) grid on title(sinyal 1 dan sinyal 2 (Domain Frekuensi)') legend('Output Sistem','Campuran',1); xlabel('Frekuensi (Hz)') ylabel('Magnitude (dB)') saveas(gcf, 'frekDomain', 'jpg')
  • 18. LISTING PROGRAM HITUNG SNR SINYAL DENGAN MATLAB clc, %baca sinyal suara.wav x_signal = wavread(‘sinyal suara’.wav'); %baca sinyal noise.wav x_noise = wavread('sinyal noise.wav'); %Daya Sinyal suara P_x_signal = mean(x_signal.^2); %daya sinyal noise P_x_noise = mean(x_noise.^2); %SNR SNR1 = 10*log10(P_x_signal/P_x_noise);
  • Related Search
    We Need Your Support
    Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

    Thanks to everyone for your continued support.

    No, Thanks