aboutsummaryrefslogtreecommitdiff
path: root/octave/make_ssbfilt.m
blob: bcd00f10dc5628d3087922b18f08cc2dce147bf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
% make_ssbfilt.m
% David Rowe May 2015
%
% Creates low pass filter coeff used to implement a SSB filter in ch

graphics_toolkit ("gnuplot");

ssbfilt_n = 100;
ssbfilt_bw = 2400;
ssbfilt_centre = 1500;
Fs = 8000;

ssbfilt_coeff  = sbfilt_coeff = fir1(ssbfilt_n, ssbfilt_bw/Fs);

figure(1)
clf;
h = freqz(ssbfilt_coeff,1,Fs/2);
plot(20*log10(abs(h)))
grid minor

% save coeffs to a C header file

f=fopen("../src/ssbfilt_coeff.h","wt");
fprintf(f,"/* %d Hz LPF FIR filter coeffs */\n", ssbfilt_bw);
fprintf(f,"/* Generated by make_ssbfilt Octave script */\n");

fprintf(f,"\n#define SSBFILT_N %d\n\n", ssbfilt_n);
fprintf(f,"\n#define SSBFILT_CENTRE %d\n\n", ssbfilt_centre);

fprintf(f,"float ssbfilt_coeff[]={\n");
for r=1:ssbfilt_n
  if r < ssbfilt_n
    fprintf(f, "  %f,\n",  ssbfilt_coeff(r));
  else
    fprintf(f, "  %f\n};", ssbfilt_coeff(r));
  end
end

fclose(f);