%% QPSK Adaptive Equalization With FIR Filter
% Transmit a quadrature phase shift keying (QPSK) signal across a noisy transmission channel. Minimize the noise in the received signal using a frequency-domain adaptive filter.
% Note:  If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes  step(obj,x).
% The QPSK signal, s, is transmitted across a noisy channel. The numerator and the denominator coefficients of the channel are contained in the vectors b and a, respectively. The received signal, r, obtained at the end of the transmission channel contains the transmitted QPSK signal and the noise added to the channel, n. The adaptive filter is used to extract the QPSK signal from the received noisy input. The desired signal, d, is the delayed version of the QPSK signal.

D = 16;
b  = exp(1i*pi/4)*[-0.7 1];
a  = [1 -0.7];
ntr = 1024;
s  = sign(randn(1,ntr+D)) + 1i*sign(randn(1,ntr+D));
n  = 0.1*(randn(1,ntr+D) + 1i*randn(1,ntr+D));
r  = filter(b,a,s) + n;
x  = r(1+D:ntr+D);
d  = s(1:ntr);

% Create a dsp.FrequencyDomainAdaptiveFilter object to model a frequency-domain adaptive filter of length 32 taps and a step size of 0.1. The adaptive filter accepts the delayed version of the received signal and the desired signal as inputs. The output of the adaptive filter is compared to the desired signal. The error between the two signals represents the noise added to the transmission channel. The adaptive filter updates its coefficients until this error becomes minimal. To get the discrete Fourier transform of the filter coefficients, call the fdaf object, and access the FFTCoefficients property of this object.

mu  = 0.1;
fdaf = dsp.FrequencyDomainAdaptiveFilter('Length',32,'StepSize',mu);
[y,e] = fdaf(x,d);
fftCoeffs = fdaf.FFTCoefficients

%
% Plot the In-Phase and the Quadrature components of the desired, output, and the error signals.

plot(1:ntr,real([d;y;e]))
legend('Desired','Output','Error')
title('In-Phase Components')
xlabel('Time Index'); ylabel('signal value')
plot(1:ntr,imag([d;y;e]))
legend('Desired','Output','Error')
title('Quadrature Components')
xlabel('Time Index')
ylabel('signal value')

%
% Create scatter plots of the received signal and the desired signal.

plot(x(ntr-100:ntr),'.')
axis([-3 3 -3 3])
title('Received Signal Scatter Plot')
axis('square')
xlabel('Real[x]')
ylabel('Imag[x]') 
grid on
plot(d(ntr-100:ntr),'.')
axis([-3 3 -3 3])
title('Desired Signal Scatter Plot')
axis('square')
xlabel('Real[y]')
ylabel('Imag[y]')
grid on

%
% The adaptive filter equalizes the received signal to eliminate noise. Plot the scatter plot of the equalized signal.

plot(y(ntr-100:ntr),'.')
axis([-3 3 -3 3])
title('Equalized Signal Scatter Plot')
axis('square')
xlabel('Real[y]')
ylabel('Imag[y]')
grid on

% Copyright 2012 The MathWorks, Inc.