Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21608 Discussions

vhdl problem for iir filter

Altera_Forum
Honored Contributor II
1,535 Views

hi: guys  

i have a problem makes me crazy.  

how to use vhdl codes to implement iir filter  

y(n)= 2cos(w)*y(n-1) - y(n-2)  

and the initial conditions is y(-1)=sin(w),y(-2)=sin(2w).  

which means i need output this filter every cycle calculation like following y(0),y(1)....  

y(0)=2cos(w)*y(-1)-y(-2);  

y(1)=2cos(w)*y(0)-y(-1);  

...  

i use a mac and a rounding operation to do it.  

but its not work like i describe above.  

how should i do. Am i need plus some selfcycle computation on testbench or on original filter codes. And how to plus it into this codes.  

 

thanks
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
629 Views

Hello, 

 

I can't indentify a filter, cause there is no signal input. If you are actually trying to design an oscillator, then you should probably choose a structure less sensitive to rounding errors or use an NCO instead. 

 

But apart from this consideration, the shown IIR structure can surely be synthesized in VHDL. I understand, that cos(w) is a constant that either can be calculated at compile time or loaded as a parameter (which is big difference for FPGA implementation), the same with the said initial values. Next you have to define a numeric format (probably signed) and a resolution. Then the algorithm can be build from a multiplier and a substractor megafunction or infered from HDL. Two registers are needed to store previous y(n).  

 

Basic operation can be evaluated also in a spreadsheet tool, e. g. Excel to study rounding error effects with different numerial resolution. 

 

Regards, 

 

Frank
0 Kudos
Altera_Forum
Honored Contributor II
629 Views

to Frank: 

thank you pay attentation to my problem. 

yes, as you said i am doing a digital oscillator utilized a iir structure.  

you said i need two registers to store previous y(n). i show u my codes as attached, may be when u see my codes you can understand my problem totally. 

Please check out my codes, and give me some advise agian. 

Thank you
0 Kudos
Altera_Forum
Honored Contributor II
629 Views

the archive seems to be broken. Can't open it.

0 Kudos
Altera_Forum
Honored Contributor II
629 Views

sorry to Frank 

the forum can not attached the .rar files, so please show me your email address, i send it to you directly.
0 Kudos
Reply