Categories
DSP

Pemisahan Derau dan Suara – Speech Noise Reduction

Dalam suatu sistem perekaman suara, dilakukan perekaman suara secara digital dalam suatu area yang berisik dengan frekuensi cuplik 8 kHz. Dianggap bahwa rekaman suara yang dihasilkan mengandung informasi mulai dari hingga 1800 Hz, sehingga kita bisa merancang sebuah tapis lolos-rendah (low-pass) yang akan menahan derau antara 1800 Hz hingga batasan Nyquist, 4000 Hz (separo dari frekuensi cuplik 8000 Hz).

Berikut spesifikasi Tapis kita:

  • Tipe Tapis = FIR lolos-rendah (lowpass FIR filter)
  • Jangkauan Frekuensi Passband = 0 – 1800 Hz
  • Riak (ripple) pada Passband = 0,02 dB
  • Jangkauan Frekuensi Stopband = 2000 – 4000 Hz
  • Pelemahan (attenuation) pada Stopband = 50 dB
  • Tipe Jendela = Hamming
  • Jumlah koefisien = 133
  • Frekuensi cutoff = 1900 Hz

Fungsi jendela menggunakan persamaan-persamaan berikut:

Selanjutnya dibuat skrip fungsi firwd(N,Ftype,WnL,WnH,Wtype) yang digunakan untuk membuat tapis menggunakan jendela dengan listing sebagai berikut…

function B=firwd(N,Ftype,WnL,WnH,Wtype)
 %  B = firwd(N,Ftype,WnL,WnH,Wtype)
 %  Rancang Tapis FIR menggunakan metode Fungsi Jendela
 %  Parameter2 masukan:
 %  N: jumlah koefisien (tap) tapis FIR
 %     Catatan: Harus bilangan ganjil.
 %  Ftype: Tipe tapis
 %	1.  Tapis Low-pass ;
 %   2.  Tapis High-pass;
 %	3.  Tapis Bandpass;
 %   4.  Tapis Bandstop.
 %  WnL: Frekuensi cutoff bawah (radian), WnL=0 untuk Tapis Highpass
 %  WnH: Frekuensi cutoff atas (radian), WnH=0 untuk Tapis Lowpass.
 %  Wtype: tipe fungsi jendela
 %	1.  Jendela Rectangular;
 %   2.  Jendela Triangular;
 %	3.  Jendela Hanning;
 %   4.  Jendela Hamming;
 %	5.  Jendela Blackman;
 % Keluaran:
 % B: Koefisien2 Tapis FIR.
 %
 M=(N-1)/2;
 hH=sin(WnH*[-M:1:-1])./([-M:1:-1]*pi);
 hH(M+1)=WnH/pi;
 hH(M+2:1:N)=hH(M:-1:1);
 hL=sin(WnL*[-M:1:-1])./([-M:1:-1]*pi);
 hL(M+1)=WnL/pi;
 hL(M+2:1:N)=hL(M:-1:1);
 if Ftype == 1
    h(1:N)=hL(1:N);
 end
 if Ftype == 2
    h(1:N)=-hH(1:N);
    h(M+1)=1+h(M+1);
 end
 if Ftype ==3
    h(1:N)=hH(1:N)-hL(1:N);
 end
 if Ftype == 4
    h(1:N)=hL(1:N)-hH(1:N);
    h(M+1)=1+h(M+1);
 end
 % Fungsi-fungsi jendela;
 if Wtype ==1
    w(1:N)=ones(1,N);
 end
 if Wtype ==2
    w=1-abs([-M:1:M])/M;
 end
 if Wtype ==3
    w= 0.5+0.5*cos([-M:1:M]*pi/M);
 end
 if Wtype ==4
    w=0.54+0.46*cos([-M:1:M]*pi/M);
 end
 if Wtype ==5
    w=0.42+0.5*cos([-M:1:M]*pi/M)+0.08*cos(2*[-M:1:M]*pi/M);
 end
 B=h .* w

Fungsi firwd() ini akan kita gunakan dalam ekperimen Noise Removal kita ini. Baik, mari kita lakukan proses tapis derau langkah demi langkah sebagai berikut, kita awali dengan menutup jendela-jendela, sekalian membersihkan memori Matlab…

close all; clear all

Kita siapkan frekuensi cuplik (8000 Hz) dan periodenya (1/Fs), sekaligus membaca data yang digunakan untuk eksperimen ini (menggunakan instruksi load pada Matlab, data beserta listing program lengkap bisa diunduh disini):

fs=8000;T=1/fs;
load we.dat

Kemudian kita siapkan variabel waktunya (t). Mulai dari 0 (detik) hingga [Panjang(we)-1] dikali T (detik)…

t=[0:length(we)-1]*T;

Baik, sekarang kita siapkan deraunya. Derau berkaitan dengan data-data, tingkatnya tinggi (high level) dan bersifat broadband (nanti akan Anda lihat spektrumnya), diawali dengan 1/4 dari rerata kuadrat data…

th=mean(we.*we)/4;
v=sqrt(th)*randn([1,length(we)]);

Gabungkan derau (v) dengan sinyal aslinya (we) dan gambarkan hasilnya (dalam ranah waktu)….

x=we+v;
subplot(2,1,1);plot(t,x,’k’);
xlabel(‘Waktu (detik)’);ylabel(‘Amplitudo’);grid;

Kemudian gambarkan juga spektrumnya…

N=length(x);
f=[0:N/2]*fs/N;
Axk=2*abs(fft(x))/N;Axk(1)=Axk(1)/2;
subplot(2,1,2); plot(f,Axk(1:N/2+1),’k’);
xlabel(‘Frekuensi (Hz)’); ylabel(‘Besaran |X(f)| ‘);grid;

hasilnya…

Bagaimana? Sekarang Anda bisa melihat dengan jelas sinyal + derau dan spektrumnya. Perhatikan bentuk-bentuk ‘rumput’ pada spektrumnya (ini karena adanya derau). Selanjutnya dilakukan proses penapisan untuk mengambil (atau lebih tepatnya menahan) komponen derau. Kita siapkan frekuensi cutoff dalam radian yang dinormalisasi terhadap frekuensi cuplik (Fc/Fs) dikali dengan 2*pi…

wc=2*pi*1900/8000;

Kemudian kita siapkan tapisnya…

B=firwd(133,1,wc,0,4);

Dan akhirnya kita lakukan proses penapisan (filtering)…

y=filter(B,1,x);

Selanjutnya kita gambarkan hasilnya, sekalian spektrumnya…

Ayk=2*abs(fft(y))/N;Ayk(1)=Ayk(1)/2;
subplot(2,1,1); plot(t,y,’k’);
xlabel(‘Waktu (detik)’);ylabel(‘Amplitudo’);grid;
subplot(2,1,2);plot(f,Ayk(1:N/2+1),’k’);
xlabel(‘Frekuensi (Hz)’); ylabel(‘Besaran |Y(f)| ‘);grid;

Hasilnya…

Okey! Bandingkan kedua gambar tersebut, adakah perbedaan? Dalam ranah waktu? Dalam ranah frekuensi? Mo Jawab? Komentar? Pertanyaan? Silahkan gunakan form komentar di bawah ini…

Terima kasih, semoga bermanfaat.. Oya mo listingnya lengkap (termasuk data we.dat)? Unduh aja disini (RAR)!

Catatan:

  • Beberapa instruksi yang tidak dijelaskan dalam artikel mohon merujuk HELP-nya Matlab.

sumber:

  • Tan, Li, 2008, Digital Signal Processing: Fundamentals and Applications, Academic Press, Elsevier, USA
Categories
DSP

What is a Filter? And why learn about it?

What is a Filter?

Any medium through which the music signal passes, whatever its form, can be regarded as a filter. However, we do not usually think of something as a filter unless it can modify the sound in some way. For example, speaker wire is not considered a filter, but the speaker is (unfortunately). The different vowel sounds in speech are produced primarily by changing the shape of the mouth cavity, which changes the resonances and hence the filtering characteristics of the vocal tract. The tone control circuit in an ordinary car radio is a filter, as are the bass, midrange, and treble boosts in a stereo preamplifier. Graphic equalizers, reverberators, echo devices, phase shifters, and speaker crossover networks are further examples of useful filters in audio. There are also examples of undesirable filtering, such as the uneven reinforcement of certain frequencies in a room with “bad acoustics.” A well-known signal processing wizard is said to have remarked, “When you think about it, everything is a filter.”

A digital filter is just a filter that operates on digital signals, such as sound represented inside a computer. It is a computation which takes one sequence of numbers (the input signal) and produces a new sequence of numbers (the filtered output signal). The filters mentioned in the previous paragraph are not digital only because they operate on signals that are not digital. It is important to realize that a digital filter can do anything that a real-world filter can do. That is, all the filters alluded to above can be simulated to an arbitrary degree of precision digitally. Thus, a digital filter is only a formula for going from one digital signal to another. It may exist as an equation on paper, as a small loop in a computer subroutine, or as a handful of integrated circuit chips properly interconnected.

Why learn about filters?

Computer musicians nearly always use digital filters in every piece of music they create. Without digital reverberation, for example, it is difficult to get rich, full-bodied sound from the computer. However, reverberation is only a surface scratch on the capabilities of digital filters. A digital filter can arbitrarily shape the spectrum of a sound. Yet very few musicians are prepared to design the filter they need, even when they know exactly what they want in the way of a spectral modification. A goal of this book is to assist sound designers by listing the concepts and tools necessary for doing custom filter designs.

There is plenty of software available for designing digital filters [10,8,22]. In light of this available code, it is plausible to imagine that only basic programming skills are required to use digital filters. This is perhaps true for simple applications, but knowledge of how digital filters work will help at every phase of using such software.

Also, you must understand a program before you can modify it or extract pieces of it. Even in standard applications, effective use of a filter design program requires an understanding of the design parameters, which in turn requires some understanding of filter theory. Perhaps most important for composers who design their own sounds, a vast range of imaginative filtering possibilities is available to those who understand how filters affect sounds. In my practical experience, intimate knowledge of filter theory has proved to be a very valuable tool in the design of musical instruments. Typically, a simple yet unusual filter is needed rather than one of the classical designs obtainable using published software.

Excerpt from “Introduction to Digital Filters: with Audio Applications” by Julius Orion Smith II