Está en la página 1de 4

Representación gráfica de Secuencias Discretas y Señales Continuas

MATLAB
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all, close all, clc

% Señales discretas (secuencias discretas)


n = -3:5; % vector de tiempo discreto: contiene 5+3+1 = 9 puntos
x_n = [2 1 -1 4 3 5 2 -1 1]; % vector de 9 elementos
subplot(2,1,1) % Divide pantalla en 2 filas, 1 columna. Toma Posición 1
stem(n,x_n) % Grafica de la secuencia x[n]

% Señales continuas
Delta = 0.1; % Delta = Ts: Tiempo de muestreo. fs = 1/Ts
t = 0:Delta:6; % vector de tiempo continuo. No de elementos depende de Ts
x_t = exp(-t);
subplot(2,1,2) % Posición 2
plot(t,x_t) % Une cada punto y grafica la señal x(t)

PHYTON
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
import numpy as np
import matplotlib.pyplot as plt

n = np.arange(-3, 6) # Vector de tiempo discreto (último valor = 5)


x_n = np.array([2, 1, -1, 4, 3, 5, 2, -1, 1])
plt.subplot(1,2,1)
plt.stem(n,x_n)

Delta = 0.1 # Delta = Ts: Tiempo de muestreo. fs = 1/Ts


t = np.arange(0, 6+Delta, Delta) # Vector de tiempo continuo. Phyton no incluye
el último valor, por eso se pone “6+Delta”
x_t = np.exp(-t)

plt.subplot(1,2,2)
plt.plot(t,x_t)
plt.show()

Interpolación por cero e interpolación escalón

MATLAB
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all, close all, clc
n_in = -1; % Posición inicial del vector de tiempo discreto n
n_fin = 7; % Posición inicial del vector de tiempo discreto n
n = n_in:n_fin; % Vector de tiempo discreto
M = 1/3; % Factor de escalamiento M < 1: Interpolación
x_n = [1 3 4 6 8 7 9 2 5]; % Secuencia de tiempo discreto
nD = n_in*(1/M):n_fin*(1/M); % Nuevo vector de tiempo interpolado
L_nD = length(nD);
for k = 0:L_nD-1
if mod(k,2)==0
r = int8(k*M);
x_nD0(k+1) = x_n(r+1); % vector para interpolación por cero
x_nDEsc(k+1) = x_n(r+1); % vector para interpolación escalón
else
x_nD0(k+1) = 0; % Interpolación por cero
x_nDEsc(k+1) = x_nDEsc(k); % Interpolación escalón
end
end
%x_nD
subplot(1,2,1)
stem(nD,x_nD0)
subplot(1,2,2)
stem(nD,x_nDEsc)

PHYTON
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
import numpy as np
import matplotlib.pyplot as plt

n_in = -1
n_fin = 7
n = np.arange(n_in,n_fin+1)
M = 1/3
x_n = [1, 3, 4, 6, 8, 7, 9, 2, 5]
L_n = len(x_n)
nD = np.arange(n_in*1/M, n_fin*1/M + 1)
print(nD)
L_nD = len(nD)
x_nD0 = np.arange(1, L_nD+1) # vector para interpolación por cero
x_nDEsc = np.arange(1, L_nD+1) # vector para interpolación escalón
for k in range(L_nD-1):
#print(k)
if k % 2 ==0:
r = int(k*M)
x_nD0[k] = x_n[r]
x_nDEsc[k] = x_n[r]
else:
x_nD0[k] = 0 # interpolación por cero
x_nDEsc[k] = x_nDEsc[k-1] # Interpolación escalón
#print(x_nD0)
x_nD0[L_nD-1] = x_n[L_n-1]
x_nDEsc[L_nD-1] = x_n[L_n-1]

plt.subplot(1,2,1)
plt.stem(nD,x_nD0)
plt.subplot(1,2,2)
plt.stem(nD,x_nDEsc)
plt.show()
Interpolación lineal

MATLAB
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all, close all, clc
n_in = -1;
n_fin = 3;
n = n_in:n_fin; % Vector de tiempo discreto
M = 1/3; % Factor de escalamiento
x_n = [1 6 2 9 8];% 1 5 2 9 3 6 8 5]; % Secuencia discreta
L_n = length(n);
M = 1/3;
n_M = n_in*1/M:n_fin*1/M; % Vector de tiempo escalado
L_nM = length(n_M);
k = 1;
for i = 1:L_n-1
x_nM(k) = x_n(i);
for j = 1:(1/M)-1
Dif = x_n(i+1)-x_n(i); % interpolación lineal
x_nM(k+1) = x_n(i)+(j*M*Dif); % interpolación lineal
k = k+1;
end
k=k+1;
end
x_nM(L_nM) = x_n(L_n);
subplot(2,1,1)
stem(n,x_n)
subplot(2,1,2)
stem(n_M, x_nM)

PHYTON
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
import numpy as np
import matplotlib.pyplot as plt
n_in = -1
n_fin = 3
n = np.arange(n_in,n_fin+1)
M = 1/3
M1 = int(1/M)
x_n = [1, 6, 2, 9, 8] #, 1, 5, 2, 9, 3, 6, 8, 5]
L_n = len(x_n)
n_M = np.arange(n_in*1/M, n_fin*1/M + 1)
L_nM = len(n_M)
x_nM = np.arange(1, L_nM+1) # vector para interpolación lineal
k = 0
for i in range(L_n-1):
x_nM[k] = x_n[i]
for j in range(1,M1):
print(j)
Dif = x_n[i+1]-x_n[i] # Operación para interpolación lineal
A = j*M*Dif+x_n[i] # Operación para interpolación lineal
x_nM[k+1] = A
print(x_nM)
k = k+1
k=k+1
x_nM[L_nM-1] = x_n[L_n-1]
plt.subplot(1,2,1)
plt.stem(n,x_n)
plt.subplot(1,2,2)
plt.stem(n_M,x_nM)
plt.show()

También podría gustarte