# RMIT University School of Electrical and Computer Engineering

EEET2369 – Signals and Systems Lab Experiment #4 Implementing FIR filters in MATLAB Lecturer: Dr. Katrina Neville Tutor: Refat Kibria Student Name: Tharindu De Silva Student Number: S3140219 Group: Monday 13:30-15:30 Submission Due Date: 7th May 2012

1 Tharindu De Silva s3140219

First difference FIR filter and a running average FIR filter. their frequency response and their practical applications. being able to load audio and image files onto MATLAB and manipulate these signals gives a better feel about the technique being analysed. This is a mathematical process where the output is derived from convolving the input signal x[n] with the system’s impulse response h[n]. FIR filters can be used to add different kinds of effects. what students perceive with what is actually happening in the frequency domain. MATLAB provides some very interesting functions in its signal processing toolbox that enables the user to define impulse responses to design filters and to apply these onto signals using convolution. Frequency response analysis of these FIR filter designs will be performed to confirm. 2 Tharindu De Silva s3140219 . MATLAB is a very useful platform to digitally design and test FIR filters on digital signals. In the practices of audio and image processing. basic design and implementation of FIR filters will be discussed. Filters are systems used to change an input signals characteristics. In order to derive the output of a FIR filter. MATLAB will be used to design and implement FIR filters on audio and image files.Introduction Analogue signals are sampled and quantized to transform into the digital or discrete domain. and analysed to understand the system’s characteristics. Two simple types of filters. Both sonic and visual perception will be used to observe the effects to understand filtering in a perceptive point of view. An FIR filter can be mathematically represented as. Discrete-time filtering systems can then be applied on these discrete-time domain signals in order to apply different visual and sonic effects. This exercise will enable students to have a basic understanding of FIR filters. In the final section magnitude and phase responses of FIR filters will be analysed. Where bk is the filter coefficient. Finite impulse response (FIR) filters are types of filters that are used in digital signal processing to manipulate a digitized signal. As seen in the previous laboratory exercise. implemented. These samples are stored as digitized data which represents the original waveform. FIR filters are defined as systems that produce an output as a sum of a finite number of weighted samples of an input signal [1]. Common types of signals that can be used in this case are audio and image signals. FIR filters can be designed to give many useful characteristics to an input signal. we use the process of convolution in the time domain. will be designed. In this laboratory exercise. Another important form of representing a FIR filter is through its impulse response where an unit impulse sequence is regarded as the input of the system [1].

each Impulse response needed to be defined in the ‘h(delay) = gain’ form (see appendix for code). h[n] = δ[n] + 1/2δ[n-4000] + 1/4δ[n-8000] . A time vector of the length of the .Task 1 A sample speech audio file is loaded on to MATLAB and plotted on both time and frequency domains. MATLAB’s stem() function is used to plot this filter. The Impulse response plot for this FIR filter is shown in figure 2.25. 3 Tharindu De Silva s3140219 . h(4000) = 0. the impulse response vector will be h(1) = 1. Thus for our filter.5 and a delay of 4000 and so on.5 and h(8000) = 0. each δ term has a gain and delay.wav file was needed to be generated and it was done using simple logic used in previous laboratory tasks (See appendix for code). The 1st term has a gain of 1 and there’s no delay and the 2 nd term has a gain of 0. Figure 1 Task 2 An impulse response vector is created in MATLAB for a given FIR filter whose impulse response is given by . First.

wav file and soundsc() function is used to listened to the filtered audio file.Figure 2 Task 3 This FIR filter is applied to the . Figure 3 4 Tharindu De Silva s3140219 .

We use convolution to apply the filter onto the audio file. We can define the specific gains corresponding to these delay paths. The filtered image is shown in figure 4.png image file. Task 4 In this task we apply a first difference FIR filter to . we can hear the echo phenomena occurring. In the frequency plot. This is a very interesting phenomena for sound production where the sound engineer can design and implement FIR filters to add customized echo and reverb effects to audio signals. we can see that the filter supresses the low frequency components of the input signal [1]. Convolution in the time domain is multiplication in the frequency domain. Figure 3 shows the time domain and frequency domain plots for the filtered signal. When we listen to the filtered signal. This observation proves the above theory. This means we can control how much of delay we want and how many times we want the delay to occur. When we obtain the magnitude plot from this. 5 Tharindu De Silva s3140219 . The conv2() function is used to apply this filter onto the image. First we define the impulse response vector for this filter. segments of the input signal is delayed when passed through the filter. we see that the magnitude has doubled. Figure 4 A first difference filter is given by the equation y[n] = x[n] – x[n-1] with the frequency response of 1-cosώ + jsinώ. Magnitude of this system will be 1-cosώ. In the convolution process. Thus this FIR filter acts as a high pass filter. Since our impulse response had delay terms. the input data is passed through the delay paths of the filter and we can hear the echo effect.

high frequency components haven’t been let through by our filter. runavh = (1/5)*ones(1. The defined impulse response vector is shown as. This proves our hypothesis that the running average filter is indeed a low pass filter. An L point running average filter can be represented as When we plot the magnitude response for this filter we can see that all the high frequency components are suppressed [1]. This proves our hypothesis that the first difference FIR filter is a high pass filter.5) Again we use the conv2() function to filter the image. Figure 5 In figure 4. Thus we can say that this filter acts as a low pass filter. Task 5 We created a 5 point running average FIR filter and apply this onto the same image file used in the previous task. The filtered image is shown in figure 6. we see that the high frequency components in the original image are let through while the low frequency components are suppressed. 6 Tharindu De Silva s3140219 .The high spatial frequency areas in the original image are shown in figure 5. Again referring back to figure 4 we can note that all the high spatial frequency areas have been blotted out.

11). Task 6 The frequency response of the above FIR filters are plotted in MATLAB using the freqs() function. the denominator is always 1. Likewise. For FIR filters. whereas num and den are the numerator and the denominator coefficients in the transfer function for the filter. Thus the quality decreases. when the length is decreased. For the ‘num’ parameter. 7 Tharindu De Silva s3140219 . This point was confirmed using an 11 point running average FIR filter defined by runavh = (1/11)*ones(1. Magnitude and the phase plots for the first difference FIR filter is shown in figure 7. the quality increases. den) . Freqs(num.Figure 6 When the length of the filter is increased. The syntax for the function is as follows. we can use the impulse response vector. more high spatial frequency components are cut out.

we see that the filter only allows the high frequency components to pass through. we use two different filters to better understand how they behave. Frequency plots for 11 point and 5 point running average filters are shown by figures 8 and 9 respectively. This plot confirms the hypothesis that the first difference FIR filter acts as a high pass filter.Figure 7 On the magnitude plot. Figure 8 11 point running average filter 8 Tharindu De Silva s3140219 . When analysing the running average filters.

Even this filter can be used on this simple image file to filter frequencies. we can clearly see that when the length of the filter increases. This feature explains why the quality of the image deteriorated when we increased the length of the running average filter.Figure 9 5 point running average filter Comparing figures 8 and 9. the running average filter is a poor low pass filter due to its slow roll off and stop band attenuation [2]. more high frequency components are supressed (note the curves). 9 Tharindu De Silva s3140219 .

Software environments like VDSP++ enables a developer to implement FIR filter systems to process audio on real time systems using Blackfin processors.adobe.html 10 Tharindu De Silva s3140219 . echo. These types of filters can be used in applications where the input signal needs to attenuated in regards to its frequency. We can observe the frequency response of a FIR system and determine whether the filter would act as a high or low pass filter. 3.0/help. Stephen W. New Jersey: Prentice Hall. Furthermore MATLAB provide tools to analyse frequency responses of such systems enabling the engineer to evaluate their design before progressing on to the actual hardware design phase.” http://help.com/en_US/Audition/3. This practical application has given FIR filters a profound importance in the field of signal processing and sound engineering. James H. Ronald W. Firmware could be developed for such processors to implement FIR filters to use on video signals which can be beneficial for video and animation designers. This is an important fact when it comes to the design of such filters. 1997. thus attributing visual and sonic effects. chapter 15. DSP first: A multimedia approach.html?content=WS58a04a822e3e5010548 241038980c2c5-7f1c. This process of 2 point evaluation (hand written and simulated). In Audio recording and processing software like Adobe Audition. Adobe systems INC. The scientist and engineers guide to digital signal processing. References 1. First difference and running average filters are examples of high and low pass filters respectively. These filters can be designed to acts as high/low pass filters in filtering out certain frequency components from a signal. San Diego. Smith. MATLAB provides some useful tools to help engineers design FIR filters. is vital when it comes to hardware design. 1999. Embedded environments like Analogue devices’ Blackfin family microprocessors are designed for optimal signal processing with more emphasis on audio. Schafer. frequency band splitter and graphic equalizer effects are realized with the use of FIR filters [3]. Further research can be conducted in implementing FIR filters on processors optimized for video processing systems with high processing capacities. Filter coefficients can be defined and applied to waveform using convolution functions. McClellan. Mark A. Yoder. as we’ve performed in this exercise. “Adobe Audition 3 – Help Resource Centre.Conclusion FIR filters can be designed and implemented to give echo and reverberation effects to audio and blurring and sharpening effects to images. California : California technical publishing. 2. chapter 5. changing its characteristics.

stem(h). 2012\Signals and systems\lab 4\barbara.'). h(8000) = 0.2). 11 Tharindu De Silva s3140219 . % Frequency vector (same length as the time vector) X=fftshift(fft(y))*Ts. fdiffh). Task 1 [x. Ts = 1/fs. % Frequency step for FFT display f = (-fs/2):F:(fs/2)-F.5. abs(X)). t = 0:Ts:T-Ts.1). % Frequency vector (same length as the time vector) X=fftshift(fft(x))*Ts. % Time vector of length of the audio file F = fs/N.Appendix Given below is the MATLAB code used for this exercise. plot(f.1). fdiffh = [1. plot(t.1.1.1. plot(t. % impulse response vector yy = conv2(Data.25. Task 3 N = length(y). T = Ts * N. T = Ts * N. imshow(yy). plot(f. % Frequency step for FFT display f = (-fs/2):F:(fs/2)-F. % FFT of the signal x subplot(2. abs(X)). Task 4 Data=imread('C:\Users\Dismal\Documents\RMIT\Semester 1. fdiffh. y) subplot(2.wav'). yy = conv2(yy. Ts = 1/fs. t = 0:Ts:T-Ts.bits]=wavread('speech_dft. h(4000) = 0. N = length(x). % FFT of the signal x subplot(2. Task 2 h(1) = 1.2).png'). x) subplot(2. % Time vector of length of the audio file F = fs/N. axis ([-1000 10000 0 2]). -1].1.fs.

yy = conv2(Data. yy = conv2(yy. runavh).5). % frequency response of the running average filter 12 Tharindu De Silva s3140219 .').11). imshow(yy).png'). runavh = (1/5)*ones(1. -1]. yy = uint8(yy). % frequency response of the first difference filter freqz(runavh.png'). 2012\Signals and systems\lab 4\barbara.1).1). runavh = (1/11)*ones(1. 2012\Signals and systems\lab 4\barbara. freqz(fdiffh.Task 5 Data=imread('C:\Users\Dismal\Documents\RMIT\Semester 1. fdiffh = [1. Task 6 Data=imread('C:\Users\Dismal\Documents\RMIT\Semester 1. runavh.

Sign up to vote on this title