April 7th, 2014, 09:52 AM  #1 
Senior Member Joined: Apr 2014 From: UK Posts: 778 Thanks: 292  FIR frequency response
I finally thought it would be a good idea to take a look at FIR filters and have started looking at the math for it. I can generate coefficients for the filter, they match an example I found on the web: FIR Filters by Windowing  The Lab Book Pages My problem is, how do I view the frequency response? None of the math I've tried gives me a graph that looks like the example. I seem to have lost the math I used, it basically ran a bunch of cosines through the tap array, something like freq[m] = sumof [cos (2 * Pi * h(n) * m)] for n= 0 to 20 repeating for m=0 to 20 Where h(n) is the FIR tap array Any idea what I'm supposed to do? 
April 8th, 2014, 01:55 AM  #2 
Senior Member Joined: Apr 2014 From: UK Posts: 778 Thanks: 292 
I think I finally have it! given that the example only uses 21 taps, having a frequency plot with only 21 points simply doesn't show enough information, So I multiplied the number of output samples in the frequency by a 'factor'. In case anyone is interested, here's my Excel VBA code to solve it: factor = 10 For j = 0 To (M / 2) * factor Rtot = 0 Itot = 0 For n = 0 To M Am = Worksheets("Sheet1").Cells(n + 1, 1) Re = Am * Cos(2 * Pi * j * n / Taps / factor) Im = Am * Sin(2 * Pi * j * n / Taps / factor) Rtot = Rtot + Re Itot = Itot + Im Next tot = ((Rtot ^ 2) + (Itot ^ 2)) ^ 0.5 Worksheets("Sheet1").Cells(j + 1, 3) = 20 * Log(tot) Next Taps is 21 and M is Taps1 (as per the example). the tap values are in "Sheet1" column A, output is "Sheet1" column C 
April 9th, 2014, 12:50 AM  #3 
Senior Member Joined: Apr 2014 From: UK Posts: 778 Thanks: 292 
Hmmm, although it gives me the right general shape, the amplitudes are off. It looks fine up until the cutoff frequency, it's a little too steep, the first 'hump' is at 50dB instead of about 20dB as per the graph in the example. I believe I've found a small error, in my Cos and Sin maths, Taps should be M, giving: Re = Am * Cos(2 * Pi * j * n / M / factor) Im = Am * Sin(2 * Pi * j * n / M / factor) The amplitude graph (an array of 'tot') looks the same as the example, but my dB graph doesn't [ 20*Log(tot) ] Anyone ideas? 
April 15th, 2014, 06:49 PM  #4 
Senior Member Joined: Jul 2012 From: DFW Area Posts: 603 Thanks: 83 Math Focus: Electrical Engineering Applications 
Hi weirddave, I think that Log() in VBA is the natural log. When I used the natural log instead of the common log in my simulation, the first hump was also around 50 dB. If you divide by Log(10) does it look right? Also, in your equation for the imaginary term, the minus sign disappeared. For the magnitude this does not matter, but it reverses the phase. 
April 16th, 2014, 12:04 AM  #5 
Senior Member Joined: Apr 2014 From: UK Posts: 778 Thanks: 292 
It does look like the minus sign disappeared, what I didn't mention was that when I changed those equations, I also moved the minus: Itot = Itot  Im Just divided by log(10), brilliant That's done the trick! Woohoo! 

Tags 
fir, frequency, response 
Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Impulse response from data  Jannamanus  Linear Algebra  0  February 19th, 2014 10:39 AM 
Help understanding frequency response for steadysystems  sydfremmer  Complex Analysis  11  November 17th, 2012 08:48 PM 
Help finding the BEST RESPONSE FUNCTIONS  LeeNoob  Economics  0  November 10th, 2011 01:30 PM 
Warranties and finding best response function  princessanna57  Economics  1  May 22nd, 2010 09:31 PM 
Response  MyNameIsVu  New Users  7  May 26th, 2009 03:14 AM 