This commit is contained in:
Silas Oettinghaus
2023-05-15 15:55:16 +02:00
parent 55db794162
commit 0086346efd
6 changed files with 265 additions and 38 deletions

View File

@@ -12,7 +12,7 @@ classdef Filter
filtdegree
passband_ripple
stopband_ripple
fdac
fsamp
end
methods
@@ -22,7 +22,7 @@ classdef Filter
arguments
options.filterType = 1;
options.f_cutoff = 0;
options.fdac = 0;
options.fsamp = 0;
options.filtdegree = 3;
options.passband_ripple = 0.5;
options.stopband_ripple = 0.5;
@@ -31,12 +31,12 @@ classdef Filter
obj.filterType = options.filterType;
obj.f_cutoff = options.f_cutoff;
obj.filtdegree = options.filtdegree;
obj.passband_ripple = options.passband_ripple;
obj.stopband_ripple = options.stopband_ripple;
obj.fdac = options.fdac;
obj.fsamp = options.fsamp;
end
@@ -67,49 +67,49 @@ classdef Filter
% Bessel filter, impulse invariant transformed
[B, A] = besself(obj.filtdegree, 2*pi*obj.f_cutoff);
[B ,A] = impinvar(B,A,obj.fdac);
[B ,A] = impinvar(B,A,obj.fsamp);
case 2
% Bessel filter, impulse bilinear transformed
[Z, P, K] = besself(obj.filtdegree, 2*pi*obj.f_cutoff);
[Z ,P, K] = bilinear(Z,P,K,obj.fdac);
[Z ,P, K] = bilinear(Z,P,K,obj.fsamp);
[B ,A] = zp2tf(Z ,P ,K);
case 3
% Butterworth filter
if obj.lowpass == 1 %lowpass
[B, A] = butter(obj.filtdegree, obj.f_cutoff/(obj.fdac/2),'low');
[B, A] = butter(obj.filtdegree, obj.f_cutoff/(obj.fsamp/2),'low');
else % highpass
[B, A] = butter(obj.filtdegree, obj.f_cutoff/(obj.fdac/2),'high');
[B, A] = butter(obj.filtdegree, obj.f_cutoff/(obj.fsamp/2),'high');
end
case 4
% Chebyshev 1 filter
[B, A] = cheby1(obj.filtdegree,rp, obj.f_cutoff/(obj.fdac/2));
[B, A] = cheby1(obj.filtdegree,rp, obj.f_cutoff/(obj.fsamp/2));
case 5
% Chebyshev 2 filter
[B, A] = cheby2(obj.filtdegree,rs, obj.f_cutoff/(obj.fdac/2));
[B, A] = cheby2(obj.filtdegree,rs, obj.f_cutoff/(obj.fsamp/2));
case 6
% Elliptic filter
[B, A] = ellip(obj.filtdegree,rp,rs,obj.f_cutoff/(obj.fdac/2));
[B, A] = ellip(obj.filtdegree,rp,rs,obj.f_cutoff/(obj.fsamp/2));
case 7
% Hamming filter
g=(obj.filtdegree-1)/2;
wc=obj.f_cutoff/(obj.fdac/2);
wc=obj.f_cutoff/(obj.fsamp/2);
B = wc*sinc(wc*(-g:g)).*hamming(obj.filtdegree)';
A=1;
@@ -117,7 +117,7 @@ classdef Filter
% Raised Cosine filter
B = firrcos(obj.filtdegree,obj.f_cutoff,para.df,obj.fdac);
B = firrcos(obj.filtdegree,obj.f_cutoff,para.df,obj.fsamp);
A=1;
case 9
@@ -125,7 +125,7 @@ classdef Filter
% Sinc filter
g=(obj.filtdegree-1)/2;
wc=obj.f_cutoff/(obj.fdac/2);
wc=obj.f_cutoff/(obj.fsamp/2);
B = wc*sinc(wc*(-g:g));
A=1;