Señales Digitales en MATLAB

9
PRACTICAS DE LABORATORIO INTRODUCTORIAS EN ENTORNO MATLAB PARA TRATAMIENTO DISCRETO DOCENTE: ING. Luis Pacheco Cribillero U.R.P: Ingeniería Mecatrónica Ingeniería de Control Digital 1 Señales Digitales en MATLAB PRÁCTICA 1 Tema: Las señales básicas Planteamiento del problema: Generar las funciones básicas como el impulso unitario, escalón unitario, rampa, exp, el sen, y cos y mostrar la salida en la pantalla. Descripción: El Impulso unitario o la muestra unitaria se define por la relación u 0 (n) = 1 n = 0 = 0 n ≠ 0 La secuencia de Escalón Unitario se define como u (-1) (n) = 1 n ≥ 0 = 0 n <0 La funcion rampa Unitaria se define por, r (n) = N, n ≥ 0 = 0, n <0 La función exponencial se define por, x (n) = a n n≥ 0 = 0, n <0 La función seno se define por, y = sen (), donde es un ángulo. L a función del coseno se define por, y = cos (), donde es un ángulo. Funciones del MATLAB : stem(x,y) Plots x versus the columns y. x and y are vectors or matrices of same size. zeros(m,n) Returns an m-by-n matrix of zeros ones(m,n) Returns an m-by-n matrix of ones exp(x)

Transcript of Señales Digitales en MATLAB

Page 1: Señales Digitales en MATLAB

PRACTICAS DE LABORATORIO INTRODUCTORIAS EN ENTORNO MATLAB PARA TRATAMIENTO DISCRETO

DOCENTE: ING. Luis Pacheco Cribillero U.R.P: Ingeniería Mecatrónica Ingeniería de Control Digital 1

Señales Digitales en MATLAB

PRÁCTICA 1

Tema: Las señales básicas

Planteamiento del problema: Generar las funciones básicas como el impulso unitario, escalón

unitario, rampa, exp, el sen, y cos y mostrar la salida en la pantalla.

Descripción:

El Impulso unitario o la muestra unitaria se define por la relación

u0 (n) = 1 n = 0

= 0 n ≠ 0

La secuencia de Escalón Unitario se define como

u (-1) (n) = 1 n ≥ 0

= 0 n <0

La funcion rampa Unitaria se define por,

r (n) = N, n ≥ 0

= 0, n <0

La función exponencial se define por,

x (n) = a n n≥ 0

= 0, n <0

La función seno se define por,

y = sen (), donde es un ángulo.

L a función del coseno se define por,

y = cos (), donde es un ángulo.

Funciones del MATLAB:

stem(x,y)

Plots x versus the columns y. x and y are vectors or matrices of same size.

zeros(m,n)

Returns an m-by-n matrix of zeros

ones(m,n)

Returns an m-by-n matrix of ones

exp(x)

Page 2: Señales Digitales en MATLAB

PRACTICAS DE LABORATORIO INTRODUCTORIAS EN ENTORNO MATLAB PARA TRATAMIENTO DISCRETO

DOCENTE: ING. Luis Pacheco Cribillero U.R.P: Ingeniería Mecatrónica Ingeniería de Control Digital 2

Returns the exponential for each element of X.

sin(x)

Returns the circular sine of the elements of X.

cos(x)

Returns the circular cosine of the elements of X.

Programa Fuente:

clc;

clear all;

close all;

n=input('Enter the value for n');

a=input('Enter the value for a in exponential function');

% Unit Impulse Response

t=-2:1:2;

%t=[-2,2]

y=[zeros(1,2),ones(1,1),zeros(1,2)];

subplot(5,2,1);

stem(t,y);

title('UNIT IMPULSE SIGNAL');

ylabel('Amplitude');

xlabel('n');

%Unit Step Response

t=-2:1:n-1;

y=[zeros(1,2),ones(1,n)];

subplot(5,2,2);

stem(t,y);

title('UNIT STEP SEQUENCE');

ylabel('Amplitude');

xlabel('n');

%Ramp Sequence

t=0:1:n-1;

subplot(5,2,5);

%y=[zeros(1,2)

stem(t,t);

title('RAMP SEQUENCE');

ylabel('Amplitude');

Page 3: Señales Digitales en MATLAB

PRACTICAS DE LABORATORIO INTRODUCTORIAS EN ENTORNO MATLAB PARA TRATAMIENTO DISCRETO

DOCENTE: ING. Luis Pacheco Cribillero U.R.P: Ingeniería Mecatrónica Ingeniería de Control Digital 3

xlabel('n');

%Exponential

t=0:1:n-1;

y=exp(a*t);

subplot(5,2,6);

plot(t,y);

title('EXPONENTIAL SEQUENCE');

ylabel('Amplitude');

xlabel('n');

%Sine Sequence

t=0:0.01:pi;

y=sin(2*pi*t);

subplot(5,2,9);

plot(t,y);

title('SINE SEQUENCE');

ylabel('Amplitude');

xlabel('n');

%Cosine Sequence

t=0:0.05:pi;

y=cos(2*pi*t);

subplot(5,2,10);

plot(t,y);

plot(t,y);

title('COSINE SEQUENCE');

ylabel('Amplitude');

xlabel('n');

OUTPUT:

Enter the value for n 7

Enter the value for a in exponential function -0.3

Page 4: Señales Digitales en MATLAB

PRACTICAS DE LABORATORIO INTRODUCTORIAS EN ENTORNO MATLAB PARA TRATAMIENTO DISCRETO

DOCENTE: ING. Luis Pacheco Cribillero U.R.P: Ingeniería Mecatrónica Ingeniería de Control Digital 4

PRACTICA 2

Topico : Transformada – Z

Enunciado del Problema : Calcule la transformada z de las siguientes expresiones utilizando el

método de fracciones parciales y mostrar la gráfica de polos y ceros.

1. X(z) = z-1/pow((z-0.7071),2)

2. X(z) = pow(z,4)-1/pow(z,4)+1

3. X(z)= pow(z,3)-pow(z,2) + z-1/pow((z+0.9),3)

Description:

La transformada z de una señal x (n) tiempo discreto se define como la serie de potencias.

n=-∞

X(z) = ∑ x(n) z-n

n=∞

donde Z es una variable compleja.

Page 5: Señales Digitales en MATLAB

PRACTICAS DE LABORATORIO INTRODUCTORIAS EN ENTORNO MATLAB PARA TRATAMIENTO DISCRETO

DOCENTE: ING. Luis Pacheco Cribillero U.R.P: Ingeniería Mecatrónica Ingeniería de Control Digital 5

MATLAB functions

residuez(b,a)

Encuentra los residuos, los polos, y términos directos de una expansión de fracciones parciales de

la relación de dos polinomios, b (z) y a (Z). Los Vectores a y b y especifican los coeficientes de

los polinomios del sistema b(z) / a (z) en tiempo discreto en potencias descendentes de z.

roots(c)

Devuelve un vector columna cuyos elementos son las raíces del polinomio c. El vector Fila c

contiene los coeficientes de un polinomio, ordenado en potencias descendentes.

zplane(B,A)

B y A son vectores fila que contiene la función de transferencia de los coeficientes del polinomio y

representa los polos y ceros de B (z) / A (z). Nótese que si B y A son ambos escalares serán

interpretados como Z y P.

Source Program

clc;

clear all;close all;

b = [1 -1]; %Numerator Coefficients

a = [1 -(2*0.7071) ((0.7071)^2)]; %Denominator Coefficients

[r,p,k] = residuez(b,a);

r = roots(b);

zplane(r,p);

axis([-1.5 1.5 -1.5 1.5])

title('Pole-Zero Plot of X(z) = (z - 1)/(z - 0.7071)^2');

b = [1 0 0 0 -1]; %Numerator Coefficients

a = [1 0 0 0 1]; %Denominator Coefficients

[r,p,k] = residuez(b,a);

r = roots(b);

figure;

zplane(r,p);

axis([-1.5 1.5 -1.5 1.5])

title('Pole-Zero Plot of X(z) = (z^4 - 1)/(z^4 + 1)');

b = [1 -1 1 -1]; %Numerator Coefficients

Page 6: Señales Digitales en MATLAB

PRACTICAS DE LABORATORIO INTRODUCTORIAS EN ENTORNO MATLAB PARA TRATAMIENTO DISCRETO

DOCENTE: ING. Luis Pacheco Cribillero U.R.P: Ingeniería Mecatrónica Ingeniería de Control Digital 6

a = [1 2.7 2.43 0.729]; %Denominator Coefficients

[r,p,k] = residuez(b,a);

r = roots(b);

figure;

zplane(r,p);

axis([-1.5 1.5 -1.5 1.5])

title('Pole-Zero Plot of X(z) = (z^3 - z^2 + z - 1) / (z + 0.9)^3');

OUTPUT:

PRACTICAL 3

Topic : N-DFT

Problem Statement: Compute the N-point DFT of the following.Vary the value of N and visualize

the effect with N=8, 16, 24, 64,128,256

1. S(n) = 3 * pow(e(-0.1*n),1)

2. S(n) = 2 * cos( 2 * pi* (0.15) * n) + sin(2 * pi * (0.4) * n)

Page 7: Señales Digitales en MATLAB

PRACTICAS DE LABORATORIO INTRODUCTORIAS EN ENTORNO MATLAB PARA TRATAMIENTO DISCRETO

DOCENTE: ING. Luis Pacheco Cribillero U.R.P: Ingeniería Mecatrónica Ingeniería de Control Digital 7

3. S(n) = 4 * sin ( 4* pi * (0.4) * n) + sin( 2 * pi * (0.2) * n)

Description

The Discrete Fourier Transform (DFT) computes the values of the z-transform for evenly spaced

points around the unit circle for a given sequence.

MATLAB functions

fft(X,n)

Returns the n-point DFT. If the length of X is less than n, X is padded with trailing zeros to length

n. If the length of X is greater than n, the sequence X is truncated. When X is a matrix, the length

of the columns is adjusted in the same manner.

length(X)

Returns the size of the longest dimension of X. If X is a vector, this is the same as its length.

Source Program

clc;

clear all;

close all;

N=input('Enter value for N');

t=0:1:N-1;

len=length(t);

for n=1:len,

x1(n)=3*power(exp(-0.1*t(n)),1);

x2(n)=2* cos(2*pi*(0.15)*t(n))+sin(2*pi*(0.4)*t(n));

x3(n)=4*sin(4*pi*(0.4)*t(n))+sin(2*pi*(0.2)*t(n));

end

t1=fft(x1,N);

t2=fft(x2,N);

t3=fft(x3,N);

figure;

stem(t,t1);

title(‘N DFT of x1(n)=3*power(exp(-0.1*t(n)),1)’);

figure;

Page 8: Señales Digitales en MATLAB

PRACTICAS DE LABORATORIO INTRODUCTORIAS EN ENTORNO MATLAB PARA TRATAMIENTO DISCRETO

DOCENTE: ING. Luis Pacheco Cribillero U.R.P: Ingeniería Mecatrónica Ingeniería de Control Digital 8

stem(t,t2);

title(‘N DFT of x2(n)=2* cos(2*pi*(0.15)*t(n))+sin(2*pi*(0.4)*t(n))’);

figure;

stem(t,t3);

title(‘N DFT of x3(n)=4*sin(4*pi*(0.4)*t(n))+sin(2*pi*(0.2)*t(n))’);

OUTPUT:

Page 9: Señales Digitales en MATLAB

PRACTICAS DE LABORATORIO INTRODUCTORIAS EN ENTORNO MATLAB PARA TRATAMIENTO DISCRETO

DOCENTE: ING. Luis Pacheco Cribillero U.R.P: Ingeniería Mecatrónica Ingeniería de Control Digital 9