Looking at your first line of C-code:
It can be converted to an algebraic relation between the samples of the filter output sequence $y[n]$ and the filter input $x[n]$ as: $$y[n+1]-(1-a)y[n]=ax[n]$$ which is also equivalent to $$y[n]-(1-a)y[n-1]=ax[n-1]$$ And the associated transfer function of this filter is $$H(z) = \frac{a z^{-1}}{1 - (1-a)z^{-1}} = \frac{a z^{-1}}{1 + (a-1)z^{-1}}$$ Now your application will probably require a causal filter, (which means only current and past input is available and should be used to produce current output) in which case then the poles of the filter should reside inside the unit circle , i.e., $|z_p| < 1$. Since this filter has a single pole which is at $z_p=(1-a)$ then we have; $|1-a| < 1$ and hence; $$0 < a <2$$ is the allowed range of real $a$ for which you can have a stable and causal filter. Now to have a casual and stable lowpass filter you require that the pole is along the positive side of the real line, i.e., $0 < z_p < 1$ which means that we require $0 < a < 1$. Otherwise when $ 1 < a < 2$ the filter becomes a highpass filter (actually it will be some other form of high-boost or shelving type filter rather than a strict high-pass filter which should block low frequencies, which these filters won't), as the pole will become negative for that range of $a$. Note also that $a=1$ produces output equal to input shifted by 1 samples: $y[n] = x[n-1]$ Below are a few frequency response plots for different values of valid $a$ range: Let's start with a very basic example of the generic problem at hand: understanding the effect of a digital filter on the spectrum of a digital signal. The purpose of this example is to provide motivation for the general theory discussed in later chapters. Our example is the simplest possible low-pass filter. A low-pass filter is one which does not affect low frequencies and rejects high frequencies. The function giving the gain of a filter at every frequency is called the amplitude response (or magnitude frequency response). The amplitude response of the ideal lowpass filter is shown in Fig.1.1. Its gain is 1 in the passband, which spans frequencies from 0 Hz to the cut-off frequency Hz, and its gain is 0 in the stopband (all frequencies above ). The output spectrum is obtained by multiplying the input spectrum by the amplitude response of the filter. In this way, signal components are eliminated (``stopped'') at all frequencies above the cut-off frequency, while lower-frequency components are ``passed'' unchanged to the output.Definition of the Simplest Low-PassThe simplest (and by no means ideal) low-pass filter is given by the following difference equation:
where is the filter input amplitude at time (or sample) , and is the output amplitude at time . The signal flow graph (or simulation diagram) for this little filter is given in Fig.1.2. The symbol ``'' means a delay of one sample, i.e., .It is important when working with spectra to be able to convert time from sample-numbers, as in Eq. (1.1) above, to seconds. A more ``physical'' way of writing the filter equation iswhere is the sampling interval in seconds. It is customary in digital signal processing to omit (set it to 1), but anytime you see an you can translate to seconds by thinking . Be careful with integer expressions, however, such as , which would be seconds, not . Further discussion of signal representation and notation appears in §A.1.To further our appreciation of this example, let's write a computer subroutine to implement Eq. (1.1). In the computer, and are data arrays and is an array index. Since sound files may be larger than what the computer can hold in memory all at once, we typically process the data in blocks of some reasonable size. Therefore, the complete filtering operation consists of two loops, one within the other. The outer loop fills the input array and empties the output array , while the inner loop does the actual filtering of the array to produce . Let denote the block size (i.e., the number of samples to be processed on each iteration of the outer loop). In the C programming language, the inner loop of the subroutine might appear as shown in Fig.1.3. The outer loop might read something like ``fill from the input file,'' ``call simplp,'' and ``write out .''Figure: Implementation of the simple low-pass filter of Eq. (1.1) in the C programming language.
In this implementation, the first instance of is provided as the procedure argument xm1. That way, both and can have the same array bounds ( ). For convenience, the value of xm1 appropriate for the next call to simplp is returned as the procedure's value.We may call xm1 the filter's state. It is the current ``memory'' of the filter upon calling simplp. Since this filter has only one sample of state, it is a first order filter. When a filter is applied to successive blocks of a signal, it is necessary to save the filter state after processing each block. The filter state after processing block is then the starting state for block .Figure 1.4 illustrates a simple main program which calls simplp. The length 10 input signal x is processed in two blocks of length 5. Figure 1.4: C main program for calling the simple low-pass filter simplp
You might suspect that since Eq. (1.1) is the simplest possible low-pass filter, it is also somehow the worst possible low-pass filter. How bad is it? In what sense is it bad? How do we even know it is a low-pass at all? The answers to these and related questions will become apparent when we find the frequency response of this filter.Next
Section: |