Error while executing the code using simulink
Show older comments
So, I have written the code for filtering multiple noises using wiener filter. I was implementing the same using the matlab function block in the simulink. I got this code through matlab only.
so in the lines:
xest=xest(N+1:end)
MSE = mean(ecg(N+1:end) - xest) .^2;
plot(x(N+1:end),xest,'k')
in these 3 lines, I'am getting an error saying size mismatch, (size[1x5000] ~= size[1x?])
The dimensions of xest is 1x9700
could someone resolve this problem as soon as possible please
function xest = fcn(noisy,ecg,N)
Fs = 500;
Ts = 1/Fs;
T=1;
x=0:Ts:10-Ts;
L = T .* Fs; % signal length
tt = (0:L-1)/Fs; % time vector
ff = (0:L-1)*Fs/L;
X = 1/N .* fft(noisy(1:N));
Y = 1/N .* fft(ecg(1:N));
X = X(:);
Y = Y(:);
Rxx = N .* real(ifft( X.* conj(X))); % Autocorrelation function
Rxy = N .* real(ifft( X.* conj(Y))); % Crosscorrelation function
Rxx = toeplitz(Rxx);
Rxy = Rxy';
B = Rxy / Rxx; B = B(:); % Wiener-Hopf eq. B = inv(Rxx) Rxy
xest = fftfilt(B,x);
xest = xest(N+1:end); %cut first N samples due to distorsion during filtering operation
MSE = mean(ecg(N+1:end) - xest) .^2; % mean squared error
figure(3)
subplot(211)
plot(x,noisy,'r'), hold on, plot(x,ecg,'k')
subplot(212)
plot(x(N+1:end),xest,'k')
end
Answers (0)
Categories
Find more on Get Started with DSP System Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!