0% found this document useful (0 votes)
42 views

Programas en Matlab: Sandra Morales Espinoza

This document contains 10 MATLAB programs related to signal processing topics. The programs cover concepts like filtering, Fourier transforms, discretization of continuous time systems, and plotting transfer functions. Program 1 is titled "Alasing" and the others are numbered up to 10 and cover topics like comparing signals, calculating filter coefficients, implementing different filter types, and converting between continuous and discrete time representations. The document provides the MATLAB code for each program and includes comments to explain aspects of the programs.

Uploaded by

Sandy Morales
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Programas en Matlab: Sandra Morales Espinoza

This document contains 10 MATLAB programs related to signal processing topics. The programs cover concepts like filtering, Fourier transforms, discretization of continuous time systems, and plotting transfer functions. Program 1 is titled "Alasing" and the others are numbered up to 10 and cover topics like comparing signals, calculating filter coefficients, implementing different filter types, and converting between continuous and discrete time representations. The document provides the MATLAB code for each program and includes comments to explain aspects of the programs.

Uploaded by

Sandy Morales
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

UACM

Programas en Matlab
Sandra Morales Espinoza
Sandy 14/07/2013

Programa 1 Alasing

Programa 2
function varargout = Compara_CyD(varargin) % COMPARA_CYD MATLAB code for Compara_CyD.fig % COMPARA_CYD, by itself, creates a new COMPARA_CYD or raises the existing % singleton*. % % H = COMPARA_CYD returns the handle to a new COMPARA_CYD or the handle to % the existing singleton*. % % COMPARA_CYD('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in COMPARA_CYD.M with the given input arguments. % % COMPARA_CYD('Property','Value',...) creates a new COMPARA_CYD or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Compara_CyD_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Compara_CyD_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help Compara_CyD % Last Modified by GUIDE v2.5 17-Apr-2013 10:37:09

gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Compara_CyD_OpeningFcn, ... 'gui_OutputFcn', @Compara_CyD_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before Compara_CyD is made visible. function Compara_CyD_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Compara_CyD (see VARARGIN) % Choose default command line output for Compara_CyD handles.output = hObject; % Aqui es donde se define lo que nos venga en gana handles.t1=0:0.001:0.5; handles.t2=0:0.01:10; handles.O1=100; handles.O2=100; % Update handles structure guidata(hObject, handles); % UIWAIT makes Compara_CyD wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = Compara_CyD_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in Ejemplo_1. function Ejemplo_1_Callback(hObject, eventdata, handles) % hObject handle to Ejemplo_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) handles.t=handles.t1; handles.O1=10; handles.O2=50; guidata(hObject, handles);

actualizar(hObject, eventdata, handles)

Programa 3 Valor de coeficientes

close all clear all clc Tp= 3; tau=1.5; A=10; k=[-40:1,0.0001,1:40]; Fo=1/Tp; h=figure(1); %figure('name','Valor de los coeficientes c_k con t_p fijo y \tau variable') tau=0.2*Tp; subplot(3,1,1) stem(k*Fo,(A*tau/Tp)*sin(pi*tau*Fo*k)./(pi*tau*Fo*k)) axis([-40/Tp 40/Tp -1 2]) xlabel('\tau=0.2 t_p con t_p=3') title('Valor de los coeficientes c_k con t_p fijo y \tau variable') tau=0.1*Tp; subplot(3,1,2) stem(k*Fo,(A*tau/Tp)*sin(pi*tau*Fo*k)./(pi*tau*Fo*k)) axis([-40/Tp 40/Tp -1 2]) xlabel('\tau=0.1 t_p con t_p=3') tau=0.05*Tp; subplot(3,1,3) stem(k*Fo,(A*tau/Tp)*sin(pi*tau*Fo*k)./(pi*tau*Fo*k)) axis([-40/Tp 40/Tp -1 2]) xlabel('\tau=0.05 t_p con t_p=3') figure(2) tau=1.5; Tp=5*tau; Fo=1/Tp; subplot(3,1,1) stem(k*Fo,(A*tau/Tp)*sin(pi*tau*Fo*k)./(pi*tau*Fo*k)) axis([-2/tau 2/tau -1 2]) Practica 4 xlabel('t_p=5 \tau con \tau=1.5') title('Valor de los coeficientes c_k con \tau fijo y t_p variable') Tp=10*tau; Fo=1/Tp; subplot(3,1,2) stem(k*Fo,(A*tau/Tp)*sin(pi*tau*Fo*k)./(pi*tau*Fo*k)) axis([-2/tau 2/tau -1 2]) xlabel('t_p=10 \tau con \tau=1.5') Tp=20*tau; Fo=1/Tp; subplot(3,1,3) stem(k*Fo,(A*tau/Tp)*sin(pi*tau*Fo*k)./(pi*tau*Fo*k)) axis([-2/tau 2/tau -1 2]) xlabel('t_p=20 \tau con \tau=1.5')

Programa

% Programa que grafica N armonicos de una seal cuadrada no periodica w=-pi:0.05:pi; wc=2; N=200 xn=0; for n=-N:-1; temp= (sin(wc*n)/(pi*n))*exp(-1i*w*n); xn=xn+temp; subplot(2,1,1) plot(w,temp) hold on end temp=exp(-1i*w*0); % evitar el cero xn=xn+temp; subplot(2,1,1) plot(w,temp) hold on for n=1:N temp=(sin(wc*n)/(pi*n))*exp(-1i*w*n); xn=xn+temp; subplot(2,1,1) plot(w,temp) hold on end subplot(2,1,2) plot([-pi -2 -2 2 2 pi],[0 0 1.4 1.4 0 0],'r') hold on plot(w,xn,'b')

Programa 5

Programa 6 %% Clean up
clear all close all clc %% Definir datos fs=500e3; f1=1e3; f2=5e3; f3=10e3; t=0:1/fs:5; %% Funcion de prueba y=cos(2*pi*f1*t)+cos(2*pi*f2*t)+cos(2*pi*f3*t); %plot(t,y) %% Anlisis de la fft N=length(y); n=nextpow2(N); Pffty=abs(fft(y))/N; f=(fs/2)*linspace(0,1,(N/2)+1); figure(1) plot(f,Pffty(1:(N/2)+1)) %% Implementeando filtros [Pasa bajas] [z_b,p_b,k_b]=butter(8,5000*2*pi,'low','s'); filtro_b=tf(zpk(z_b,p_b,k_b)) [num_bc,den_bc]=tfdata(filtro_b,'v'); [num_b,den_b]=tfdata(c2d(filtro_b,1/fs),'v'); yf_b=filter(num_b,den_b,y); N=length(yf_b); Pffty=abs(fft(yf_b))/N; f=(fs/2)*linspace(0,1,(N/2)+1); figure(2) plot(f,Pffty(1:(N/2)+1)) %% Implementeando filtros [Pasa Altas] [z_a,p_a,k_a]=butter(8,5000*2*pi,'high','s'); filtro_a=tf(zpk(z_a,p_a,k_a)) [num_ac,den_ac]=tfdata(filtro_a,'v'); [num_a,den_a]=tfdata(c2d(filtro_a,1/fs),'v'); yf_a=filter(num_a,den_a,y); N=length(yf_a); Pffty=abs(fft(yf_a))/N; f=(fs/2)*linspace(0,1,(N/2)+1); figure(3) plot(f,Pffty(1:(N/2)+1)) %% Implementeando filtros [rechaza Banda] [z_s,p_s,k_s]=butter(8,[4000*2*pi,6000*2*pi],'stop','s'); filtro_s=tf(zpk(z_s,p_s,k_s)) [num_sc,den_sc]=tfdata(filtro_s,'v'); [num_s,den_s]=tfdata(c2d(filtro_s,1/fs),'v'); yf_s=filter(num_s,den_s,y); N=length(yf_s); Pffty=abs(fft(yf_s))/N; f=(fs/2)*linspace(0,1,(N/2)+1); figure(4) plot(f,Pffty(1:(N/2)+1))

Programa 7
% Introducir una funcion de transferencia % tf(numerador,denominador,tiempo de muestreo) % (coeficentes de los polinomios de mayor a menor potencia fz1=tf([1],[1 2 3],1) impulse(fz1) % respuesta ante el impulso step(fz1) % respuesta ante el escalon unitario impulse(fz1,10) % obtener la respuesta en los primeros 10 segundos step(fz1,8)% obtener la respuesta en los primeros 8 segundos fz2=tf([1 0.1],[1 1 0.16],1) impulse(fz2,5) [y t]=impulse(fz2,5) %regresa los valores de y(k) % Residue calcula los residuos (Cauchy) [R,P,k]=residue([1 0.1],[1 1 0.16]) [p,z,k]=residue([10 1 0.1],[1 1 0.16]) % introducir una funcion de transferencia % factorizada ZPK fz4=zpk([-0.9],[-0.7 -0.8],1,1) %convertir representaciones tf(fz4) %convertir al espacio de estados ss(fz4)

Programa 8
clc clear all f1c=zpk([-1],[-3,-4],10.1) f1d=c2d(f1c,0.01,'matched') f2c=zpk([-0.5],[-2.5,-2],7.2) f2d=c2d(f2c,0.02,'matched') f3c=zpk([-2.5],[-0.5,-2],7.3) f3d_0=c2d(f3c,0.02,'zoh') f3d_1=c2d(f3c,0.02,'foh') f3d_i=c2d(f3c,0.02,'impulse') f3d_t=c2d(f3c,0.02,'tustin') f3d_m=c2d(f3c,0.02,'matched') [f3c_num,f3c_den]=tfdata(f3c,'v'); [f3d_0_num,f3d_0_den]=tfdata(f3d_0,'v'); [f3d_1_num,f3d_1_den]=tfdata(f3d_1,'v'); [f3d_i_num,f3d_i_den]=tfdata(f3d_i,'v'); [f3d_t_num,f3d_t_den]=tfdata(f3d_t,'v'); [f3d_m_num,f3d_m_den]=tfdata(f3d_m,'v');

f2c = 7.2 (s+0.5) ------------(s+2.5) (s+2) Continuous-time zero/pole/gain model. f2d = 0.13838 (z-0.99) --------------------(z-0.9512) (z-0.9608) Sample time: 0.02 seconds Discrete-time zero/pole/gain model.

Programa 9 Varios filtros

Programa 10

You might also like