FIR digital filter (filters out specified noise)

Table of contents

1. Introduction:

(1) Title:

(2) Key knowledge points:

Edit

2. Plan demonstration

2.1 Idea analysis

2.2 Solution selection

3. Specific design and implementation of courses

3.1 Introduction to algorithm principles

3.2 Programming implementation

3.3 Experiment and data analysis

3.3.1 Initial signal operation results:

3.3.2 Sound signal operation results and difference analysis after adding noise

 3.3.3 Filter design

4. Conclusion

5. References

1. Introduction:

(1) Title:

1. Record your own audio, read the audio file as the input signal, and use spectrum analysis technology to analyze the spectrum of the sound signal.

2. Draw the original audio signal x(t) waveform, estimate the amplitude, frequency, etc. of the time domain signal; draw the original audio signal x(t) spectrum, and the signal spectrum diagram.

3. Add noise. Add noise to the existing audio signal, and then draw the spectrogram of the audio signal after adding the noise.

4. Observation: Observe the changes in the waveform of adding noise to the audio signal, the differences in hearing, and the differences in spectrum distribution.

5. Experiment and think about: the choice of filter cutoff frequency.

6. The format of the design report must be standardized, and the principles, methods, and steps of the implementation must be clearly stated, the reasons for the differences must be analyzed, and the conclusions must be verified through further simulation experiments. The experimental data must be complete and fully explain the correctness of the design. , advanced nature.

(2) Key knowledge points:

  1. Matlab application: MATLAB is a commercial mathematics software produced by the American MathWorks company. The software mainly faces high-tech computing environments for scientific computing, visualization and interactive programming.
  2. Audio signal input: The audioread('a.wav') function reads the audio file.
  3. FFT: Fast Fourier Transform. Using this algorithm can greatly reduce the number of multiplications required for computers to calculate discrete Fourier transforms.
  4. Noise generation: randn(N,1) is to generate an NX1 random noise matrix that obeys the Gaussian distribution with a variance of 1 and a mean of 0 (i.e. N(0,1)).
  5. Cutoff frequency: The concept of cutoff frequency is applied to frequency band characteristics such as low pass, high pass, band pass, and band stop in signal transmission channels such as electronic filters. The cutoff frequency is sometimes defined as the intersection of the passband and cutoff band of an electronic filter.

2. Plan demonstration

2.1 Idea analysis

2.2 Solution selection

 Theoretical principles:

Filtering the sound is mainly based on the difference in frequency between the original sound signal and the noise sound signal, retaining the main frequency range of the original sound signal, and filtering out the frequency range of the noise sound signal. Therefore, the key is to convert the sound signal into the time domain and the frequency domain, and process the frequency domain. Mainly usedDiscrete Fourier Transform (DFT).

When adding noise signals, our group considered two types of noise signals, namely single-frequency interference noise and Gaussian random noise. Because the two types of noise are obviously different and can represent different situations, we did not make a choice, but conducted experiments on both. , in order to obtain a more general conclusion.

         When filtering, we considered FIR filters and IIR filters. Because FIR has the advantages of linear phase and easy design, and the information given in the textbook is FIR filter information, we finally decided to use FIR filters.

Technical methods of implementation:matlab language, FFT algorithm, single-frequency interference noise signal, Gaussian random noise signal, FIR filter design

Tools and platforms used for design and development:Computer, MATLAB

3. Specific design and implementation of courses

3.1 Introduction to algorithm principles

  1. First use the audioread('a.wav') function to read the audio file and obtain the audio matrix vector x and sampling frequency fs. Take the first column of x and calculate it based on the x sequence length (number of sampling points) and sampling frequency. Find its time length t, and then draw the time domain signal with t as the abscissa;
  2. Then use the fft() function to perform a discrete Fourier transform (DFT) on x to obtain X, and draw a spectrogram. (The picture below shows the DFT transformation formula).

  1. Signal spectrum diagram drawing principle - FFT algorithm:

(1) FFT is the abbreviation of an efficient and fast calculation method that uses computers to calculate Discrete Fourier Transform (DFT).

(2) Core idea: Use the properties of the complex exponential sequence to combine and simplify the DFT definition, thereby decomposing the N-point DFT calculation into two N/2-point DFT calculations, and this decomposition can be carried out in sequence. , until it is decomposed into a 2-point DFT. In this way, the N-point DFT calculation can be calculated from the 2-point DFT, and the iterative process is used until the N-point DFT is calculated.

  1. The addition of noise uses the superposition of signals to generate the signal after the noise is added.
  2. The selection of noise signals uses sinusoidal sound signals and Gaussian random noise signals.
  3. Design of FIR filter:The filter design function fir2 and the digital filter function filte are used.

Characteristics of FIR: (1) The unit impulse response of the system is not zero at a limited number of n values. (2) For a stable system, the system function converges at lz l>0, and the poles are all at z=0. (3) The structure is mainly non-recursive, with no feedback from the output to the input, but some structures (such as frequency sampling structures) also contain the recursive part of feedback.

3.2 Programming implementation

%读入音频
[x,fs]=audioread('D:\作业\大二\信号与系统\新录音 19.wav'); % 读取音频文件中的数据,并返回样本数据x以及该数据的采样频率fs。
x=x(:,1); % 读入信号为列矩阵,从中取出第一列(声道中的第一个声道)
x=x';  %将x由列矢量转置成习惯上的行矢量
%player=audioplayer(x,fs);%创建用于播放音频的对象
%play(player);%播放音频
 
%绘制时域信号
N=length(x); %x的长度(抽样点数)
n=0:N-1; %采样点序列
t=n/fs; %时间点序列(也表示音频时长)
figure(1); %创建窗口1
subplot(3,2,1);plot(t,x);grid on; %绘制时域信号
title('初始信号时域波形'); %图像名称
xlabel('时间'); %横轴标志
ylabel('幅值'); %纵轴标志
 
%绘制频域信号
X=fft(x); %对时域信号x进行离散傅里叶变换得频域信号X
fm=n/N*fs; %原始信号的不同模拟频率分布
subplot(3,2,2);plot(fm,abs(X));grid on; %绘制原始信号频谱波形,横坐标为模拟频率
title('初始声音信号频谱'); %图像名称
xlabel('模拟频率/Hz'); %横轴标志
ylabel('幅度'); %纵轴标志
axis([0 fs/2 0 300]); %展示物理谱范围内的频谱图
%axis( [xmin xmax ymin ymax] ),设置当前二维图形对象的 x 轴 和 y 轴的取值范围 

%加入噪音
fn=3000; %加入噪声信号的模拟频率
% y=x+0.1.*sin(fn*2*pi*t); %y为加入单频干扰信号后的音乐,加入的为正弦信号
y=x+0.1*randn(1,N);% 也可使用randn函数产生一个与音频信号等长度的高斯随机噪声信号(噪声大小取决于随机函数的幅度倍数)
% sound(y,fs);%播放增加正弦信号噪音后的声音
subplot(3,2,3);plot(t,y);grid on; %将时域信号绘制在画布上
title('加入噪音后的时域波形'); %图像名称
xlabel('时间'); %横轴标志
ylabel('幅值'); %纵轴标志
Y=fft(y); %对加噪后的信号y进行离散傅里叶变换
subplot(3,2,4);plot(fm,abs(Y));grid on; %绘制加噪后的频谱波形,横坐标为模拟频率
title('加入噪音后的信号频谱');
xlabel('模拟频率/Hz');
ylabel('幅度');
axis([0 fs/2 0 300]); %展示物理谱范围内的频谱图



%设计滤波器-单频干扰噪声
f1=800; %取模拟通带截止频率f1=800Hz
f2=2000; %取阻带边界频率f2=2000Hz
%将模拟频率映射到[0,1]区间求数字频率
F1=f1/(fs/2); 
F2=f2/(fs/2); 
Fc=(F1+F2)/2; %取截止频率Fc为F1和F2中点

% % 设计滤波器-高斯随机噪声
% f1=800; %取模拟通带截止频率f1=800Hz
% f2=1000; %取阻带边界频率f2=1000Hz
% %将模拟频率映射到[0,1]区间求数字频率
% F1=f1/(fs/2); 
% F2=f2/(fs/2); 
% Fc=(F1+F2)/2; %取截止频率Fc为F1和F2中点

%设定数字滤波器参数
frange=[0,Fc,Fc,1];
hval=[1,1,0,0];
b=fir2(300,frange,hval);
[H,W]=freqz(b,1);
figure(2);%新建2号窗口显示滤波器特性
plot(W/pi,abs(H));grid on;
title('低通滤波器的幅频特性');

%进行滤波
figure(1); %绘制在1号窗口上
z=filter(b,1,y); %对加噪信号y进行滤波
subplot(3,2,5);plot(t,z);grid on;%绘制滤波后信号的时域图
xlabel('时间');
ylabel('幅度');
title('低通滤波后的信号波形');
Z=fft(z); %对滤波后信号进行傅里叶变换
subplot(3,2,6);plot(fm,abs(Z));grid on;%绘制滤波后信号的频域图
xlabel('模拟频率/Hz');
ylabel('幅度');
title('低通滤波后的信号频谱');
player=audioplayer(z,fs);%创建用于播放音频的对象
axis([0 fs/2 0 300]); 
play(player);%播放音频

3.3 Experiment and data analysis

3.3.1 Initial signal operation results:

Time waveform:

(1) Amplitude: The amplitude is between plus and minus 0.1. You can see with the naked eye that there are about 9 waveforms with amplitudes changing from large to small (the audio actually says nine Character).

(2) Frequency: roughly distributed around 1000hz

Signal 频谱

It can be intuitively seen from the figure that the frequency component in the low frequency part is high and the frequency component in the high frequency part is low. It can be seen that the sound signal

is a low frequency signal. If you zoom in on the picture further, you can see that the frequency of the sound signal is mainly distributed between 0-800Hz.

 After enlarging the frequency domain diagram

3.3.2 Sound signal operation results and difference analysis after adding noise

1. When adding single frequency interference signal:

Add sinusoidal signal noise

(1) In terms of hearing, if there is a "ding" sound in the original sound that runs throughout the signal, the main information of the original sound signal can still be heard.

(2) In the time domain, the original signal waveform is divided into two parts by the x-axis, and a waveform with a constant amplitude of 0.1 and a high frequency is inserted from the middle. The original signal waveform is distributed on the upper and lower sides of the waveform.

(3) In the frequency domain, an infinite straight line appears at 3000Hz.

2. When adding high-frequency random noise:

Add Gaussian random noise signal

(1) Auditory: A noisier sound layer will be heard, and the original sound signal can hardly be heard.

  (2) In the time domain, the original waveform cannot be observed at all. In terms of amplitude and density, the waveform is much more uniform than the original signal, the spectral lines are much denser, and the amplitude has also increased.

  (3) In the frequency domain, except for the original frequency components with large amplitudes in the very low frequency range, waveforms with uneven but not very different amplitudes are almost evenly distributed in other frequency ranges. The original frequency domain waveforms are covered up, and it can be seen that the noise is in the frequency domain. There are distributions in each frequency domain.

The observed changes in the spectrogram are consistent with our purpose, and the noise addition is successful.

 3.3.3 Filter design

When choosing a FIR low-pass filter, the ideal low-pass cutoff frequency is generally placed at the midpoint of the transition zone.

Design steps for an ideal low-pass filter:

  1. Determine the analog passband cutoff frequency f1 and stopband boundary frequency f2 according to the application requirements (the two form the transition zone);
  2. Select the cutoff frequency fc=(f1+f2)/2 to simulate the ideal low-pass filter;
  3. Calculate the digital frequency Fc corresponding to fc.
  1. When the noise is a single-frequency interference signal:

cutting ratio :

(1) The main analog frequencies of the original signal are mainly distributed between 0-800Hz, The analog passband cutoff frequency f1=800Hz; a>

(2) The analog frequency of the single-frequency interference signal is 3000Hz, so a low-pass filter should be used for it, low-pass and high-pass filter frequency, stop band boundary frequencyf2<3000Hz, take f2=2000Hz ,

(3) Takefc=(f1+f2)/2=1400Hz and convert it to a number in the interval [0,1] The frequency is:Fc=fc/(fs/2)=0.0583.

Experimental verification:

Amplitude-frequency characteristics diagram of low-pass filter

Time domain and frequency domain comparison chart before and after filtering

It can be seen from the figure that the filtered signal can better restore the original signal waveform and achieve the purpose of filtering.

2. When the noise is Gaussian random noise:

(1) The frequency of the noise signal is evenly distributed in each frequency range. The original signal is mainly distributed between 0-800Hz. If you want to filter out Gaussian noise and retain the original signal, you must also choose Low pass filter.

(2)Analog passband cutoff frequencyf1 should be greater than or equal to 800Hz, Stopband boundary frequency should be greater than 800Hz and close to 800Hz, take f1=800Hz, stop band boundary frequencyf2=1000Hz;

(3) Takefc=(f1+f2)/2=900Hz and convert it to a number in the interval [0,1] The frequency is,Fc=fc/(fs/2)=0.0375.

Experimental verification:

Amplitude-frequency characteristics diagram of low-pass filter

Time domain and frequency domain comparison chart before and after filtering

It can be seen from the figure that the filtered signal can better restore the original signal waveform and achieve the purpose of filtering.

4. Conclusion

(1) Analysis of original signal:

1. In the time domain: it is uneven. You can see with the naked eye that there are about nine waveforms with amplitudes changing from high to low.

2. In the frequency domain: the frequency component of the low-frequency part is high, and the frequency component of the high-frequency part is low. It can be seen that the sound signal is a low-frequency signal, and the main frequency component is between 0-800Hz.

(2) Comparative analysis of signals before and after adding noise:

When adding 3000Hz single frequency noise with an intensity of 0.1:

1. Auditory: a "ding" sound appears;

2. In the time domain: the absolute value of the amplitude of each sampling point increases by 1, the waveform between the amplitude of plus and minus one becomes denser, the frequency increases, and the original signal waveform is cut in the middle and distributed to the upper and lower sides of the plus and minus one.

3. In the frequency domain: An infinite straight line appears at 3000Hz in the frequency domain.

When adding Gaussian random noise with intensity 0.1:

1. Auditory: A noisier sound layer will be heard, and the original sound signal can hardly be heard.

2. In the time domain: the original waveform cannot be observed, the amplitude is much more uniform and increased, and the spectral lines are much denser.

3. In the frequency domain: the original frequency component with large amplitude in the low frequency part is still retained. In other frequency ranges, the original frequency domain waveform is covered by waveforms with uneven but not large amplitudes distributed almost evenly.

(3) Selection of cutoff frequency:

When adding 3000Hz single frequency noise with an intensity of 0.1:

Select the cutoff frequency with an analog frequency of 1400Hz (corresponding to a digital frequency of 0.0583).

When adding Gaussian random noise with intensity 0.1:

Select a cutoff frequency with an analog frequency of 900Hz (corresponding to a digital frequency of 0.0375).

Select based on:

The filter design stopband should contain as many noise signal frequencies as possible, the passband should contain as many original signal frequencies as possible, and the cutoff frequency fc should be in the transition band between the passband cutoff frequency f1 and the stopband boundary frequency f2 , generally selected at the midpoint of the transition zone.

(4) Others

When the frequency difference between the noise and the original signal is large, it is better to separate and filter. When the difference is small or they overlap, it is difficult to separate and filter.

5. References

CSDN:"Detailed explanation of fft function in Matlab", "Very simple and easy to understand FFT (Fast Fourier Transform)"

"Signals and Systems" textbook:"4.3-Discrete Fourier Transform", "4.4-Discrete Time System and Continuous Time System", "Digital Filtering-FIR Filter" ", "4.6-MATLAB Practice"

Zhihu:"Speech Denoising Processing Based on Matlab"

Fan Changxin, Cao Lina. Communication Principles[M]. Beijing: National Defense Industry Press, 2008.

Huangfu Kan, Chen Jianwen, Lou Shengqiang. Modern digital signal processing[M]. Beijing: Electronic Industry Press, 2003.

Wu Hongwei, Wu Zhenyang, Zhao Li. Psychoacoustic speech enhancement based on multi-window spectra [J]. Acta Acoustica Sinica, 2007, 32(3): 275-281.

Guess you like

Origin blog.csdn.net/m0_64054405/article/details/128400960