Skip to content
Snippets Groups Projects
Commit e59b5b35 authored by Pepping's avatar Pepping
Browse files

Initial commit

parent b66bf739
No related branches found
No related tags found
No related merge requests found
% filename FIR_LPF_ApertifCF.m
% author R. de Wild
% project APERTIF_CF
% history 150129-150218,150319,150430,150512,150521,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% workspace initiation
clear all
close all
% preset FIR-filter parameters
M = 512 ; % # filter-coefficients (taps)
n = M -1 ; % # delay-elements
h_ix = 1 : 1 : M ; % coefficient-index
nbit = 15 ; % # bits/coefficient = 1 sign +('nbit'-1) mantissa
fs = 781250.0 ; % sampling clock = 800.0 MHz / 1024
f_nyq = fs/2 ; % Nyquist frequency
f_pb = 12000.0 ; % end of passband
% normalized frequency axis & normalized amplitude axis
w_pb = f_pb/f_nyq ;
r_sb = 10^(-3.0) ; % stopband ripple = -60.0 dB_W
r_pb = 10^(-0.025) ; % passband ripple = -0.5 dB_W
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compute M (= n+1) real-valued filter-coefficients
h = fircls1(n, w_pb, r_pb,r_sb) ;
% compute amplitude characteristic of h
hfs_abs = abs (fftshift(fft( h ,M))) ;
% compute M (= n+1) integer-valued filter-coefficients
hmax = max(h) ;
hq = double ( uencode(h,nbit,hmax,'signed') ) ;
% compute amplitude characteristic of hq
hqfs_abs = abs (fftshift (fft( hq )/M)) ;
% compute M (= n+1) 2's complement filter-coefficients
hq_str = dec2bin ( mod((hq),2^nbit) , nbit )
hq_bin = ( str2num(hq_str) )' ;
%whos
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% display FIR-filter parameters on screen:
sprintf ( [ ' f_pb = end of passband = %10.6e Hz \r' , ...
' fs/2 = nyquist rate = %10.6e Hz \n' , ...
' M = number of coefficients = %d \n' , ...
' nbit = number of bits/coefficient = %d ' ], ...
f_pb , f_nyq , M , nbit )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% write FIR-filter coefficients to file (formats=real/integer/hexadecimal):
% N.B. - read '.txt'-file with 'wordpad' !!!
file_name = ['FIR_LPF_ApertifCF.txt'] ;
FIRtable = [ h_ix ; h(h_ix) ; hq(h_ix) ; hq_bin(h_ix) ] ;
fid = fopen ( file_name , 'w' ) ;
fprintf ( fid ,'%d \t %14.10f \t %14.10f \t %X \n' , FIRtable ) ;
fclose ( fid ) ;
file_name = ['FIR_LPF_ApertifCF2.txt'] ;
FIRtable = [ hq(h_ix)] ;
fid = fopen ( file_name , 'w' ) ;
fprintf ( fid ,'%d \n' , FIRtable ) ;
fclose ( fid ) ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot frequency response of h on screen: log-amplitude characteristic
figure (1) ;
h_ixH = (M/2)+1 : 1 : M ;
plot ( h_ixH , 20.0 * log10 ( hfs_abs(h_ixH) ) ) ;
xlim ( [ (M/2)+1 M ] ) ;
grid on ;
zoom on ;
title( [ 'FIR filter: (log-)amplitude-spectrum --> ' , ...
'number of coefficients = ', num2str(M), ' ; ' , ...
'real-valued coefficients ; ' , ...
'sampling rate = ', num2str(fs), ' [Hz] ; ' , ...
'end of passband = ', num2str(f_pb), ' [Hz] ; ' ] ) ;
% plot frequency response of hq on screen: log-amplitude characteristic
figure (2) ;
h_ixH = (M/2)+1 : 1 : M ;
plot ( h_ixH , 20.0 * log10 ( hqfs_abs(h_ixH) ) ) ;
xlim ( [ (M/2)+1 M ] ) ;
grid on ;
zoom on ;
title( [ 'FIR filter: (log-)amplitude-spectrum --> ' , ...
'number of coefficients = ', num2str(M), ' ; ' , ...
'number of bits/coefficient = ', num2str(nbit), ' ; ' , ...
'sampling rate = ', num2str(fs), ' [Hz] ; ' , ...
'end of passband = ', num2str(f_pb), ' [Hz] ; ' ] ) ;
figure (3) ;
h_ixH = 1 : 1 : M ;
plot ( h_ixH , hq ) ;
xlim ( [ 1 M ] ) ;
grid on ;
zoom on ;
title( [ 'FIR filter: Filtercoefficients --> ' , ...
'number of coefficients = ', num2str(M), ' ; ' , ...
'number of bits/coefficient = ', num2str(nbit), ' ; ' , ...
'sampling rate = ', num2str(fs), ' [Hz] ; ' , ...
'end of passband = ', num2str(f_pb), ' [Hz] ; ' ] ) ;
-257
-31
3
-10
-6
2
5
11
20
27
36
47
59
71
85
100
116
133
150
168
187
206
226
245
266
285
305
324
343
361
378
394
408
421
432
441
449
454
456
456
454
449
440
429
416
398
379
356
330
301
270
236
199
161
120
77
33
-12
-58
-105
-152
-199
-246
-291
-336
-379
-420
-458
-494
-527
-556
-581
-602
-619
-631
-639
-641
-638
-630
-616
-597
-573
-543
-508
-468
-423
-374
-320
-263
-202
-138
-72
-3
67
138
209
280
350
419
485
548
608
664
715
761
801
835
862
882
895
900
897
886
866
838
803
759
707
648
581
508
429
344
254
159
61
-40
-142
-246
-350
-452
-553
-652
-746
-836
-920
-997
-1067
-1129
-1181
-1224
-1257
-1278
-1288
-1286
-1273
-1247
-1209
-1158
-1095
-1021
-935
-839
-732
-615
-490
-357
-217
-72
78
231
385
540
694
846
993
1136
1271
1397
1514
1620
1713
1793
1857
1906
1938
1953
1949
1926
1884
1823
1743
1643
1525
1388
1234
1062
875
673
458
231
-6
-251
-502
-757
-1014
-1271
-1525
-1774
-2015
-2246
-2465
-2668
-2854
-3020
-3163
-3282
-3374
-3437
-3470
-3470
-3436
-3368
-3263
-3121
-2941
-2722
-2466
-2171
-1838
-1467
-1060
-618
-141
368
908
1476
2070
2687
3326
3982
4653
5336
6027
6722
7419
8113
8801
9479
10144
10791
11418
12021
12597
13142
13653
14128
14563
14957
15306
15609
15865
16071
16227
16331
16383
16383
16331
16227
16071
15865
15609
15306
14957
14563
14128
13653
13142
12597
12021
11418
10791
10144
9479
8801
8113
7419
6722
6027
5336
4653
3982
3326
2687
2070
1476
908
368
-141
-618
-1060
-1467
-1838
-2171
-2466
-2722
-2941
-3121
-3263
-3368
-3436
-3470
-3470
-3437
-3374
-3282
-3163
-3020
-2854
-2668
-2465
-2246
-2015
-1774
-1525
-1271
-1014
-757
-502
-251
-6
231
458
673
875
1062
1234
1388
1525
1643
1743
1823
1884
1926
1949
1953
1938
1906
1857
1793
1713
1620
1514
1397
1271
1136
993
846
694
540
385
231
78
-72
-217
-357
-490
-615
-732
-839
-935
-1021
-1095
-1158
-1209
-1247
-1273
-1286
-1288
-1278
-1257
-1224
-1181
-1129
-1067
-997
-920
-836
-746
-652
-553
-452
-350
-246
-142
-40
61
159
254
344
429
508
581
648
707
759
803
838
866
886
897
900
895
882
862
835
801
761
715
664
608
548
485
419
350
280
209
138
67
-3
-72
-138
-202
-263
-320
-374
-423
-468
-508
-543
-573
-597
-616
-630
-638
-641
-639
-631
-619
-602
-581
-556
-527
-494
-458
-420
-379
-336
-291
-246
-199
-152
-105
-58
-12
33
77
120
161
199
236
270
301
330
356
379
398
416
429
440
449
454
456
456
454
449
441
432
421
408
394
378
361
343
324
305
285
266
245
226
206
187
168
150
133
116
100
85
71
59
47
36
27
20
11
5
2
-6
-10
3
-31
-257
-5
-1
0
-1
-1
0
0
0
0
0
0
0
0
1
1
1
1
2
2
2
2
3
3
3
4
4
4
5
5
5
5
6
6
6
6
6
7
7
7
7
7
7
6
6
6
6
5
5
5
4
4
3
3
2
1
1
0
-1
-1
-2
-3
-4
-4
-5
-6
-6
-7
-8
-8
-9
-9
-10
-10
-10
-10
-10
-11
-10
-10
-10
-10
-9
-9
-8
-8
-7
-6
-5
-5
-4
-3
-2
-1
1
2
3
4
5
6
7
8
9
10
11
11
12
13
13
13
13
14
14
13
13
13
12
11
11
10
9
7
6
5
3
2
0
-1
-3
-4
-6
-8
-9
-11
-12
-14
-15
-16
-17
-18
-19
-20
-20
-20
-21
-21
-20
-20
-19
-19
-18
-16
-15
-14
-12
-10
-8
-6
-4
-2
1
3
6
8
10
13
15
17
19
21
23
25
26
28
29
29
30
30
30
30
29
28
27
25
23
21
19
16
13
10
7
3
-1
-4
-8
-12
-16
-20
-24
-28
-32
-36
-39
-42
-45
-48
-50
-52
-53
-54
-55
-55
-54
-53
-51
-49
-46
-43
-39
-34
-29
-23
-17
-10
-3
5
14
23
32
41
51
62
72
83
94
105
115
126
137
148
158
168
178
187
196
205
213
220
227
233
239
243
247
251
253
255
255
255
255
253
251
247
243
239
233
227
220
213
205
196
187
178
168
158
148
137
126
115
105
94
83
72
62
51
41
32
23
14
5
-3
-10
-17
-23
-29
-34
-39
-43
-46
-49
-51
-53
-54
-55
-55
-54
-53
-52
-50
-48
-45
-42
-39
-36
-32
-28
-24
-20
-16
-12
-8
-4
-1
3
7
10
13
16
19
21
23
25
27
28
29
30
30
30
30
29
29
28
26
25
23
21
19
17
15
13
10
8
6
3
1
-2
-4
-6
-8
-10
-12
-14
-15
-16
-18
-19
-19
-20
-20
-21
-21
-20
-20
-20
-19
-18
-17
-16
-15
-14
-12
-11
-9
-8
-6
-4
-3
-1
0
2
3
5
6
7
9
10
11
11
12
13
13
13
14
14
13
13
13
13
12
11
11
10
9
8
7
6
5
4
3
2
1
-1
-2
-3
-4
-5
-5
-6
-7
-8
-8
-9
-9
-10
-10
-10
-10
-11
-10
-10
-10
-10
-10
-9
-9
-8
-8
-7
-6
-6
-5
-4
-4
-3
-2
-1
-1
0
1
1
2
3
3
4
4
5
5
5
6
6
6
6
7
7
7
7
7
7
6
6
6
6
6
5
5
5
5
4
4
4
3
3
3
2
2
2
2
1
1
1
1
0
0
0
0
0
0
0
0
-1
-1
0
-1
-5
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment