code for the task 2 and I will attach the source code. ASAP source code: ;;;;;;; Assembler directives ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; list P=PIC18F4520, F=INHX32, C=160, N=0,...

code for the task 2 and I will attach the source code. ASAP source code: ;;;;;;; Assembler directives ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; list P=PIC18F4520, F=INHX32, C=160, N=0, ST=OFF, MM=OFF, R=DEC, X=ON #include __CONFIG _CONFIG1H, _OSC_HS_1H ;HS oscillator __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_ON_2L & _BORV_2_2L ;Reset __CONFIG _CONFIG2H, _WDT_OFF_2H ;Watchdog timer disabled __CONFIG _CONFIG3H, _CCP2MX_PORTC_3H ;CCP2 to RC1 (rather than to RB3) __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L ;RB5 enabled for I/O errorlevel -314, -315 ;Ignore lfsr messages ;;;;;;; Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; cblock 0x000 ;Beginning of Access RAM ; --- BEGIN variables for TABLAT POINTER ; DO NOT MODIFY (created by AC) value counter ; --- END variables for TABLAT POINTER ; Create your variables starting from here endc ;;;;;;; Macro definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MOVLF macro literal,dest movlw literal movwf dest endm ;;;;;;; Vectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; org 0x0000 ;Reset vector nop goto Mainline org 0x0008 ;High priority interrupt vector goto $ ;Trap org 0x0018 ;Low priority interrupt vector goto $ ;Trap ;;;;;;; Mainline program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Mainline rcall Initial ;Initialize everything Loop ; -------------------------------------------------------------- ; Change value for counter depending ; on period of time series that you wish to use ; MOVLF 2,counter MOVLF upper SimpleTable,TBLPTRU MOVLF high SimpleTable,TBLPTRH MOVLF low SimpleTable,TBLPTRL label_A TBLRD*+ movf TABLAT, W movwf value ; value = x[n] ;;;;;;; NOTE FOR STUDENTS: ; ; Write the code for your moving average filter in ; the empty spaces below. Please create subroutines ; to make code your code transparent and easier to debug ; ; DO NOT MODIFY ANY OTHER PART OF THE THIS LOOP IN THE MAINLINE ; ; -------------------------------------------------------------- ; BEGIN WRTING CODE HERE ; --------------------------------- ; (1) WRITE CODE FOR MEMORY BUFFER HERE ; you may write the full code ; here or call a subroutine ; --------------------------------- ; (2) WRITE CODE FOR ADDER AND DIVIDER HERE ; you may write the full code ; here or call a subroutine ; FINISH WRTING CODE HERE ; -------------------------------------------------------------- decf counter,F bz label_B bra label_A label_B bra Loop ;;;;;;; Initial subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; This subroutine performs all initializations of variables and registers. Initial MOVLF B'10001110',ADCON1 ;Enable PORTA & PORTE digital I/O pins MOVLF B'11100001',TRISA ;Set I/O for PORTA 0 = output, 1 = input MOVLF B'11011100',TRISB ;Set I/O for PORTB MOVLF B'11010000',TRISC ;Set I/0 for PORTC MOVLF B'00001111',TRISD ;Set I/O for PORTD MOVLF B'00000000',TRISE ;Set I/O for PORTE MOVLF B'10001000',T0CON ;Set up Timer0 for a looptime of 10 ms; bit7=1 enables timer; bit3=1 bypass prescaler MOVLF B'00010000',PORTA ;Turn off all four LEDs driven from PORTA ; See pin diagrams of Page 5 in DataSheet return ;;;;;;; TIME SERIES DATA ; ; The following bytes are stored in program memory. ; Created by AC ; ; Choose your Periodic Sequence ;-------------------------------------------------------------- ; time series X1 SimpleTable ; ---> period 2 db 180,240 ;-------------------------------------------------------------- ; time series X2 ;SimpleTable ; ---> period 4 ;db 180,240,200,244 ;-------------------------------------------------------------- ; time series X3 ;SimpleTable ; ---> period 6 ;db 180,240,200,244,216,236 ;-------------------------------------------------------------- ; time series X4 ;SimpleTable ; ---> period 8 ;db 180,240,200,244,216,236,160,176 ; -------------------------------------------------------------- end Main Question: Implementation of moving average filters with application to discrete-time series.Consider the moving average filter given by: In Figure 1 we show the output time series yi[n], for i=1,...,4, produced by this filter when it is convolved with each of the five different periodic times series inputs xi[n], for i=1,...,4. In this figure, the inputs xi[n] are shown in blue, while the outputs yi[n] are shown in red, and it should be evident to you, by inspection, why we call such a filter a moving average filter: note how in Figure 1 all the outputs appear “smoother” than the inputs, in some sense. Indeed, averaging can be interpreted as a smoothing process. Please note that the outputs yi[n], for i=1,...,4, in Figure 1 are showing both the transient phase and the steady-state phase. Task 1 1. The first thing for you to do is to compile and simulate the given .asm template titled “template_for_moving_average_by_AC_Part_II.” While you do that, please note the following: a. The variable of interest in this template is, again, the register called value. b. Simulate the template as is (i.e., without making any changes) and note that the contents of value are exactly the values for time series x1[n] shown in Figure 1. 2. Go back to the template and locate the sections of code shown in Figures 2 and 3. 3. Consider Figures 2 and 3, and perform the following changes in the template: a. Corresponding to Figure 2, replace the literal 2 with the new literal 4. This new literal 4 is simply the period of the second time series x2[n], of period 4, shown in the code in Figure 3. b. Corresponding to Figure 3, comment out the following lines of code, which correspond to time series x1[n]: i. SimpleTable ; ---> period 2, ii. db 80,240 c. Corresponding to Figure 3, uncomment the following lines of code, which correspond to time series x2[n]: i. ;SimpleTable ; ---> period 4 ii. ;db 80,240,160,60 4. Simulate the code again, with the changes made in step 3, and note how the contents of register value change according to the time series x2[n], also shown in Figure 1. 5. Repeat step 3 above for each of the remaining time series in Figure 3 and note that the contents of value will vary according to the time series that you choose. All the available time series in the template are shown in the time domain in Figure 1 as xi[n], for i=1,...,4, and shown in code in Figure 3. Each time series has a different period, please verify this through simulations before moving on to the next task. Task 2 1. Having completed Task 1, please write the .asm code to implement the moving average filter y[n] specified above. a. Convolve your implemented filter with each of the time series xi[n], for i=1,...,4, in the template, one at a time, of course. i. Note that this Task is an extension of your work for Lab 5. ii. You must implement a linear memory buffer exactly like the one that you wrote for Lab 5. iii. There are many ways to perform this addition. Note that this adder/divider is not a difficult thing to do, but you really have to be clear on what is going on when you are trying to add four variables (two at a time), considering that each of these variables is 8 bits long. b. Verify that your filter was properly implemented by comparing your results with each output yi[n], for i=1,...,4, in Figure 1. In order to help you keep track of all the values, you should create a table for each pair xi[n] and yi[n] as shown in Table 1 for x1[n]. c. For this task, you should fill up the tables for each pair on your own, by hand, before implementing the filter. This is so that you know what outputs to expect (Hint: see Figure 1). Include all tables in your report.
Nov 14, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here