Sin categoría

Matlab Code for DSP – Introduction

Matlab provides a variety of commands that allow us to control the flow of commands in a program.

Control Flow

The most common construct is the if-elseif-else structure. Another common control flow construct is the for..end loop. It is simply an iteration loop that tells the computer to repeat some task a given number of times. The following example illustrates the concept:

Example 1.

Consider the following sum of sinusoidal functions. Use Matlab to generate samples of x(t) at the time instances 0:0.1:1.

First method: In this approach, we will compute each sinusoidal component in one step as a vector, using the time vector t=0:0.1:1 and then add all components using one for..end loop.

>> t=0:0.1:1;

>> xt=zeros(1,length(t));

>> for k=1:3

xt=xt+(1/k)*sin(2*pi*k*t);

>> end

We obtain the following:

xt =   0    1.3803    1.0490    0.4612    0.4293    0.0000   -0.4293   -0.4612   -1.0490   -1.3803   -0.0000

Second method: In this approach, we will use matrix-vector multiplication. We will see how efficient could be Matlab by this way. For the purpose of demostration, consider only four values for t:

Which can be written in matrix form as:

After taking transposition:

Thus, the Matlab code is:

>> t=0:0.1:1; k=1:3;

>> xt=(1./k)*sin(2*pi*k’*t)

We obtain:

xt =   0    1.3803    1.0490    0.4612    0.4293    0.0000   -0.4293   -0.4612   -1.0490   -1.3803   -0.0000

This is the most compact code and the most efficient execution in Matlab, especially when the number of sinusoidal terms is very large.

Scripts and Functions

In construction…

Plotting

In construction….

Source:

  • Digital Signal Processing Using Matlab, 3erd ed

PREVIOUS:

NEXT:

Literature review by:

Prof. Larry Francis Obando – Technical Specialist – Educational Content Writer

Exercises are solved!!

WhatsApp:  +34633129287  Inmediate Attention!!

Twitter: @dademuch

Copywriting, Content Marketing, Tesis, Monografías, Paper Académicos, White Papers (Español – Inglés)

Escuela de Ingeniería Electrónica de la Universidad Simón Bolívar, USB Valle de Sartenejas.

Escuela de Ingeniería Eléctrica de la Universidad Central de Venezuela, UCV Caracas.

Escuela de Turismo de la Universidad Simón Bolívar, Núcleo Litoral.

Contacto: España. +34633129287

Caracas, Quito, Guayaquil, Jaén. 

WhatsApp:  +34633129287   

Twitter: @dademuch

FACEBOOK: DademuchConnection

email: dademuchconnection@gmail.com

3 comentarios en “Matlab Code for DSP – Introduction”

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s