OpenCores
URL https://opencores.org/ocsvn/wdsp/wdsp/trunk

Subversion Repositories wdsp

[/] [wdsp/] [trunk/] [sw/] [matlab-scripts/] [fir/] [gen_coeffs.m] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 parrado
%Header file generation for Wishbone compliant FIR Core test
2
 
3
 
4
%Cleans work environment
5
clc;
6
clear all;
7
close all;
8
 
9
 
10
 
11
%Low-pass filter design
12
%Cut-off frequencies
13
fs=8000;
14
fc1=1500;
15
fc2=2000;
16
 
17
%Length of impulse response
18
Nh=50;
19
order=Nh-1;
20
 
21
 
22
%Designs filter
23
hn = firpm(order,[0 fc1 fc2 fs/2]/(fs/2),[1 1 0 0]);
24
 
25
%Bits to use for each coefficient
26
Nbits=16;
27
 
28
%Fractional part
29
Q=floor(Nbits-1-log2(max(abs(hn))))-1;
30
 
31
%Quantized impulse response
32
hn_Q=(round(hn*2^Q));
33
 
34
%Header file generation
35
handle = fopen('../../FIR50/coefs.h', 'wt');
36
fprintf(handle, '/*Impulse response for FIR filter automatically generated header file*/\n');
37
fprintf(handle, '/*M.Eng. Alexander López Parrado*/\n\n');
38
fprintf(handle, '#include <stdint.h>\n');
39
fprintf(handle, '/*Number of coeffcients*/\n');
40
fprintf(handle, '#define Nh %d\n\n',Nh);
41
fprintf(handle, '/*Number of bits in fractional part of coeffcients*/\n');
42
fprintf(handle, '/*Fixed point format with %d bits ([%d].[%d])*/\n',Nbits,Nbits-Q,Q);
43
fprintf(handle, '#define Q %d\n\n',Q);
44
 
45
fprintf(handle, '/*Filter Coefficients */');
46
fprintf(handle, '\nconst int16_t hn[Nh] = {\n');
47
 
48
hn_printf= [hn_Q; hn];
49
 
50
fprintf(handle, '%d, //%f\n',hn_printf);
51
 
52
fprintf(handle, '};\n');
53
fclose(handle);
54
 
55
 
56
 
57
 
58
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.