RMIT University School of Electrical and Computer Engineering EEET2369 – Signals and Systems Assignment #2 Lecturer: Dr. Katrina Neville Student Name: Alakawalage Don Bhanuka Sachintha Samarakkody Student Number: s3490356 Submission Due Date: 15th May 2015s3490356 Alakawalage Don Bhanuka Samarakkody 1 Introduction The main purpose of this assignment is to investigate the uses of the SMA (Simple Moving Average) and EMA (Exponential Moving Average) filters and the uses of the filters, the pros and the cons of using each filter for its uses ,and to identify which filter is better suited for which purpose and to what extent the data from each filter can be trusted, which filter most accurately allows trends to be identified and how the two filters together can provide a unique set of information relevant to making important decisions. Eg: what instances to buy and sell shares. How the general difference equations and transfer functions are found and how the SMA and EMA filters are related to the above equations and the qualities of each of the filters whether , high pass, low pass , etc. and how that can be identified from the frequency response graph created by using the freqz() function in MATLAB.s3490356 Alakawalage Don Bhanuka Samarakkody 2 Simple Moving Average (P1HW-1) Impulse graph for a filter with a length of 5 samples (P1HW-2)s3490356 Alakawalage Don Bhanuka Samarakkody 3 The graph in figure (1) below shows the simple moving average filter for the closing stock prices for Caltex Figure (2) below shows the same graph as above, but the engaging of the filters have been taken out .There is an engaging delay of 5 days and of 20 days in the filtered samples respectively.s3490356 Alakawalage Don Bhanuka Samarakkody 4s3490356 Alakawalage Don Bhanuka Samarakkody 5 Discuss: 1. How well do these two filters smooth the stock price data? As clearly seen in figure (2), the short term (5 days) and the long term (20 days) filters both minimize the effect of high-frequency fluctuations or noise and remove any timely trends in frequency, The filters have brought a ‘smoothened’ effect into the original data. However when the two filters the short term and the long term are compared with each other the long term filter has a higher smoothening effect because a larger amount of samples or data points have been taken into account, so the longer term filter is more effective in the identification of trends in the stock price than the short term filter. 2. Compare the delay in the two methods. For both filters, how many initial output samples/data points should be discarded before a reliable indication of trend can be obtained from this output? Why is the case? The longer term filter has a greater delay than the short term filter simply because it uses the average data from every 20 samples, instead of the 5 which the short term filter uses, hence it takes a bit longer to adjust to the changes in the stock price.s3490356 Alakawalage Don Bhanuka Samarakkody 6 3. Use the Math lab freqz() function on these two filters. Do they behave as low-pass, high pass, band-pass or band-stop filters? How does the length of the filter affects the passband region (frequency that the filter passes)? By observing the graphs below the, properties of a graph of a low pass filter can be identified as the band of the phase response keeps increasing slightly every time. The lower the length of the filter the greater number of frequencies pass through giving a closer to accurate signal, but the greater the length the less frequencies that pass through , which produce a smoother curve.s3490356 Alakawalage Don Bhanuka Samarakkody 7s3490356 Alakawalage Don Bhanuka Samarakkody 8 Exponential Moving Average (P2HW-1) (P2HW-2)s3490356 Alakawalage Don Bhanuka Samarakkody 9s3490356 Alakawalage Don Bhanuka Samarakkody 10s3490356 Alakawalage Don Bhanuka Samarakkody 11 Discuss: 1. Compare the behaviour of the EMA filters with the SMA filters from part a. The SMA is commonly used as it provides a simple solution for problems, The SMA weights each data point equally and it is calculated by dividing the number of samples by the total number in the series. But in the EMA more weight is given to the recent data points and reacts quickly to changes in trends, being favourable for people seeking to identify trends. 2. Using these long and short-term average lines, identify the times when it would have been good to buy and sell stocks in your company. Justify your answer from the explanation at: http://www.asx.com.au/prices/exponential_moving_average.htm A trading signal is issued when a short term average line crosses over a longer term average line. A buy signal is produced when the short term average crosses above the longer term average. A sell signal is produce when the short term average line crosses below the long term average line. Two instances to buy and sell are indicated in the graph below. Time to sell Time to Buys3490356 Alakawalage Don Bhanuka Samarakkody 12 3. Again use the MATLAB freqz() function on these two filters and examine their frequency responses. Both the frequency responses end on an increasing straight line, which indicates that the next step would be higher, that indicates that the EMA filter acts as a low pass filter as well, similar to the SMA filter above, but since the equation for the second part ends up with only a few values for the denominator and the numerator the pattern cannot be clearly identified as earlier.s3490356 Alakawalage Don Bhanuka Samarakkody 13s3490356 Alakawalage Don Bhanuka Samarakkody 14 Appendix Some variables in the code below are similar and were commented out when obtaining the results.s3490356 Alakawalage Don Bhanuka Samarakkody 15s3490356 Alakawalage Don Bhanuka Samarakkody 16s3490356 Alakawalage Don Bhanuka Samarakkody 17 References 1. FIR and transfer functions, pg 1- 4 URL: http://www.astro.rug.nl/~vdhulst/SignalProcessing/Hoorcolleges/college07.pdf 2. The Scientist and Engineer's Guide to Digital Signal Processing, Chapter 15,Moving average Filters, pg 278-279, URL:http://www.analog.com/media/en/technical-documentation/dspbook/dsp_book_Ch15.pdf 3. Digital Filters, FIR Filters , section 6 URL : http://www.analog.com/media/en/training-seminars/designhandbooks/MixedSignal_Sect6.pdf 4. James H. McClellan, Signal Processing First, International ed., Upper Saddle River, NJ 2003,pg 110-131 5. Dr. Katrina Neville, RMIT University ,City campus , Melbourne, EEET2369 Signals and Systems : Lecture 5: Sampling and Aliasing Lecture 6: FIR Filters Lecture 7: Frequency Response of FIR Filters Lecture 8: The z-transform 6. MATLAB documentation Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. 2nd Ed. Upper Saddle River, NJ: Prentice Hall, 1999. URL: http://au.mathworks.com/help/signal/ref/freqz.html