Você está na página 1de 2

Hola!! Dejo ac un cdigo que gratamente encontr en la red que es para calcular la co nvolucin de forma "continua" en matlab.

"continua" entre " porque matlab no traba ja en forma continua (por eso lo til). Resalto, para que nadie ms caiga en mi error, que la funcin conv de matlab que ha ce la convolucin (entre otras cosas..) slo es para seales o funciones de tiempo dis creto (utiliza el algoritmo FFT). function conv_322(x,x_start,h,h_start,delta); % conv_322(x,x_start,h,h_start,delta); % % Convolution support function for the Signals and Systems course, % EE-322 at the United States Naval Academy {EE Department}. % Calculates and plots the numeric convolution integral, y(t) = x(t)*h(t). % The input, x(t), and the impulse response, h(t), are also plotted. % For the result to be accurate ... delta must be sufficiently small. % % x - sampled version of the input function % x_start - input function start time (in seconds) % h - sampled version of the impulse response function % h_start - impulse response function start time (in seconds) % delta - time interval between samples (in seconds) ... delta t % % 7 September 1998, last rev 23 September 1998 % copyright (c) 1998, written by CDR Thad Welch {USNA} % w/ help from Midshipman 2/C Trevor Laughter expand=0.1; total_length=length(x)+length(h)-1; t=x_start+h_start+delta*(0:total_length-1); t_min=min([x_start h_start t]); t_max=max([x_start+delta*length(x) h_start+delta*length(h) t]); y=delta*conv(x,h); y_min=min([x h y]); y_max=max([x h y]); tmin=t_min-expand*(t_max-t_min); tmax=t_max+expand*(t_max-t_min); ymin=y_min-expand*(y_max-y_min); ymax=y_max+expand*(y_max-y_min); x_time=x_start+delta*(0:length(x)-1); h_time=h_start+delta*(0:length(h)-1); subplot(3,1,1) plot([tmin t(1)-delta t tmax],[0 0 y 0],'b') grid title('Convolution of x(t) and h(t)') ylabel('output, y(t)') %axis([tmin tmax ymin ymax]) subplot(3,1,2) plot([tmin x_time(1)-delta x_time x_time(length(x_time))+delta tmax],[0 0 x 0 0] ,'r') grid ylabel('input, x(t)') %axis([tmin tmax ymin ymax]) subplot(3,1,3)

plot([tmin h_time(1)-delta h_time h_time(length(h_time))+delta tmax],[0 0 h 0 0] ,'g') grid xlabel('time (seconds)') ylabel('impulse response, h(t)') %axis([tmin tmax ymin ymax]) Confirmo que anda y muy bien de hecho. Dejo un par ejemplos de como se usa porque si da paja leer la ayuda que tiene en ingls. (Estoy cursando teora de las telecomunicaciones as que yo, slo por eso, voy a expli car esto con el tema de filtros adaptados. Y de hecho, ejercicio 3 del tp 2 de e sa materia) Supongamos que queremos ver la salida de un filtro adaptado a un escaln (en reali dad ms bien a un cajn..). Para ello tengo ya hecha la siguiente funcin: Cdigo: function y=escalon(t) %escaln unitario %y=u(t) y=1.*(t>=0); teniendo esa y conv_322 en el path de matlab hacemos en la lnea de comandos como sigue ( en un .m): T=1; %sto ser el tiempo de bit t=0:0.01:1; %esto es la duracin de la simulacin, el paso de 0.01 es uno de los arg umentos de la funcin %conv_322 s1=escalon(t); %la seal, escaln h1=escalon(-t+T); %la respuesta impusiva del filtro adaptado a s1 conv_322(s1,0,h1,0,0.01)

Otro ejemplo, seal senoidal. T=pi/2; %tiempo de bit t=0:0.01:2*pi% (puede ser ms o menos pero lo pongo as para tener un perodo entero, me refiero al 2*pi) s2=sin(t); h2=sin(-t+T); conv_322(s2,0,h2,0,0.01)

Você também pode gostar