Skip to main content

Wiener Filter in MATLAB

 

MATLAB Code 

% Wiener Filter Based on Wiener-Hopf Equation
% This script demonstrates how to apply the Wiener filter to recover
% a reference signal from a noisy signal using the Wiener-Hopf equation.
% The filter minimizes the mean squared error between the noisy signal and the reference signal.

clear; close all; clc;

% Signal Parameters
fs = 4000; % Sampling frequency (Hz)
T = 1; % Total recording time (seconds)
L = T * fs; % Signal length (samples)
tt = (0:L-1) / fs; % Time vector
ff = (0:L-1) * fs / L; % Frequency vector

% Generate Reference Signal (a sinusoid)
y = sin(2 * pi * 120 * tt); % Reference sinusoidal signal
y = y(:); % Ensure column vector

% Create Noisy Signal by Adding Gaussian Noise
x = 0.50 * randn(L, 1) + y; % Noisy signal
x = x(:); % Ensure column vector

% Define Filter Order (Number of Coefficients)
N = 200;

% Apply Wiener Filter using custom function
[xest, b, MSE] = wienerFilt(x, y, N);

% Plot Results
figure;
subplot(411);
plot(tt, x, 'k'), hold on, plot(tt, y, 'r');
title('Wiener Filtering Example');
legend('Noisy Signal', 'Reference Signal');

subplot(412);
plot(tt(N+1:end), xest, 'k');
legend('Estimated Signal');

subplot(413);
plot(tt(N+1:end), (x(N+1:end) - xest), 'k');
legend('Residue Signal');

subplot(414);
stem(0:N-1, b, 'k'); % Stem plot for Wiener filter coefficients
title('Wiener Filter Coefficients');
xlabel('Coefficient Index');
ylabel('Magnitude');
grid on;

% Function to Compute Wiener Filter Based on Wiener-Hopf Equations
function [xest, B, MSE] = wienerFilt(x, y, N)
% Inputs:
% x - Noisy signal
% y - Reference signal
% N - Filter order (number of filter coefficients)

% Outputs:
% xest - Estimated signal after filtering
% B - Wiener filter coefficients
% MSE - Mean squared error (performance metric)

% Perform FFT on the first N samples of x (noisy signal) and y (reference)
X = 1/N .* fft(x(1:N)); % FFT of noisy signal
Y = 1/N .* fft(y(1:N)); % FFT of reference signal

% Reshape to column vectors
X = X(:);
Y = Y(:);

% Compute the Autocorrelation Function (Rxx) and Cross-correlation Function (Rxy)
Rxx = N * real(ifft(X .* conj(X))); % Autocorrelation
Rxy = N * real(ifft(X .* conj(Y))); % Cross-correlation

% Convert Rxx into a Toeplitz matrix
Rxx = toeplitz(Rxx);

% Transpose Rxy for the equation
Rxy = Rxy';

% Solve the Wiener-Hopf equation to get filter coefficients: B = inv(Rxx) * Rxy
B = Rxy / Rxx;
B = B(:); % Flatten the filter coefficients vector

% Apply Wiener filter to estimate the signal from the noisy signal
xest = fftfilt(B, x);
xest = xest(N+1:end); % Remove the first N samples to avoid distortion

% Calculate the Mean Squared Error (MSE)
MSE = mean((y(N+1:end) - xest).^2); % Calculate MSE
end

Output

 
 

Further Reading

 

People are good at skipping over material they already know!

View Related Topics to







Contact Us

Name

Email *

Message *

Popular Posts

Constellation Diagram of ASK in Detail

A binary bit '1' is assigned a power level of E b \sqrt{E_b}  (or energy E b E_b ), while a binary bit '0' is assigned zero power (or no energy).   Simulator for Binary ASK Constellation Diagram SNR (dB): 15 Run Simulation Noisy Modulated Signal (ASK) Original Modulated Signal (ASK) Energy per bit (Eb) (Tb = bit duration): We know that all periodic signals are power signals. Now we’ll find the energy of ASK for the transmission of binary ‘1’. E b = ∫ 0 Tb (A c .cos(2П.f c .t)) 2 dt = ∫ 0 Tb (A c ) 2 .cos 2 (2П.f c .t) dt Using the identity cos 2 x = (1 + cos(2x))/2: = ∫ 0 Tb ((A c ) 2 /2)(1 + cos(4П.f c .t)) dt ...

Online Simulator for ASK, FSK, and PSK

Try our new Digital Signal Processing Simulator!   Start Simulator for binary ASK Modulation Message Bits (e.g. 1,0,1,0) Carrier Frequency (Hz) Sampling Frequency (Hz) Run Simulation Simulator for binary FSK Modulation Input Bits (e.g. 1,0,1,0) Freq for '1' (Hz) Freq for '0' (Hz) Sampling Rate (Hz) Visualize FSK Signal Simulator for BPSK Modulation ...

MATLAB Code for Rms Delay Spread

RMS delay spread is crucial when you need to know how much the signal is dispersed in time due to multipath propagation, the spread (variance) around the average. In high-data-rate systems like LTE, 5G, or Wi-Fi, even small time dispersions can cause ISI. RMS delay spread is directly related to the amount of ISI in such systems. RMS Delay Spread [↗] Delay Spread Calculator Enter delays (ns) separated by commas: Enter powers (dB) separated by commas: Calculate   The above calculator Converts Power to Linear Scale: It correctly converts the power values from decibels (dB) to a linear scale. Calculates Mean Delay: It accurately computes the mean excess delay, which is the first moment of the power delay profile. Calculates RMS Delay Spread: It correctly calculates the RMS delay spread, defined as the square root of the second central moment of the power delay profile.   MATLAB Code  clc...

Theoretical vs. simulated BER vs. SNR for ASK, FSK, and PSK

📘 Overview 🧮 Simulator for calculating BER 🧮 MATLAB Codes for calculating theoretical BER 🧮 MATLAB Codes for calculating simulated BER 📚 Further Reading BER vs. SNR denotes how many bits in error are received for a given signal-to-noise ratio, typically measured in dB. Common noise types in wireless systems: 1. Additive White Gaussian Noise (AWGN) 2. Rayleigh Fading AWGN adds random noise; Rayleigh fading attenuates the signal variably. A good SNR helps reduce these effects. Simulator for calculating BER vs SNR for binary ASK, FSK, and PSK Calculate BER for Binary ASK Modulation Enter SNR (dB): Calculate BER Calculate BER for Binary FSK Modulation Enter SNR (dB): Calculate BER Calculate BER for Binary PSK Modulation Enter SNR (dB): Calculate BER BER vs. SNR Curves MATLAB Code for Theoretical BER % The code is written by SalimWireless.Com clc; clear; close all; % SNR va...

MATLAB Code for ASK, FSK, and PSK

📘 Overview & Theory 🧮 MATLAB Code for ASK 🧮 MATLAB Code for FSK 🧮 MATLAB Code for PSK 🧮 Simulator for binary ASK, FSK, and PSK Modulations 📚 Further Reading ASK, FSK & PSK HomePage MATLAB Code MATLAB Code for ASK Modulation and Demodulation % The code is written by SalimWireless.Com % Clear previous data and plots clc; clear all; close all; % Parameters Tb = 1; % Bit duration (s) fc = 10; % Carrier frequency (Hz) N_bits = 10; % Number of bits Fs = 100 * fc; % Sampling frequency (ensure at least 2*fc, more for better representation) Ts = 1/Fs; % Sampling interval samples_per_bit = Fs * Tb; % Number of samples per bit duration % Generate random binary data rng(10); % Set random seed for reproducibility binary_data = randi([0, 1], 1, N_bits); % Generate random binary data (0 or 1) % Initialize arrays for continuous signals t_overall = 0:Ts:(N_bits...

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...

📘 Overview of BER and SNR 🧮 Online Simulator for BER calculation of m-ary QAM and m-ary PSK 🧮 MATLAB Code for BER calculation of M-ary QAM, M-ary PSK, QPSK, BPSK, ... 📚 Further Reading 📂 View Other Topics on M-ary QAM, M-ary PSK, QPSK ... 🧮 Online Simulator for Constellation Diagram of m-ary QAM 🧮 Online Simulator for Constellation Diagram of m-ary PSK 🧮 MATLAB Code for BER calculation of ASK, FSK, and PSK 🧮 MATLAB Code for BER calculation of Alamouti Scheme 🧮 Different approaches to calculate BER vs SNR What is Bit Error Rate (BER)? The abbreviation BER stands for Bit Error Rate, which indicates how many corrupted bits are received (after the demodulation process) compared to the total number of bits sent in a communication process. BER = (number of bits received in error) / (total number of tran...

UGC NET Electronic Science Previous Year Question Papers

Home / Engineering & Other Exams / UGC NET 2022: Previous Year Question Papers ... UGC-NET (Electronics Science, Subject code: 88) UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2024]  UGC Net Paper 1 With Answer Key Download Pdf [Sep 2024] with full explanation UGC Net Electronic Science Question Paper With Answer Key Download Pdf [Sep 2024]  UGC Net Paper 1 With Answer Key Download Pdf [June 2023] with full explanation UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2023] with full explanation UGC Net Electronic Science Question Paper With Answer Key Download Pdf [June 2023] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2022] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [June 2022] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2021] ...

Theoretical BER vs SNR for BPSK

Theoretical Bit Error Rate (BER) vs Signal-to-Noise Ratio (SNR) for BPSK in AWGN Channel Let’s simplify the explanation for the theoretical Bit Error Rate (BER) versus Signal-to-Noise Ratio (SNR) for Binary Phase Shift Keying (BPSK) in an Additive White Gaussian Noise (AWGN) channel. Key Points Fig. 1: Constellation Diagrams of BASK, BFSK, and BPSK [↗] BPSK Modulation Transmits one of two signals: +√Eb or −√Eb , where Eb is the energy per bit. These signals represent binary 0 and 1 . AWGN Channel The channel adds Gaussian noise with zero mean and variance N₀/2 (where N₀ is the noise power spectral density). Receiver Decision The receiver decides if the received signal is closer to +√Eb (for bit 0) or −√Eb (for bit 1) . Bit Error Rat...