Design a Filter Using MATLAB

Source: Internet
Author: User
Procedure 1:
FS = 22050; % voice signal sampling frequency: 22050
X1 = wavread ('windows critical stop.wav '); % reads audio signal data and assigns it to the variable X1
Sound (x1, 22050); % play voice signal
Y1 = FFT (x1, 1024); % perform 1024-point FFT transformation on the signal
F = FS * (0: 511)/1024;
Figure (1)
Plot (X1) % to make the time domain image of the original voice signal
Title ('original speech sign ');
Xlabel ('time n ');
Ylabel ('fuzhi n ');

Figure (2)
Freqz (X1) % plot the frequency response diagram of the original voice signal
Title ('frequency response fig ')

Figure (3)
Subplot (2, 1, 1 );
Plot (ABS (Y1 () % to do the FFT Spectrum of the original voice signal
Title ('fft spectrum of original speech signal ')
Subplot (2, 1, 2 );
Plot (F, ABS (Y1 (1:512 )));
Title ('original Speech Signal Spectrum ')
Xlabel ('hz ');
Ylabel ('fuzhi ');

Procedure 2:
FS = 22050; % voice signal sampling frequency: 22050
X1 = wavread ('windows critical stop.wav '); % reads audio signal data and assigns it to the variable X1
T =/22050 :( size (X1)-1)/22050;
Y1 = FFT (x1, 1024); % perform 1024-point FFT transformation on the signal
F = FS * (0: 511)/1024;
X2 = randn (1, length (X1); % generates a random signal with the same length as X
Sound (X2, 22050 );
Figure (1)
Plot (X2) % to make the time domain image of the original voice signal
Title ('gaussian random Noise ');
Xlabel ('time n ');
Ylabel ('fuzhi n ');

Randn ('state', 0 );
M = randn (SIZE (X1 ));
X2 = 0.1 * m + x1;

Sound (X2, 22050); % voice signal after noise is played
Y2 = FFT (X2, 1024 );
Figure (2)
Plot (T, X2)
Title ('noisy speech sign ');
Xlabel ('time n ');
Ylabel ('fuzhi n ');
Figure (3)
Subplot (2, 1, 1 );
Plot (F, ABS (Y2 (1:512 )));
Title ('original Speech Signal Spectrum ');
Xlabel ('hz ');
Ylabel ('fuzhi ');
Subplot (2, 1, 2 );
Plot (F, ABS (Y2 (1:512 )));
Title ('noisy Speech Signal Spectrum ');
Xlabel ('hz ');
Ylabel ('fuzhi ');

Based on the above code, you can modify the following error code
Procedure 3: design a Butterworth Filter Using Bilinear Transformation

FS = 22050;
X1 = wavread ('H: \ Course Design 2 \ shuzi.wav ');
T =/22050 :( size (X1)-1)/22050;
Au = 0.03;
D = [Au * Cos (2 * pI * 5000 * t)] ';
X2 = X1 + D;
WP = 0.25 * PI;
Ws = 0.3 * PI;
Rp = 1;
Rs = 15;
FS = 22050;
TS = 1/Fs;
WP1 = 2/TS * Tan (WP/2); % converts a simulated indicator to a digital indicator
WS1 = 2/TS * Tan (WS/2 );
[N, Wn] = buttord (WP1, WS1, RP, RS, 's'); % select the minimum order of the filter
[Z, P, K] = buttap (n); % create a Butterworth analog filter
[BAP, AAP] = zp2tf (z, P, K );
[B, A] = lp2lp (BAP, AAP, wn );
[BZ, AZ] = bilinear (B, A, FS); % use bilinear transform to convert a simulated filter to a digital filter
[H, w] = freqz (BZ, AZ); % plot the frequency response curve
Figure (1)
Plot (w * fs/(2 * PI), ABS (h ))
Grid
Xlabel ('frequency/Hz ')
Ylabel ('frequency response amplitude ')
Title ('butterws ')
F1 = filter (BZ, AZ, X2 );
Figure (2)
Subplot (2, 1, 1)
Plot (T, X2) % to plot the time domain diagram before Filtering
Title ('time Domain Waveform before filtering ');
Subplot (2, 1, 2)
Plot (T, F1); % plot the filtered Time Domain Diagram
Title ('time Domain Waveform after filter ');
Sound (F1, 22050); % the filtered signal
F0 = FFT (F1, 1024 );
F = FS * (0: 511)/1024;
Figure (3)
Y2 = FFT (X2, 1024 );
Subplot (2, 1, 1 );
Plot (F, ABS (Y2 (); % plot the spectrum before Filtering
Title ('spectrum before filter ')
Xlabel ('hz ');
Ylabel ('fuzhi ');
Subplot (2, 1, 2)
F1 = plot (F, ABS (f0 (); % plot the filtered Spectrum
Title ('spectrum after filter ')
Xlabel ('hz ');
Ylabel ('fuzhi ');

Procedure 4: design the filter using the Window Function Method:

FS = 22050;
X1 = wavread ('H: \ Course Design 2 \ shuzi.wav ');
T =/22050 :( size (X1)-1)/22050;
Au = 0.03;
D = [Au * Cos (2 * pI * 5000 * t)] ';
X2 = X1 + D;
WP = 0.25 * PI;
Ws = 0.3 * PI;
Wdelta = WS-WP;
N = Ceil (6.6 * PI/wdelta); % integer
Wn = (0.2 + 0.3) * PI/2;
B = FIR1 (n, Wn/PI, Hamming (n + 1); % select the window function and normalize the cutoff frequency
Figure (1)
Freqz (B, 1,512)
F2 = filter (BZ, AZ, X2)
Figure (2)
Subplot (2, 1, 1)
Plot (T, X2)
Title ('time Domain Waveform before filtering ');
Subplot (2, 1, 2)
Plot (T, F2 );
Title ('time Domain Waveform after filter ');
Sound (F2, 22050); % audio signal after filtering
F0 = FFT (F2, 1024 );
F = FS * (0: 511)/1024;
Figure (3)
Y2 = FFT (X2, 1024 );
Subplot (2, 1, 1 );
Plot (F, ABS (Y2 (1:512 )));
Title ('spectrum before filter ')
Xlabel ('hz ');
Ylabel ('fuzhi ');
Subplot (2, 1, 2)
F2 = plot (F, ABS (f0 (1:512 )));
Title ('spectrum after filter ')
Xlabel ('hz ');
Ylabel ('fuzhi ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.