FIR filters: a simple but slow C implementation (003)

preview_player
Показать описание
An FIR filter can be implemented with the help of an array which acts as a delay line. Every time step the data is shifted through the delay line and then accumulated as a weighted sum.
Рекомендации по теме
Комментарии
Автор

If I want to compute the output of exacly one input at a certain time, do I still need the inputs before my specific input, and do i still need to use all of the filter coeffs.? Or if for example my filter has 50taps and my input is an array with lenght=50, if I want to calculate only the output of array[49], do i still need all 49 filter coeffs.?

veqazbaby
Автор

What is the appropriate filter for speech signals?

daliatariq
Автор

i think for the 2nd loop we cannot start from the i=0. If we start from i=0 then for the updated co efficient say(C0) will be added to the array and that will make some garbage value while computing the output. Here i am giving my code. Please check whether you are getting any error or not





#include <stdio.h>
#include <conio.h>
main()
{
int buffer[]={10, 20, 30, 40, 50};// input buffer in a from of array
int C[]={1, 2, 3, 4, 5}; // previous co-efficient
int n=5; // number of coefficient
int i, j; // for loop
int result=0; //adding result=0 for not to get any garbage value

for(j=n-1;j>0;j--)
{
buffer[j]=buffer[j-1];
printf("\t%d", buffer[j]);
}
printf("\n");

for(i=1;i<n;i++)
{
printf("\t%d", C[i]);
result=result+C[i]*buffer[i];
}
printf("\n");
printf("the result is %d", result);
getch();
}

s.m.ehsanulamin
Автор

and how would you implement a moving average in C code?

Eldg
Автор

here i have attached another solution for linear shifting of a FIR filter. Please check this




#include <stdio.h>
#include <conio.h>
main()
{
int buffer[]={10, 20, 30, 40, 50};
int i, n=5, t[n], k=0, j;
int result=0;
int C[]={1, 2, 3, 4, 5};

for(j=1;j<n;j++)
{
t[k+1]=buffer[j-1]; //temporary storage where data can be stored

printf("\nthe buffers are");
printf("\n\t%d", t[k+1]); //print out the updated buffer in form of array in a new array
k++;
}
printf("\n");
for(i=0;i<n;i++)
{
printf("\nthe co-efficients");
printf("\n\t%d", C[i]);
}
for(i=1;i<n;i++) //since the buffer from the negative portion is out of bound thats for the reason we will start from i=1
{
result+=C[i]*t[i];
printf("\n");
}
printf("the result is %d", result);
getch();
}

s.m.ehsanulamin