"Wayne King" <wmki...@gmail.com> wrote in message <icg6m1$sff$1...@fred.mathworks.com>...how the transients are handled in MATLAB code and translate that to C.
"andreasem Seminatore" <Antonio.S...@ansaldo-sts.com> wrote in message <icg5s5$8ci$1...@fred.mathworks.com>...
Hi All,
I'm trying to implement a C program that emulate the filtfilt() function. I wrote a code for filter() function as you can look in the bottom code sequence.
After filtering in the forward direction, the filtered sequence is then reversed and run back through the filter (filter twice).
//IIF Filter 3° Order
static void iir3f(double *input,double *output, int size, double *A, double *B,double gain) {
printf("\nLPF3 F %d\n",sizeof(double)*size);
int i;
for(i=0;i<size;i++)
{
in[0] = in[1];
in[1] = in[2];
in[2] = input[i];
// Shift previous outputs and calculate new output
out[0] = out[1];
out[1] = out[2];
out[2] = B[0] * in[2] + B[1] * in[1] + B[2] * in[0] - A[1] * out[1] - A[2] * out[0];
output[i]=out[2];
// Shift previous outputs and calculate new output
tmp = A[3] * previous_out + (output[i] + previous_in);
previous_out = tmp;
previous_in = output[i];
output[i]=tmp*gain;
}
}
The problem is the presence of an initail and final transient. I know that this problem can be solved using initial condition but, I do not know how this can be done.
Thank's in advance for any contibution that you'll give me
Andrea
Hi Andrea, If you have the Signal Processing Toolbox, you can look at the MATLAB code for filtfilt(). That is one of the nice things about MATLAB, the implementation is usually open for you to see. That is absolutely true for filtfilt(). You can see
Hey Andrea,WayneThank's Wayne,
I have already looked the file filtfilt.m
The file shows you how the initial conditions are calculated, then these values are provided to Matlab filter() function.
The implementation of filter() function is hide.
Essentially I know how calculate the initial condition's but I don't know how filter use these values.
I have implemented filter function without initial conditions...
On Tuesday, November 23, 2010 at 5:18:03 AM UTC-6, andreasem Seminatore wrote:see how the transients are handled in MATLAB code and translate that to C.
"Wayne King" <wmki...@gmail.com> wrote in message <icg6m1$sff$1...@fred.mathworks.com>...
"andreasem Seminatore" <Antonio.S...@ansaldo-sts.com> wrote in message <icg5s5$8ci$1...@fred.mathworks.com>...
Hi All,
I'm trying to implement a C program that emulate the filtfilt() function.
I wrote a code for filter() function as you can look in the bottom code sequence.
After filtering in the forward direction, the filtered sequence is then reversed and run back through the filter (filter twice).
//IIF Filter 3° Order
static void iir3f(double *input,double *output, int size, double *A, double *B,double gain) {
printf("\nLPF3 F %d\n",sizeof(double)*size);
int i;
for(i=0;i<size;i++)
{
in[0] = in[1];
in[1] = in[2];
in[2] = input[i];
// Shift previous outputs and calculate new output
out[0] = out[1];
out[1] = out[2];
out[2] = B[0] * in[2] + B[1] * in[1] + B[2] * in[0] - A[1] * out[1] - A[2] * out[0];
output[i]=out[2];
// Shift previous outputs and calculate new output
tmp = A[3] * previous_out + (output[i] + previous_in);
previous_out = tmp;
previous_in = output[i];
output[i]=tmp*gain;
}
}
The problem is the presence of an initail and final transient. I know that this problem can be solved using initial condition but, I do not know how this can be done.
Thank's in advance for any contibution that you'll give me
Andrea
Hi Andrea, If you have the Signal Processing Toolbox, you can look at the MATLAB code for filtfilt(). That is one of the nice things about MATLAB, the implementation is usually open for you to see. That is absolutely true for filtfilt(). You can
https://blog.fearcat.in/a?ID=01550-c703f0dc-0af2-4066-a1b9-03ce13146e75Hey Andrea,WayneThank's Wayne,
I have already looked the file filtfilt.m
The file shows you how the initial conditions are calculated, then these values are provided to Matlab filter() function.
The implementation of filter() function is hide.
Essentially I know how calculate the initial condition's but I don't know how filter use these values.
I have implemented filter function without initial conditions...
Did you ever end up solving your problem? I'm having the same problem with translating filtfilt where the inital and final transients are causing problems. Please, let me know if you found any good conversion online or translation of the code.
Best,
Matt
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 292 |
Nodes: | 16 (2 / 14) |
Uptime: | 178:57:14 |
Calls: | 6,616 |
Calls today: | 3 |
Files: | 12,165 |
Messages: | 5,313,939 |