











Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!












2 clear ; clc ; close all ; 3 4 5 fc = 1 e9 ; % Frecuencia de portadora : 1 GHz 6 P_dBm = -50; % Potencia en dBm 7 R_load = 50; % Impedancia de referencia [ Ohm ] 8 9 % --- Conversion de potencia a tension pico --- 10 % P [ W ] = 10^( P_dBm /10) * 1e - 11 P_W = 10^( P_dBm /10) * 1e -3; % Potencia en Watts 12 V_rms = sqrt ( P_W * R_load ) ; % Tension RMS [ V ] 13 Vpico = V_rms * sqrt (2) ; % Tension pico [ V ] 14 15 fprintf ( ’ Tension pico : %.4e V \ n ’ , Vpico ) ; 16 % Resultado esperado : ~31.6 uV 17 18 % --- Parametros de muestreo --- 19 % Para capturar 1 GHz se necesita fs >= 2 GHz ( Nyquist ) 20 % Usamos 10 x la portadora para buena resolucion espectral 21 fs = 10 e9 ; % Frecuencia de muestreo : 10 GHz 22 T_sim = 1e -6; % Duracion : 1 microsegundo (1000 ciclos a 1 GHz ) 23 t = 0:1/ fs : T_sim -1/ fs ; % Vector de tiempo 24 25 % --- Generacion de la s e a l --- 26 s = Vpico * cos (2* pi * fc * t ) ; 27 28 % --- Calculo de la FFT --- 29 N = length ( s ) ; % Numero de muestras 30 S = fft ( s ) ; % FFT compleja 31 f = (0: N -1) * ( fs / N ) ; % Vector de frecuencias [ Hz ] 32 33 % --- Conversion a espectro unilateral y dBm --- 34 % Se duplican las componentes de frecuencia positiva ( excepto DC y Nyquist ) 35 S_mag = abs ( S / N ) ; 36 S_mag (2: end -1) = 2 * S_mag (2: end -1) ; % Espectro unilateral 37 38 % Conversion de magnitud de tension a potencia en dBm 39 % P = V ^2 / (2* R ) para s e a l sinusoidal ( factor 2 = valor RMS ) 40 S_dBm = 10* log10 ( ( S_mag .^2 / 2) / R_load / 1e -3 + eps ) ; 41 % eps se agrega para evitar log (0) en zonas sin s e a l 42
43 % --- Grafico del espectro --- 44 figure ( ’ Name ’ , ’ Tarea 1 A - S e a l Sinusoidal ’ , ’ NumberTitle ’ , ’ off ’ ,... 45 ’ Position ’ ,[100 100 800 450]) ; 46 47 plot ( f /1 e9 , S_dBm , ’b - ’ , ’ LineWidth ’ , 1.2) ; 48 xlim ([0.98 1.02]) ; % Rango : + -20 MHz alrededor de fc 49 ylim ([ -120 -30]) ; % Rango de amplitud en dBm 50 xlabel ( ’ Frecuencia [ GHz ] ’ , ’ FontSize ’ , 12) ; 51 ylabel ( ’ Amplitud [ dBm ] ’ , ’ FontSize ’ , 12) ; 52 title ( ’ Espectro de s e a l sinusoidal | fc =1 GHz | P = -50 dBm ’ , ... 53 ’ FontSize ’ , 13) ; 54 grid on ; 55 56 % Agregar marcador en el pico 57 [ pico_val , pico_idx ] = max ( S_dBm (1: floor ( N /2) ) ) ; 58 f_pico = f ( pico_idx ) ; 59 hold on ; 60 plot ( f_pico /1 e9 , pico_val , ’ rv ’ , ’ MarkerSize ’ , 10 , ... 61 ’ MarkerFaceColor ’ , ’r ’) ; 62 text ( f_pico /1 e9 + 0.002 , pico_val + 2 , ... 63 sprintf ( ’ %.1f dBm @ %.3f GHz ’ , pico_val , f_pico /1 e9 ) , ... 64 ’ FontSize ’ , 9 , ’ Color ’ , ’ red ’) ; 65 legend ( ’ Espectro ’ , ’ Pico detectado ’ , ’ Location ’ , ’ northeast ’) ;
44 45 S_mag = abs ( S / N ) ; 46 S_mag (2: end -1) = 2 * S_mag (2: end -1) ; 47 S_dBm = 10* log10 ( ( S_mag .^2 / 2) / R_load / 1e -3 + eps ) ; 48 49 % --- Grafico del espectro AM --- 50 figure ( ’ Name ’ , ’ Tarea 1 B - S e a l AM ’ , ’ NumberTitle ’ , ’ off ’ ,... 51 ’ Position ’ ,[100 100 900 500]) ; 52 53 plot ( f /1 e9 , S_dBm , ’b - ’ , ’ LineWidth ’ , 1.0) ; 54 % Zoom alrededor de la portadora : + -300 kHz 55 xlim ([( fc -300 e3 ) /1 e9 ( fc +300 e3 ) /1 e9 ]) ; 56 ylim ([ -120 -30]) ; 57 xlabel ( ’ Frecuencia [ GHz ] ’ , ’ FontSize ’ , 12) ; 58 ylabel ( ’ Amplitud [ dBm ] ’ , ’ FontSize ’ , 12) ; 59 title ( ’ Espectro AM | fc =1 GHz | fm =100 kHz | m =20 % ’ , ’ FontSize ’ , 13) ; 60 grid on ; 61 62 % --- Marcadores en los 3 picos esperados --- 63 % Frecuencias teoricas de los componentes 64 f_teoricas = [ fc - fm , fc , fc + fm ]; % [ Hz ] 65 nombres = { ’ LSB ’ , ’ Portadora ’ , ’ USB ’ }; 66 67 hold on ; 68 for k = 1: 69 % Buscar el indice mas cercano a cada frecuencia teorica 70 [~ , idx ] = min ( abs ( f - f_teoricas ( k ) ) ) ; 71 plot ( f ( idx ) /1 e9 , S_dBm ( idx ) , ’ rv ’ , ’ MarkerSize ’ , 11 , ... 72 ’ MarkerFaceColor ’ , ’r ’) ; 73 text ( f ( idx ) /1 e9 , S_dBm ( idx ) +3 , nombres { k } , ... 74 ’ HorizontalAlignment ’ , ’ center ’ , ’ FontSize ’ ,9 , ’ Color ’ , ’ red ’) ; 75 end 76 77 legend ( ’ Espectro AM ’ , ’ Componentes ’ , ’ Location ’ , ’ northeast ’) ; 78 79 % --- Calculo de diferencia de amplitud entre portadora y laterales
80 [~ , idx_fc ] = min ( abs ( f - fc ) ) ; 81 [~ , idx_usb ] = min ( abs ( f - ( fc + fm ) ) ) ; 82 diff_dB = S_dBm ( idx_fc ) - S_dBm ( idx_usb ) ; 83 fprintf ( ’ Diferencia portadora - lateral medida : %.2f dB \ n ’ , diff_dB ) ; 84 fprintf ( ’ Diferencia portadora - lateral teorica : %.2f dB \ n ’ ,
37 f_env = (0: N_env -1) * ( fs_env / N_env ) ; % [ Hz ] 38 39 E_mag = abs ( E / N_env ) ; 40 E_mag (2: end -1) = 2 * E_mag (2: end -1) ; 41 E_dB = 20* log10 ( E_mag + eps ) ; % Amplitud en dB 42 43 % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 44 % SIMULACION DEL EFECTO DEL RBW 45 % Se modela el RBW como una convolucion con una ventana gaussiana 46 % en el dominio espectral , que representa la respuesta del filtro FI 47 % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 48 49 % Resolucion espectral de la FFT [ Hz / bin ] 50 delta_f = fs_env / N_env ; 51 52 % --- Funcion para aplicar RBW gaussiano --- 53 % El filtro RBW tiene respuesta en frecuencia gaussiana : 54 % H ( f ) = exp ( - f ^2 / (2* sigma_f ^2) ) 55 % FWHM ( ancho a -3 dB ) = 2* sqrt (2* ln2 ) * sigma_f = RBW 56 57 rbw_valores = [5000 , 1000 , 500]; % RBW a probar : 5 kHz , 1 kHz , 500 Hz 58 titulos = { ’ RBW = 5 kHz ( NO resuelve --- tonos fusionados ) ’ , ... 59 ’ RBW = 1 kHz ( LIMITE --- tonos apenas distinguibles ) ’ , ... 60 ’ RBW = 500 Hz ( SI resuelve --- tonos claramente separados ) ’ }; 61 62 figure ( ’ Name ’ , ’ Tarea 2 - Efecto del RBW ’ , ’ NumberTitle ’ , ’ off ’ ,... 63 ’ Position ’ ,[50 50 1000 750]) ; 64 65 for k = 1: 66 RBW = rbw_valores ( k ) ; 67 68 % Calcular sigma en bins espectrales 69 % FWHM = 2* sqrt (2* ln2 ) * sigma = > sigma = FWHM /(2* sqrt (2* ln2 ) ) 70 sigma_f = RBW / (2* sqrt (2* log (2) ) ) ; % sigma en Hz 71 sigma_bins = sigma_f / delta_f ; % sigma en bins 72 73 % Crear kernel gaussiano centrado 74 half_win = ceil (4 * sigma_bins ) ; 75 n_gauss = ( - half_win : half_win ) ; 76 gauss_kernel = exp ( - n_gauss .^2 / (2* sigma_bins ^2) ) ; 77 gauss_kernel = gauss_kernel / sum ( gauss_kernel ) ; % Normalizar 78 79 % Convolucionar el espectro con el kernel ( simula el filtrado del SA ) 80 E_rbw = conv ( E_mag , gauss_kernel , ’ same ’) ; 81 E_rbw_dB = 20* log10 ( E_rbw + eps ) ; 82 83 % --- Grafico para cada RBW --- 84 subplot (3 , 1 , k ) ; 85 plot ( f_env /1 e3 , E_rbw_dB , ’b - ’ , ’ LineWidth ’ , 1.5) ; 86 xlim ([0 25]) ; % Mostrar zona 0 a 25 kHz 87 ylim ([ -60 0]) ; 88 xlabel ( ’ Frecuencia [ kHz ] ’ , ’ FontSize ’ , 10) ; 89 ylabel ( ’ Amplitud [ dB ] ’ , ’ FontSize ’ , 10) ; 90 title ( titulos { k } , ’ FontSize ’ , 11) ; 91 grid on ;
92 93 % Marcar las frecuencias de los tonos 94 hold on ; 95 xline ( fm1 /1 e3 , ’r - - ’ , ’ LineWidth ’ , 1.2) ; % Tono 1 en 10 kHz 96 xline ( fm2 /1 e3 , ’g - - ’ , ’ LineWidth ’ , 1.2) ; % Tono 2 en 11 kHz 97 legend ( ’ Espectro ’ , sprintf ( ’ fm1= %d kHz ’ , fm1 /1 e3 ) , ... 98 sprintf ( ’ fm2= %d kHz ’ , fm2 /1 e3 ) , ... 99 ’ Location ’ , ’ northeast ’ , ’ FontSize ’ ,8) ; 100 end 101 102 sgtitle ( ’ Efecto del RBW sobre la resolucion espectral ’ ,... 103 ’ FontSize ’ , 14 , ’ FontWeight ’ , ’ bold ’) ;
38 f_env = (0: N_env -1) * ( fs_env / N_env ) ; 39 40 E_mag = abs ( E / N_env ) ; 41 E_mag (2: end -1) = 2 * E_mag (2: end -1) ; 42 E_dB = 20* log10 ( E_mag + eps ) ; 43 44 delta_f = fs_env / N_env ; % Resolucion espectral [ Hz ] 45 fprintf ( ’ Resolucion espectral FFT : %.2f Hz \ n ’ , delta_f ) ; 46 47 % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 48 % COMPARACION : RBW adecuado vs RBW inadecuado 49 % RBW adecuado ( < 400 Hz ) : el tono deberia ser visible 50 % RBW inadecuado ( > 400 Hz ) : el tono queda dentro de la pollera 51 % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 52 rbw_list = [200 , 400 , 1000]; % [ Hz ] 53 colores = { ’b ’ , ’g ’ , ’r ’ }; 54 labels = { ’ RBW =200 Hz ( < 400 Hz , resolucion OK ) ’ , ... 55 ’ RBW =400 Hz (= separacion , limite exacto ) ’ , ... 56 ’ RBW =1 kHz ( > 400 Hz , tono oculto ) ’ }; 57 58 figure ( ’ Name ’ , ’ Tarea 3 - Sensibilidad ’ , ’ NumberTitle ’ , ’ off ’ ,... 59 ’ Position ’ ,[50 50 1000 700]) ; 60 61 % --- Panel 1: Espectro sin filtrar ( FFT pura = RBW infinitesimal )
62 subplot (2 ,2 ,1) ; 63 stem ( f_env (1:200) /1 e3 , E_dB (1:200) , ’b. ’ , ’ MarkerSize ’ , 4) ; 64 xlim ([0 2]) ; ylim ([ -120 20]) ; 65 xlabel ( ’ Frecuencia [ kHz ] ’) ; ylabel ( ’ dB ’) ; 66 title ( ’ Espectro FFT sin filtrar ( RBW ideal ) ’ , ’ FontSize ’ , 10) ; 67 grid on ; 68 % Marcar el tono modulante 69 hold on ; 70 xline ( fm /1 e3 , ’r - - ’ , ’ LineWidth ’ , 1.5) ; 71 text ( fm /1 e3 +0.05 , E_dB ( round ( fm / delta_f ) +1) +5 ,... 72 sprintf ( ’ fm = %.0 f Hz \ n %.1f dB ’ , fm , E_dB ( round ( fm / delta_f ) +1) ) ,... 73 ’ FontSize ’ , 8 , ’ Color ’ , ’ red ’) ; 74 75 % --- Paneles 2 -4: Con distintos RBW --- 76 for k = 1: 77 RBW = rbw_list ( k ) ; 78 79 % Modelo gaussiano del filtro FI ( RBW ) 80 sigma_f = RBW / (2* sqrt (2* log (2) ) ) ; 81 sigma_bins = sigma_f / delta_f ; 82 half_win = ceil (5 * sigma_bins ) ; 83 n_gauss = ( - half_win : half_win ) ; 84 gauss_k = exp ( - n_gauss .^2 / (2* sigma_bins ^2) ) ; 85 gauss_k = gauss_k / sum ( gauss_k ) ; 86 87 % Aplicar filtrado ( simula el filtro FI del SA ) 88 E_rbw = conv ( E_mag , gauss_k , ’ same ’) ; 89 E_rbw_dB = 20* log10 ( E_rbw + eps ) ; 90 91 subplot (2 , 2 , k +1) ; 92 plot ( f_env (1:400) /1 e3 , E_rbw_dB (1:400) , colores { k } , ’ LineWidth ’ , 1.5) ;
93 xlim ([0 2]) ; ylim ([ -120 20]) ; 94 xlabel ( ’ Frecuencia [ kHz ] ’) ; ylabel ( ’ dB ’) ; 95 title ( labels { k } , ’ FontSize ’ , 9) ; 96 grid on ; hold on ; 97 xline ( fm /1 e3 , ’k - - ’ , ’ LineWidth ’ , 1.2) ; 98 99 % Indicar si el tono es visible o no 100 idx_fm = round ( fm / delta_f ) + 1; 101 idx_dc = 1; 102 diferencia = E_rbw_dB ( idx_dc ) - E_rbw_dB ( idx_fm ) ; 103 if RBW < fm 104 visible = ’ VISIBLE ’; 105 col_txt = ’ blue ’; 106 else 107 visible = ’ OCULTO por pollera ’; 108 col_txt = ’ red ’; 109 end 110 text (0.8 , -90 , sprintf ( ’ Tono : %s \ nDif : %.1f dB ’ , visible , diferencia ) ,... 111 ’ FontSize ’ , 8 , ’ Color ’ , col_txt ,... 112 ’ BackgroundColor ’ , ’ white ’ , ’ EdgeColor ’ , col_txt ) ; 113 end 114 115 sgtitle ( ’ Sensibilidad del SA : efecto del RBW sobre el tono de 400 Hz ’ ,... 116 ’ FontSize ’ , 13 , ’ FontWeight ’ , ’ bold ’) ; 117 118 % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 119 % ANALISIS DEL FACTOR DE FORMA ( sensibilidad del filtro ) 120 % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 121 fprintf ( ’\n - - - Analisis del Factor de Forma - - -\ n ’) ; 122 fprintf ( ’ Separacion portadora - lateral : %d Hz \ n ’ , fm ) ; 123 fprintf ( ’ RBW maximo ( resolucion ) : %d Hz \ n ’ , fm ) ; 124 fprintf ( ’ Con factor de forma 15:1:\ n ’) ; 125 fprintf ( ’ BW_60dB = 15 * RBW \ n ’) ; 126 fprintf ( ’ Para que el tono NO quede en la pollera a 60 dB :\ n ’) ; 127 fprintf ( ’ Separacion > BW_60dB /2 = 7.5 * RBW = %.0f Hz \ n ’ , 7.5* fm ) ;