forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecimation.m
31 lines (28 loc) · 873 Bytes
/
decimation.m
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
function decimation
%program performs multi-stages of decimation on data in a user-specified data file
%enough data must be guaranteed when using a large overall decimation fator
clear all;
r = [2 2 3 2]; % decimation factor array for different stages
FIR = 0; % 1 - use FIR filter, 0 - use IIR filter
n = 0; % order of IIR filter or FIR filter length
% n=0 for 30 points FIR filter or 8th order Chebyshev type I LPF filter
in = fopen('decimation.dat','r') ;
[x,count] = fscanf(in,'%g',inf); % data to be decimated
y = x;
fclose(in);
for i=1:length(r)
if n==0 %decimating data use default filter
if FIR
y = decimate(y,r(i),'fir');
else
y = decimate(y,r(i));
end
else
if FIR
y = decimate(y,r(i),n,'fir');
else
y = decimate(y,r(i),n);
end
end
end
plot(1:count,x,1:prod(r):count,y(1:length(y)),'o');