% wiener 1-D
clear
%
N=8;
n=0:1:N-1;
x=cos(((2*pi/N)*n+0*(pi/4))); % true input
xmean=[x(1)+x(8) x(1)+x(2) x(2)+x(3) x(3)+x(4) x(4)+x(5)];
xmean=[xmean x(5)+x(6) x(6)+x(7) x(7)+x(8)]/2; % blurred sig
X=fft(x); % dft true sig
H=fft([1 1]*0.5,N); % DFT of hd
%
rng('default'); % noise generation
Noise=0.1 * randn(1,N) % std 0.1, mean 0
Nd=fft(Noise);
y=xmean+Noise; % degrad sig +noise
Y=fft(y); %dft of degraded signal
%
A=conj(fft([0.5 0.5],N)) .*fft([0.5 0.5],N);
B=conj(fft(Noise,N)) .*fft(Noise,N);
C=conj(fft(x,N)) .*fft(x,N);
w=conj(fft([0.5 0.5],N))./(A + B./C) % Wiener filter
rs=real(ifft(fft(y) .* w)) % restored signal
sum((y-x).^2) % least squares error
sum((x-rs).^2) % least squares error

