我有一个大小为120x1
的信号。我正在尝试创建一维高斯滤波器(G
),这样当它乘以信号时,它会生成滤波后的信号。
sFilt = G*s
我知道MATLAB filter
函数可以通过以下方式应用此转换:
i = -30:30;
sigma = 2;
gaussFilter = exp(- i.^ 2 / (2 * sigma ^ 2));
gaussFilter = gaussFilter / sum (gaussFilter); % normalize
s = rand(120,1); % Example signal
sFilt = filter(gaussFilter,1, s); % Example filtered signal
但是,我希望自己找到内核矩阵,而不是MATLAB在内部找到并将其应用于我的信号。
这是我想要找到G
的信号。
s = [...
0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.930556000000000 3.38767207896461 2.96157398017693 -0.333333000000000 1.60762896805897 2.00694000000000 2.00694000000000 2.00694000000000 1.28472000000000 -1.43744631449631 0.944444000000000 2.59392295081968 2.99306000000000 2.99306000000000 2.99306000000000 2.99306000000000 2.99306000000000 2.99306000000000 2.99306000000000 2.02922488524590 -0.812570065573777 -1.18993444717445 -0.782122839475842 0.640152000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 2.01873464373465 4.49027190008191 5.18750000000000 5.18750000000000 5.18750000000000 5.18750000000000 5.18750000000000 4.59722000000000 2.59722000000000 3.97561321867322 3.21314756756758 0.604167000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.111111000000000 0.458646085995084 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000
]';
这是带噪声的滤波信号。
sFilt = [...
0.0138889000000000 0.00208355909090909 -0.00329849545454587 0.201389000000000 0.861111500000000 1.86806000000000 2.44947936559843 2.52500275098103 2.15972000000000 2.04861000000000 2.14807844644317 2.16668303352412 1.78457304987735 1.27778000000000 1.00173350000000 1.57634828431373 2.33333000000000 3.21248677841374 3.55556000000000 3.64930500000000 3.71804717320261 3.81944000000000 3.49947244281046 2.76389000000000 1.65451500000000 0.470087078495503 -0.229167000000000 -0.208333000000000 0.354167000000000 0.789952043336059 1.08820161079313 1.19444000000000 1.19444000000000 1.07082559280458 1.09288587898610 1.19444000000000 1.20139000000000 1.23611000000000 1.45729755519215 2.02778000000000 3.14999395748160 4.65278000000000 5.78193152902698 6.30624161896975 6.45139000000000 6.34444931316435 5.92361000000000 5.44723022076860 4.78127380212592 4.18750000000000 3.06944000000000 1.72222000000000 0.791893542109568 0.312170886345054 0.0555556000000000 0.00694444000000000 0.0482593386437905 0.0524382556009807 -0.0647580647058824 -0.0694444000000000 0.0486111000000000 0.0249897492232223 0.0356016021241839 0.256944000000000 0.361111000000000 0.573964112019624 0.681776461161079 0.674996493049878 0.583855436631235 0.625000000000000 0.701389000000000 0.701389000000000 0.673611000000000 0.729167000000000 0.701389000000000 0.659722000000000 0.583333000000000 0.645833000000000 0.687500000000000 0.701389000000000 0.625000000000000 0.625000000000000 0.701389000000000 0.701389000000000 0.629343798855273 0.583333000000000 0.625000000000000 0.645833000000000 0.631944000000000 0.460070669664759 0.665622201962387 0.527778000000000 0.562500000000000 0.520833000000000 0.562500000000000 0.541667000000000 0.645833000000000 0.708333000000000 0.581075065359477 0.579855317512275 0.548611000000000 0.666667000000000 0.548611000000000 0.618056000000000 0.576389000000000 0.590278000000000 0.645833000000000 0.666667000000000 0.554531401639344 0.548611000000000 0.576389000000000 0.583333000000000 0.656560276422764 0.584357622950820 0.559938565573770 0.465278000000000 0.583333000000000 0.659722000000000 0.687500000000000 0.673611000000000
]';
我尝试使用以下代码来获取G
,但它不会生成正确的过滤信号:
G = zeros(180); % Zero padding G
i = -30:30;
sigma = 2;
gaussFilter = exp(- i.^ 2 / (2 * sigma ^ 2));
gaussFilter = gaussFilter / sum (gaussFilter); % normalize
for i = 31 : 150
G(i, i-30:i+30) = gaussFilter;
end
G = G(31:150,31:150); % Truncate to size 120x120
可以看出,无论噪音如何,G*s
都与sFilt
不同。我的目标是能够找到G
,G*s = sFilt
,无论噪音如何,滤波信号的幅度大致相同。
我是否也知道我创建G
的方式是否正确?如果没有,我应该如何为信号G
构建s
?给定s
和sFilt
,找到G = sFilt * pinv(s)
是否正确,我害怕得到奇异矩阵?
答案 0 :(得分:1)
我认为你应该写错字,因为我获得了两种方法完全相同的结果:
s = [...
0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.930556000000000 3.38767207896461 2.96157398017693 -0.333333000000000 1.60762896805897 2.00694000000000 2.00694000000000 2.00694000000000 1.28472000000000 -1.43744631449631 0.944444000000000 2.59392295081968 2.99306000000000 2.99306000000000 2.99306000000000 2.99306000000000 2.99306000000000 2.99306000000000 2.99306000000000 2.02922488524590 -0.812570065573777 -1.18993444717445 -0.782122839475842 0.640152000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 0.909722000000000 2.01873464373465 4.49027190008191 5.18750000000000 5.18750000000000 5.18750000000000 5.18750000000000 5.18750000000000 4.59722000000000 2.59722000000000 3.97561321867322 3.21314756756758 0.604167000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.00694444000000000 0.111111000000000 0.458646085995084 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000 0.506944000000000
];
i = -30:30;
sigma = 2;
gaussFilter = exp(- i.^ 2 / (2 * sigma ^ 2));
gaussFilter = gaussFilter / sum (gaussFilter); % normalize
sFilt = filter(gaussFilter,1, s); % Example filtered signal
G = zeros(180); % Zero padding G
for i = 31 : 150
G(i, i-30:i+30) = gaussFilter;
end
G = G(31:150,31:150); % Truncate to size 120x120
figure
hold on
plot(s)
plot(sFilt(31:end))
plot(G*s')