Electronic – Matlab code to derive the overall difference equation relating two systems

equationMATLABsignal processing

Using Matlab, I am trying to:

  • Get the overall difference equation relating to z[n] to x[n] and check if
  • z[n] = x[n] is a valid solution to the overall difference equation

I have two signals given by the differential equations:

  • z[n] + az[n−N] = y[n]
  • y[n] = x[n] + ax[n−N]

Where x[n] is an uncorrupted speech signal, which has been delayed by N samples and added back in with its amplitude decreased by a <1. Also, N = 1000, and the echo amplitude,a = 0.5.

What I have at this point:

% z[n] + az[n - N] = y[n]
% y[n] = x[n] + ax[n - N]

% Replacing:
% z[n] + az[n - N] = x[n] + a[n - N]
% z[n] = x[n] + a[n - N] - az[n - N]

syms z(n) % z[n] = dz/dn
syms x(n)

ode = diff(z,n) == ??

But I am stuck in how should I add the x[n] part.

How do I show these equations are equivalent?

As requested, I am adding more information about this overall question:

I am using a speech that was recorded with a sampling rate of 8192 Hz (I can hear the speech by typing sound(y,8192). The signal y[n], represented by the vector y, is of the form:

y[n] = x[n] + ax[n−N] (1)

where x[n] is the uncorrupted speech signal, which has been delayed by N samples and added back in with its amplitude decreased by a <1. This is a reasonable model for an echo resulting from the signal reflecting off of an absorbing surface like a wall.

For the problems in this exercise, I am using the value of the echo time, N= 1000, and the echo amplitude , a= 0.5.

My first task and also my question here was to remove the echo by linear filtering. Since the echo can be represented by a linear system of the form Eq. (1) I determined and plotted the impulse response of the echo system Eq. (1). I stored this impulse response in the vector he for 0≤n≤1000.

Now I need to consider an echo removal system described by the difference equation

z[n] +az[n−N] = y[n] (2)

where y[n] is the input and z[n] is the output which has the echo removed. I need to derive the overall difference equation relating z[n] to x[n] and check if z[n] =x[n] is a valid solution to the overall difference equation.

My whole code at this point is:

% Testing the input:
sound(y,8192)


    %% Part A:
    % create the impulse response
    M = 1; % MATLAB indexing offset
    N = 1000;
    h = zeros(1001,1); 
    h(M+0) = 1;
    h(M+1000) = 1;
    stem(h);
    he = h;

    %% Part B:
    % z[n] + az[n - N] = y[n]
    % y[n] = x[n] + ax[n - N]

    % Replacing:
    % z[n] + az[n - N] = x[n] + a[n - N]
    % z[n] = x[n] + a[n - N] - az[n - N]

    syms z(n) % z[n] = dz/dn
    syms x(n)

    ode = diff(z,n) == 

Best Answer

Sure:

\$ z[n] + az[n−N] = y[n] \$

now lets take the above equation and substitute x[n]=z[n]

\$ x[n] + ax[n−N] = y[n] \$

which looks exactly like the other equation, so they are equivalent