y[n] = b0x[n] +b1x[n-1]

I have this MA filter in matlab as following

 load handel;
 x = y;

 b0 = 0.5;
 b1 = 0.5;

 N = length(x); % Length of input signal
 y = zeros(1,20); % Allocate space for output

 y(1) = b0*x(1); % First sample, assuming x(0) = 0
  for n=2:N % Remaining samples
    y(n) = b0*x(n) + b1*x(n-1);



I was asked to create an input signal x[n] = dirac[n] where i save the x[n] for n = 0...19 in a vector and plot both signals in the same window for axis ([-1 20 ,0 1.5]).

I have tried so far that the new signal should look like this y1(n) = b0*dirac(n) + b1*dirac(n-1) but not sure if this is the right way or I maybe just not understood something?

  • \$\begingroup\$ well, if you put an impulse through a system, you get the impulse response, in your case [b0, b1]. \$\endgroup\$ Mar 24 '19 at 6:58
  • \$\begingroup\$ does it mean that it looks like h[n] = b0 + b1? \$\endgroup\$
    – Adam
    Mar 24 '19 at 7:03
  • \$\begingroup\$ how about impulse? \$\endgroup\$
    – Hazem
    Mar 24 '19 at 7:06
  • \$\begingroup\$ @Adam no. I meant exactly what I wrote! The impulse response of your system has length 2 and is the vector [b0, b1]. \$\endgroup\$ Mar 24 '19 at 7:16
  • 1
    \$\begingroup\$ I mean, do it on paper. If you input 1,0,0,0,0,0… to your y[n] = b0 * x[n] + b1 * x[n-1], you simply get [b0, b1, 0, …] out. That's what we call impulse response. Because it's the response to an impulse. Since you're a student of something related to signal processing, you should be getting yourself really familiar with impulse responses and basics of system theory! \$\endgroup\$ Mar 24 '19 at 7:23

The output sequence y(n) is a linear regression of the input sequence x(n) which "keeps memory" of the last 2 samples of the input to compute the output.

Allocating the sequence x(n), required being a dirac pulse, into an array x[n] is a correct begin. Then you can develop the output sequence y(n) per input sequence x(n). For that I suggest you to exploit the functionality of matlab and to avoid the for loop:

y = zeros(1,20); % Allocate space for output
y(1) = b0*x(1); %initial condition
y(2:20) = b0*x(2:20) + b1*x(1:20); % for n > 0

You should obtain an array of 20 samples of y(n) that you can easily plot using the function plot(x,y). Note: since the dirac function is symbolic, you must decide by your own at which time the pulse should rise (e.g. at n=0 or otherwise). For that I suggest you the example in the documentation of the function called "Plot Dirac Delta Function".


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.