M-point moving average filter MATLAB Program

MATLAB Program for M-point moving average filter

Hi friends, today we are going to learn a how to write a MATLAB program for m point moving averagr filter.

Steps for writing M-point moving average filter program in MATLAB:

1)    Take a given signal 2n*(0.9)^n and denote it by s(n).

2)    Then generate a random noise signal having same length (50) as that of s(n) and denote it by d.

3)    Then add s+d and save it in p, i.e. p=s+d.

4)    We know that the formula for m point moving average filter is given by

1

5)    To determine summation use one for loop.

6)    Finally divide summation by M, you will get original signal.

The MATLAB program:

clc;

clear all;

close all;

n=1:50;

s(n)=2*n.*(0.9).^n;

subplot(2,2,1)

stem(s)

xlabel(‘Original signal’)

d=rand(1,50);

subplot (2,2,2)

stem(d)

xlabel(‘Noise signal’)

p=s+d;

subplot (2,2,3)

stem(p)

xlabel(‘Corrupted Signal’)

m=100;

xu=0;

for i=1:m

d=rand(1,50);

x=s+d;

xu=xu+x;

end

xu=xu/m;

subplot(2,2,4)

stem(xu)

xlabel(‘Output signal’)

OUTPUT of M-Point moving average filter :

m point moving average filter
m point moving average filter

You may also like:

Tags: MATLAB program for M point moving average filter.

Introduction to Z Transform with examples

Introduction to Z Transform:

Z transform of a signal provides a valuable technique for analysis and design of the discrete time signal and discrete time LTI system.

Z transform of a discrete time signal has both imaginary and real part. The plot of imaginary part versus real part is called as the z plane. The poles and zeros of the discrete time signals are plotted in the complex z plane. Pole-zero plot is the main characteristics of the discrete time signals. Using pole zero plot we can check the stability of the system which we will see in the upcoming posts.

Advantages of the Z transform:

Following are some of the main advantages of the Z transform:

  • We can simplify the solution of differential equation using z transform.
  • By the use of z transform we can completely characterize given discrete time signals and LTI systems.
  • The stability of the LTI system can be determined using z transform.
  • Mathematical calculations can be reduced by using z transform. For example convolution operation is transformed into simple multiplication operation.

Z transforms:

There are two types of z transform:

  1. Single sided Z transform.
  2. Double sided Z transform.

Single sided Z transform:

Single sided Z transform can be defined as,

 1

Double sided Z transform:

Double sided Z transform can be defined as,

 2

 

In single sided Z transform only positive values of n are used (from 0 to ∞) hence called single sided, whereas in the double sided values of n are ranging from -∞ to +∞.

Representation of the Z transforms:

Z transform of the signal x(n) is represented as,

3

The relation between x(n) and X(Z) is denoted as follows:

4

Where X(Z) is the Z transform of the signal x(n). The arrow is bidirectional which indicates that we can obtain x(n) from X(Z) also, which is called as inverse Z transform.

x(n) and X(Z) is called as Z transform pair.

Region of convergence (ROC):

“Region of convergence is defined as a set of all values of Z for which X(Z) has finite value. It is very important to denote ROC every time when we find Z transform.”

Significance of ROC:

  • ROC will decide whether the given system is stable or unstable.
  • ROC is also useful for determining the type of sequence. i.e. whether the system is causal or non-causal, finite or infinite.

Examples on Z Transform:

5

You may also like:

Tags: Basics of Z transform.

 

Representation of basic discrete time signal using MATLAB

Representation of basic discrete time signal using MATLAB:

Hi friends, today we are going to discuss about discrete time signals and how to plot graphs of different discrete time signals such as step signal, ramp signal, impulse function, exponential, sine and cosine signals using MATLAB.

Before going towards actual programming part, let us recall the definition of discrete time signal.

“In discrete time signal the value of signal is specified only at specific time. So signal represented at “discrete interval of time” is called as discrete time signal.”

MATLAB Program:

clc;

clear all;

close all;

x=[0:15];

for i=1:16

y(i)=1;

end

subplot(2,3,1)

stem(x,y)

title(‘Discrete time Step Function’)

xlabel(‘Samples’)

ylabel(‘Step function’)

for i=1:16

y(i)=x(i);

end

subplot(2,3,2)

stem(x,y)

title(‘Discrete time Ramp Function’)

xlabel(‘Samples’)

ylabel(‘Ramp signal’)

y=[zeros(1,4),1,zeros(1,11)];

subplot(2,3,3)

stem(x,y)

title(‘Discrete time Impulse Function’)

xlabel(‘Samples’)

ylabel(‘Impulse function’)

for i=1:16

y(i)=exp(-0.22*i);

end

subplot(2,3,4)

stem(x,y)

title(‘Discrete time Exponential Function’)

xlabel(‘Samples’)

ylabel(‘Exponential function’)

z=[1:35]

for i=1:35

y(i)=sin(2*pi*0.1*i)

end

subplot(2,3,5)

stem(z,y)

title(‘Discrete time Sine Function’)

xlabel(‘Samples’)

ylabel(‘Sine function’)

z=[1:35]

for i=1:35

y(i)=cos(2*pi*0.1*i)

end

subplot(2,3,6)

stem(z,y)

title(‘Discrete time Cosine Function’)

xlabel(‘Samples’)

ylabel(‘Cosine function’)

Explanation:

  • Representation of discrete time step function:

x=[0:15];

for i=1:16

y(i)=1;

end

subplot(2,3,1)

stem(x,y)

title(‘Discrete time Step Function’)

xlabel(‘Samples’)

ylabel(‘Step function’)

For representing discrete time step function, let us consider x-axis represents number of samples and y-axis represents corresponding values of signal. Here we use two matrix x and y. x=[0:15] represents matrix ‘x’ contains 16 elements from 0 to 15. Then we used one for loop from 1:16 (16 times) in which we define matrix y, which stores ‘1’ entire the matrix. Then we give command subplot(2,3,1). Here we used subplot command because we want all the basic signals on a single display. (2,3,1) represents there are 2 rows and 3 columns of graphs (it means 2*3=6 graphs are possible) 1 indicates that we want this graph at first position.

As we know for continuous signal plotting we use plot command but for discrete time signal we have to use stem command.

  • Similarly for discrete time ramp signal we use y(i)=x(i) keeping all the program same.
  • For impulse function we use y=[zeros(1,4),1,zeros(1,11)] that means first 4 elements of the matrix are ‘0(zeros)’ 5th element is ‘1’ and from 6th to 16th it is again ‘0’. Thus y becomes 16 element matrix. Thus we can plot graph of impulse function using matlab.
  • For exponential signal we have used exp(-0.22*i). Here negative sign indicates that the nature of exponential signal is decreasing. But if you remove the negative sign it will become simple increasing exponential signal.
  • Similarly we can plot discrete time sine and cosine functions using MATLAB

MATLAB Program:

MATLAB program for representation of basic discrete time signals 1 MATLAB program for representation of basic discrete time signals 2

basic_signals_graphs
basic_signals_graphs

You may also like:

Tags: MATLAB code for representing discrete time signals. How to plot a discrete time signal in MATLAB.

Stable or Unstable System (Stability Property)

In the previous post we have seen linear and non linear systems. Here we will see how to determine whether the system is stable or unstable i.e. stability property. To define stability of a system we will use the term ‘BIBO’. It stands for Bounded Input Bounded Output. The meaning of word ‘bounded’ is some finite value. So bounded input means input signal is having some finite value. i.e. input signal is not infinite. Similarly bounded output means, the output signal attains some finite value i.e. the output is not reaching to infinite level.

Definition of stable system:

An infinite system is BIBO stable if and only if every bounded input produces bounded output.

Mathematical representation:

Let us consider some finite number Mx whose value is less than infinite. That means Mx < ∞, so it’s a finite value. Then if input is bounded, we can write,

|x(n)| ≤ Mx < ∞

Similarly for C.T. system

|x(t)| ≤ Mx < ∞

Similarly consider some finite number My whose value is less than infinity. That means My < ∞, so it’s a finite value. Then if output is bounded, we can write,

|y(n)| ≤ My < ∞

Similarly for continuous time system

|y(t)| ≤ My < ∞

Definition of Unstable system:

An initially system is said to be unstable if bounded input produces unbounded (infinite) output.

Significance:

  • Unstable system shows erratic and extreme behavior.
  • When unstable system is practically implemented then it causes overflow.

Solved problem on stability:

Determine whether the following discrete time functions are stable or not.

1)      y(n) = x(-n)

Solution: we have to check the stability of the system by applying bounded input. That means the value of x(-n) should be finite. So when input is bounded output will be bounded. Thus the given function is Stable system.

You may also like:

Share it with your friends and like our facebook page for future updates. Have a nice day!