210 likes | 322 Views
ECT 358. Lecture 14 Digital Signal Processing. A man is rich according to what he is, not according to what he has. There is that maketh himself rich, yet hath nothing: there is that maketh himself poor, yet hath great riches. Proverbs 13:7. Signals and Sampling. Analog Input
E N D
ECT 358 Lecture 14 Digital Signal Processing
A man is rich according to what he is, not according to what he has. There is that maketh himself rich, yet hath nothing: there is that maketh himself poor, yet hath great riches. Proverbs 13:7
Signals and Sampling • Analog Input • Discrete Time Samples • Manipulation of Numbers • Mostly zero • Has non-zero value only at the sample points • Output at sample points approximately equals the value of the continuous signal evaluated for the sample point
Discrete Linear System • Input is convolved with another function to produce an output
Difference Equation • Discrete data stream, x(n), is stored in a shift register • Each stage of the shift register corresponds to the delay operation • Contents of each stage multiplied by a distinct coefficient and summed • Output is fed back through a separate shift register with corresponding multiply and add operations
Finite Impulse Response Filters • If each of the b coefficients are zero, then • Represents a Finite Impulse Response (FIR) filter
Finite Impulse Response Filters • Operations are delay, multiply, and accumulate the result
A Simple FIR Filter • Moving Average Filter
Eight Point Moving Average Filter //MovAvg.v //A simple moving average filter to illustrate FIR filter implementation //Uses an 8 point filter //Assumes 8-bit samples module MovAvg(Y_out,temp, X_in, clk, reset); input [7:0] X_in; input clk, reset; output [7:0] Y_out; output [10:0] temp; reg [10:0] temp; reg [7:0] Y_out; reg [7:0] samples[0:6]; //reg [2:0] k; integer k;
Eight Point Moving Average Filter always @(posedge clk or posedge reset) if (reset) begin for(k = 0;k <= 6;k = k+1) begin samples[k] <= 0; Y_out <= 0; temp <= 0; end end else begin temp <= samples[0] + samples[1] + samples[2] + samples[3] + samples[4] + samples[5] + samples[6] + X_in; Y_out <= temp>>3; for(k=0; k < 6; k = k+1) samples[k] <= samples[k+1]; samples[6] <= X_in; end endmodule
Finite Impulse Response Filter //rect_prototype.v //a prototype rectangular digital filter example //fs = 1000 module rect_prototype(Y_out, X_in, clk, reset); input clk, reset; input [7:0] X_in; output [15:0] Y_out; reg [15:0] Y_out; reg [15:0] REG [0:20]; integer k;
Finite Impulse Response Filter always @(posedge clk or posedge reset) if (reset) for (k = 0; k <= 20; k = k+1) begin REG[k] <= 0; Y_out <= 0; end else begin Y_out <= (REG[0] + REG[20])* 32 //this behavior approach to multiply causes an LPM-MULT to be used //avoid by explicitly using power of 2 multiplies (shift) and add +(REG[1] + REG[19])* 25 -(REG[3] + REG[17])* 32 -(REG[4] + REG[16])* 53 -(-REG[5] + REG[15])* 45 +(REG[7] + REG[13])* 75 +(REG[8] + REG[12])* 159 +(REG[9] + REG[20])* 225 + REG[10]*250; for(k = 0; k<20; k = k+1) begin REG[k]<= REG[k+1]; REG[20]<=X_in; end end endmodule
Low Pass Filter Response //IIR_LP.v /* An infinite impulse response, digital low-pass filter based on a standard continuous time filter formulation. */ module IIR_LP(yn, xn, clk, reset); parameter width = 8; parameter order = 1; /*for this filter, there is one b coefficient that has the value 0.904. We multiply by 1000 to create an integer operation. This effectively moves the "binary" point 10 positions to the left. In order for the results to converge, we must compensate for this shift in both the input and the output data*/ parameter b = 10'd904; input [width-1:0] xn; input clk, reset; output [2*width-1:0] yn; reg [3*width:0]samples_out ; wire [3*width:0]Data_feedforward; wire [3*width:0] Data_feedback; //input shifted 10 positions to the left to line up with coefficient assign Data_feedforward = xn<<10; assign Data_feedback = samples_out*b ; //output shifted 10 positions to the right to compensate for scale assign yn = (Data_feedforward + Data_feedback)>>10; always @(posedge clk) if (reset) samples_out <= 0; else samples_out <= (Data_feedforward + Data_feedback)>>10; //delayed ouput shifted 10 positions to the right to compensate for scale endmodule