fir filter implementation in octave without inbuilt function

510 views Asked by At

I want to make a FIR filter. I have an array of coefficients n2 and an array of data n1 but without using inbuilt function (fir) in octave. i am not sure what is the problem here.

I am getting an error while running this code. error: y(0): subscripts must be either integers 1 to (2^31)-1 or logicals error: called from fir1 at line 12 column 10

`n1=input('enter length of random sequence');     
 n2=input('enter length of filter');        
 for i=1:n1        
 x(i)=input('elements of x')        
 end            
 for i=1:n2       
 y(i)=input('elements of y')        
 end        
 c=zeros(1,(n1+n2));        
 for i=1:(n1+n2)    
 for j=1:n2    
     c(i)=c(i)+x(j)*y(i-j+1);    
 end    
 end        
 c`
1

There are 1 answers

0
remya On

thank you so much.. I figured it out.. I tried the following code for the problem.

clear all;                                   
%random input sequence of 1000 
random_i = randn(1,1000);

%filter coefficients of order 5
h =[1 0.5 0.25 0.125 0.0625] ;

l1=length(random_i);
l2=length(h);
length=l1+l2-1;

output_f=zeros(1,length);        
 %convolution 
 for i=1:length
 for j=1:length
   if ((i-j+1)<=l2 && j<=l1 && j<=i)
     output_f(i)=output_f(i)+random_i(j)*h(i-j+1);    
   endif
 end 
end