Comparing Naive Inverse Filter to Wiener Filter for Deconvolution in Matlab

廉价感情. 提交于 2021-02-20 19:34:04

问题


I am currently trying to compare a simple inverse filter to the wiener filter for deconvolution using matlab. My starting signal is exp(-t^2) and this is to be convolved with a rect that is nonzero for times -.5 to .5. I am introducing noise with amplitude in the range -.5 to .5.

Defining my time domain to frequency domain mapping:

f = exp(-t^2) => F

s = rect => R

c = f*s => C

r = noise (see above) => R

with noise c becomes: c = f*s + n => C = FxS + N

For the first approach I am simply taking the FT of c and dividing it by the FT of f and then doing an inverse FT. This is amounts to s = (approx.) ifft((FxS + N)/F).

For the second approach I am taking the wiener filter, W, and multiplying it against C/R and then doing an inverse FT. This amounts to S = (approx.) ifft(CxW/R).

The wiener filter is W = mag_squared(FxS)/(mag_squared(FxS) + mag_squared(N)).

I have used '*' to mean convolution and 'x' to mean multiplication.

I am trying to compare the two deconvolutions of the rect over the time interval -3 to 3. Right now, my resulting graphs of the deconvolved rect look nothing like the original.
Could someone point me in the right direction as to what I'm doing to wrong? I have tried using ifftshift and different scalings in many different orderings but nothing seems to work.

Thanks

My matlab code is below:

%%using simple inverse filter
dt = 1/1000;
t = linspace(-3,3,1/dt); %time
s = zeros(1,length(t)); 
s(t>=-0.5 & t<=0.5) = 1; %rect
f = exp(-(t.^2)); %function
r = -.5 + rand(1,length(t)); %noise

S = fft(s);
F = fft(f);
R = fft(r);
C = F.*S + R;
S_temp = C./F;
s_recovered_1 = real(ifft(S_temp));  %correct?...works for signal without R (noise)

figure();
plot(t,s + r);
title('rect plus noise');

figure();
hold on;
plot(t,s,'r');
plot(t,f,'b');
legend('rect input','function');
title('inpute rect and exponential functions');
hold off;

figure();
plot(t,s_recovered_1,'black');
legend('recovered rect');
title('recovered rect using naive filter');


%% using wiener filter
N = length(s);
I_mag = abs(I).^2;
R_mag = abs(R).^2;
W = I_mag./(I_mag + R_mag);
S_temp = (C.*W)./F;
s_recovered_2 = abs(ifft(S_temp));  

figure();
freq = -fs/2:fs/N:fs/2 - fs/N;
hold on;
plot(freq,10*log10(I_mag),'r');
plot(freq,10*log10(R_mag),'b');
grid on
legend('I_mag','R_mag');
title('Periodogram Using FFT')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)')

figure();
plot(t,s_recovered_2);
legend('recovered rect');
title('recovered rect using wiener filter');

回答1:


So it turns out that I was dividing by the wrong denominator when calculating the Wiener Filter. I also now calculate the |...|^2 (power spectral density) of each term in the Wiener Filter using the straightforward abs(...)^2 way. The code above reflects these changes. Hope this is helpful to any noobs like myself :)



来源:https://stackoverflow.com/questions/26313129/comparing-naive-inverse-filter-to-wiener-filter-for-deconvolution-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!