Introduction

When we process an audio signal, for example, adding a sound effect, sometimes we have to think about what is the effect of that processing on the audio? Does it raise the low frequencies or the high frequencies? Or does the frequency change periodically?

Of course, you can use your ears, but it’s too hard to do that. Not everyone has golden ears. Even if your ear is good enough to pick up the most subtle distinctions, how do you describe them in terms that humans can understand? After all, not everyone has the ability to describe things.

In summary, we need a quantifiable way to describe the process of processing. Needless to say, we can only describe this complex process mathematically. In this article, we will look at the “processing” process from multiple perspectives.

Some knowledge foundation

The following are some basic signal processing knowledge, which will not be very detailed, but all point to point, the purpose is to string together the whole content, forming a self-closed loop. More in-depth introduction, we are interested in the DSP book to see it.

Signal said

First, how do you represent an audio signal (we’re only talking about discrete signals)? Very simply, we describe it as an array, a signal of length N, which can be expressed as:


We call x[n] a discrete time series

Unit pulse signal

The mathematics of it looks like this:


It looks like this:

Linear time invariant filter

The so-called filter, in fact, is the signal “operation” : a signal, through the filter, into another signal. We focus here on Linearity and time-invariance; LTI) filter. LTI filters are widely used and are the most powerful family of filters. We can express an LTI filter with the difference equation:


Where x is the input sequence and y is the output sequence.andAs the coefficient.

Impulse response

The result obtained by feeding the unit impulse signal into an LTI filter is called the impulse response and is usually expressed as

convolution

signalAfter LTI filter, this process can be expressed as the impulse responsewithThe convolution of:


Z transform

Now let’s talk about the Z transform, which is very important.

Z transform can transform discrete time series into expressions in complex frequency domain. Er… Well, the preceding sentence is copied by Baidu Encyclopedia, for those of you who have never been exposed to Z transformation, this sentence is simply too good. Let’s try to understand it from an emotional point of view, using concrete examples.

The formula for Z transformation is very simple, as follows:


For example, the discrete time series is: x[0]=1, x[1]=2, x[2]=3, then:


By Z transformation, we convert a sequence of N values into an expression of Z (a value). The Z transformation can be viewed as a linear transformation, as in the example above, and can be rewritten as a multiplication of two vectors:


There’s an important property about the Z transform, convolution. Two signals convolved in the time domain is equal to multiplying in the Z transform domain


As mentioned earlier, the signal passing through the filter can be expressed as a convolution process (4), then forZ change is carried out to obtain:


From the point of view of this formula,Is actuallyPerformed a linear transformation to get, whereIs what we callTransfer function; TF)


The formula above also shows that the impulse responseThe change in Z of phi is equal to the transformation equation. This is oA method of calculatingAnd then you take the inverse z transform, and you get

There are a few other properties we need to know about the Z transform:




Therefore, for an LTI filter (3), we perform Z transformation to obtain:


By combining the same items, we get:


ifLet’s add some 0 coefficients to make the left and right sides the same.

The transfer equation is obtained:


Describe a filter from multiple angles

The Difference equation

As shown in equation (3), this is the difference equation. Let’s give two examples to get a feel for it.


and


An impulse signal is input into (14) to obtain the impulse response.The value of theta approaches 0, and we call such a filter thetastable.

An impulse signal is input into (15) to obtain the impulse response.The value of theta gradually goes off to infinity, and we call such a filter thetaunstable.

Block diagram

Sometimes it is more consistent with human cognitive processes to display filters in graphical form. Take Equation (3) for example, its block diagram is as follows:

Well, it looks complicated. Let’s look at a simple example, a delayed signal:


It looks like this:

Impulse response

As mentioned earlier, an impulse signal (equation (3)) is fed into a filter and the output is observed to obtain the impulse response.

For example, there is a filter:


You can plot the impulse response of the filter using the following MATLAB code

g1 = 0.5^3;  B = [1 0 0 g1];      % Feedforward coeffs
g2 = 0.9^5;  A = [1 0 0 0 0 g2];  % Feedback coefficients

h = filter(B,A,[1,zeros(1.50)]);  % Impulse response
% h = impz(B,A,50); % alternative in octave-forge or MSPTB

% Matlab-compatible plot:
clf; figure(1); stem([0:50],h,'-k'); axis([0 50 0.8 1.1]);
ylabel('Amplitude'); xlabel('Time (samples)'); grid;
Copy the code

Of course, there are more precise calculationsRightThe z transformation gives you the transfer functionAnd so onYou take the inverse z change and you get.

It can be obtained by formula (13), which is fairly easy. I haven’t learned the inverse Z transform yet, so I can’t explain it to you. But we can verify thatThe z transformation of phi is the result of equation (13).

Z transformation is performed on Formula (16) to obtain the transfer equation:


takeThat they may have

Then we compute H(z) in the code, which is also 0.9972, exactly the same.

g1 = 0.5^3;  B = [1 0 0 g1];      % Feedforward coeffs
g2 = 0.9^5;  A = [1 0 0 0 0 g2];  % Feedback coefficients

h = filter(B,A,[1,zeros(1.50)]);  % Impulse response
z_value = 2;                      % z = 2
z = zeros(1.length(h)) + z_value; 
Z = z.^-(0:length(h)- 1);
HZ = h*Z';                        % calculate H(z), the result is 0.9972
Copy the code

Transfer function

The transfer equation is already up here, rightYou can get it by applying the z transformation, or you can get it by formula (13). In the analysis of LTI filters, the transfer equation is an important method.

Poles, zeros gain and gain Poles

Let’s multiply the top and the bottom of equation 13, obtain a set of polynomials and factorize


We callGain (Gain)

We callThe pole (Poles)when.

We callZero (Zeros)when.

We plot all poles and zeros on a complex plane. If all poles are in the unit circle, then the filter is stable; If all zeros are in the unit circle, then we call this filter a minimum phase filter.

Frequency Response

The spectral response refers to the change in the frequency domain of the signal after it passes through the filter. It is defined as the spectrum of the output signal divided by the spectrum of the input signal

The spectral information of a signal can be obtained by Fourier transform (DTFT) :


Does DTFT look a lot like the Z transform to you? Formula (5), then it perfectly corresponds to DTFT. And there was a, so:


So the spectral response is essentially


Among them, includingIs the signal frequency in the range of, so

Spectrum response is divided into Amplitude response and Phase response.

The amplitude response is essentiallyTake the absolute value. The amplitude response can account for the effect of the filter on the amplitude of each frequency.

And the phase response is essentially, which describes the effect of the filter on each frequency phase

Practical examples

A thousand words are not as good as an actual example. Suppose we have a filter like this:


Z transform:


Calculate the transfer equation:


Factor it


Get two poles:

You get two zeros, and they’re both atIf you plot them on the complex plane, you can see that all the poles are in the unit circle, so the filter is stable; All zeros are in the unit circle, so it’s minimum phase

whenIt, and then, calculate its amplitude response and phase response, and directly calculate with the code:

w = 0:0.001:pi;
E = exp(1j*w);

Hz = (4*(E.^2) - 4*E + 1) ./ ((E.^2) + E + 0.5);

amplitude_Hz = abs(Hz);
phase_Hz = angle(Hz);

figure(1);
plot(20*log10(amplitude_Hz));

figure(2);
plot(phase_Hz*180/pi);

Copy the code

The result might look something like this:

As can be seen from the figure, this filter suppresses low frequency information in the signal and gains high frequency information. in(17.3kHz at 44.1kHz sampling rate). For very high and very low frequency information, this filter has only a small effect on the phase. But in the(11.025kHz at the sampling rate of 44.1khz), the phase information is offset by 116 degrees

conclusion

This article describes several ways to recognize a filter,

  • Difference equation
  • Block diagram
  • Impulse response
  • Transfer equation
  • Poles, zeros, and gains
  • Spectral response

And enumerate relevant examples, let everybody have more in-depth understanding and experience.

Reproduced please indicate the source juejin.cn/post/684490…