-
Notifications
You must be signed in to change notification settings - Fork 2
/
filterTest.m
86 lines (59 loc) · 1.3 KB
/
filterTest.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
clear
load bfDas.mat;
load Num1.mat;
Num = Num1;
data = bfDas(:, 128);
data = data';
fs = 40e6;
figure;
plot(data);
hold on
plot(abs(hilbert(data)), 'r')
t = 1/fs:1/fs:(length(Num))/fs;
fc = 4.0e6;
sinWavF = sin(2*pi*fc * t) .* Num;
cosWavF = cos(2*pi*fc * t) .* Num;
[dft, ang, frq] = spectrumAns(data, fs);
xq = filter(sinWavF, 1, [zeros(1, 5) data]);
xi = filter(cosWavF, 1, [zeros(1, 5) data]);
env = sqrt(xq.^2 + xi.^2) * 2;
hold on;
plot(env(length(Num) - 1:end), 'k');
[dftA, angA, frqA] = spectrumAns(1j * xq + xi, fs);
[dftC, angC, frqC] = spectrumAns(hilbert(data), fs);
figure;
plot(frq, dft);
hold on
plot(frqA, dftA, 'r');
hold on
plot(frqC, dftC, 'k');
[dftF, angF, frqF] = spectrumAns(1j * [sinWavF, zeros(1, 200)] + [cosWavF, zeros(1, 200)], fs);
hold on
plot(frqF, dftF);
ylim([-80, 0.5]);
data = data(1:30);
dataT = data(1:20);
tic;
for i = 1:800
env = hilbert(dataT);
end
disp(toc)
tic;
for i = 1:800
x1 = filter(cosWavF, 1, data);
y1 = filter(sinWavF, 1, data);
end
disp(toc)
tt = 1/fs: 1/fs: length(data)/fs;
sinW = sin(2 * pi * fc * tt);
cosW = cos(2 * pi * fc * tt);
tic;
for i = 1:800
dataX = sinW .* data;
dataY = cosW .* data;
x1 = filter(Num, 1, dataX);
y1 = filter(Num, 1, dataY);
end
disp(toc)
tones = ones(1, 30);
tfilt = filter(Num, 1, tones);