FIR filter design with null frequency

6 views (last 30 days)
Noor Salam
Noor Salam on 1 Dec 2023
Answered: Balavignesh on 11 Dec 2023
For a signal x[n] = s[n] + v[n] and rs[l] = 1 2 cos(0.6πl), rv[l] = 2δ[l]. For a filter with input of x[n] and output is an estimate of s[n].
How to design a FIR filter that minimizes the mean square error between the filter output and s[n]. The filter should have a null in the frequency response at ωI = 0.2π. and the null should be a part in the optmization process.

Answers (1)

Balavignesh
Balavignesh on 11 Dec 2023
Hello Noor,
I understand that you are interested in creating a FIR filter that reduces the mean square error between the filter output and the original signal 's[n]'.
I recommend generating the sample signal 's[n]' with a cosine component at '0.6*pi' and adding a noise signal 'v[n]' as white noise. These combined signals form the input signal 'x[n]'. Afterward, you can compute the power spectral density (PSD) of 's[n]' and 'v[n]' to derive the weiner filter in the frequency domain, ensuring a null at the specified frequency. The designed filter aims to minimize the mean square error (MSE) between the filter output and the original signal.
You may find the following example code helpful in understanding this concept:
% Define the parameters
N = 512; % Number of samples
omega_null = 0.2 * pi; % Frequency where the null is desired
% Generate the sample signal s[n] with a cosine component at 0.6*pi
n = 0:N-1; % Sample index vector
s = 1 + 2*cos(0.6*pi*n); % Signal s[n]
% Generate the noise signal v[n] as white noise
v = sqrt(2)*randn(1, N); % Signal v[n] with variance 2
% Generate the input signal x[n] as the sum of s[n] and v[n]
x = s + v;
% Define the frequency vector for filter design
omega = linspace(0, pi, N);
% Calculate the PSD of s[n] (assuming it follows the autocorrelation given)
S = 1 + 2*cos(0.6*pi*(0:N-1)); % PSD of s[n]
% Calculate the PSD of v[n] (assuming white noise with variance 2)
V = 2*ones(1, N); % PSD of v[n]
% Calculate the Wiener filter in the frequency domain
H_wiener = S ./ (S + V);
% Enforce the null at the specified frequency by setting the response to zero
H_wiener(round(omega_null/pi*N)) = 0;
% Design the FIR filter using the frequency sampling method
b = fir2(N, omega/pi, H_wiener);
% Apply the filter to the input signal x[n]
y = filter(b, 1, x);
% Compute the MSE between the filter output y and the original signal s
mse = mean((y - s).^2);
% Plot the original signal s[n], the noisy signal x[n], and the filtered output y[n]
figure;
subplot(3, 1, 1);
plot(n, s);
title('Original Signal s[n]');
xlabel('Sample Index');
ylabel('Amplitude');
subplot(3, 1, 2);
plot(n, x);
title('Noisy Signal x[n]');
xlabel('Sample Index');
ylabel('Amplitude');
subplot(3, 1, 3);
plot(n, y);
title('Filtered Output y[n]');
xlabel('Sample Index');
ylabel('Amplitude');
% Plot the frequency response of the FIR filter
[H, W] = freqz(b, 1, 1024);
figure;
plot(W/pi, abs(H));
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Magnitude');
title('Frequency Response of the FIR Filter with a Null');
grid on;
Kindly refer to the following documentation links to have more information on:
Hope this helps!
Balavignesh

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!