You are on page 1of 25

Ideas geniales de una sola persona valen ms que

grandes grupos de investigadores con muchos


recursos.

Curso bsico de Procesamiento Digital de


Seales.
Herramienta de simulacin: MatLab

Ing. Robin Alvarez Rueda, MSc, PhD

E-Mail: arobin7es@yahoo.es / robin.alvarez@epn.edu.ec


DOMINIO DE LA FRECUENCIA

1. - La SERIE DE FOURIER CONTINUA


- La SERIE DE FOURIER DISCRETA
- La TRANSFORMADA DE FOURIER DISCRETA (DFT)
- La TRANSFORMADA RPIDA DE FOURIER (FFT)
- El PERIODOGRAMA (MDULO DE LA FFT)
- Conceptos y prctica se RESOLUCIN EN FRECUENCIA Y DETECCIN.

2. - CONSECUENCIA DE TENER DATOS FINITOS:


TEORA DE VENTANAS Y FUGA ESPECTRAL (Resolucin en frec y Deteccin)
- ALGUNOS TIPOS DE VENTANAS
- El PERIODOGRAMA MODIFICADO (Ejemplos de Resolucin en frec y Deteccin)

3. - MTODOS MEJORADOS DE PROMEDIADO PARA REDUCIR EL EFECTO DEL RUIDO:


MTODOS DE BARTLETT Y WELCH
4. - MTODOS TIEMPO FRECUENCIA
EL ESPECTROGRAMA
MTODOS TIEMPO FRECUENCIA
STFT (Short Time Fourier Transform)
EL ESPECTROGRAMA (mdulo de STFT)
WAVELETS
WIGNER-VILLE
CHOI WILLIAMS
MATCHING PURSUIT
ANLISIS FRECUENCIAL DE UNA SEAL NO ESTACIONARIA:

SEAL A ANALIZAR:

ESPECTROS EVALUADOS CON UNA VENTANA DESLIZANTE

....
PROBLEMA: VISUALIZACIN DE MUCHAS GRFICAS
EJEMPLO: Visualizacin de la seal cada t segundos (usando welch).

% Anlisis de la seal cada t segundos: incremento=0;

close all; for i=1:Num_porciones


clear all;
if fin<=length(x_filt)
porcion=1000; % Porcin de X puntos => analiza bloques de t= X/100 segundos for p=inicio:fin
x_porc(p,1)=x_filt(p+incremento,1);
fmax=50; % Frecuencia mxima de la seal end
fm=2*fmax; % Teorema de muestreo end
nFFT= 1024; % Zero-padding si nFFT mayor que longitud de ventana
LongVentana=100; % Aplicamos Welch a cada segmento:
Solapamiento=50; [P_welch,F_welch] =
pwelch(x_porc,LongVentana,Solapamiento,nFFT,fm);
%Lectura de datos:
load signal_1.mat; %Eje del tiempo:
x=A; tiempo=(1:porcion)/fm;
x1=x(1:6000); % solo analizar los primeros 6000 puntos o muestras
clear A x; figure
subplot(3,1,1)
% filtrado: plot(tiempo(1:porcion/2),x_porc(1:porcion/2))
WcN=[4 45]/fmax; axis([0.1 5 -50 50]);
[b,a]=butter(2,WcN); ylabel('TIME 0-5 SEC')
x_filt=filter(b,a,x1);
clear x1; subplot(3,1,2)
plot(tiempo((porcion/2+1):porcion),x_porc((porcion/2+1):porcion))
% SEPARAMOS EN PORCIONES DE 10 SEG (1000 MUESTRAS) Y LAS ANALIZAMOS. axis([5.01 10 -50 50]);
Num_porciones=0; ylabel('TIME 6-10 SEC')
Num_porciones=fix(length(x_filt)/porcion)
subplot(3,1,3)
inicio = 1 plot(frecNorm,P_welch,'b')
fin =porcion ylabel('DSP visto en porciones')
grid on
% EJE DE FRECUENCIA NORMALIZADO:
frecNorm=fm*(0:(nFFT/2))/nFFT;
frecNorm=frecNorm'; incremento=incremento+porcion;

end
Resultados:

PROBLEMA: VISUALIZACIN DE MUCHAS GRFICAS, NO ES PRCTICO. NECESITAMOS


UN MTODO QUE PERMITA VER EN UNA SOLA GRFICA LA EVOLUCIN DEL CONTENIDO
DE FRECUENCIAS EN FUNCIN DEL TIEMPO.
SOLUCIN:

La Transformada de Fourier de Tiempo Corto (Short-time Fourier transform, STFT)


o Transformada de Fourier de Trmino Reducido (short-term Fourier transform)
STFT en tiempo discreto: la informacin a ser transformada es dividida en pedazos o
tramas por medio de una ventana deslizante (que usualmente se traslapan unos con otros,
para reducir irregularidades en la frontera). Para cada pedazo se calcula la transformacin
de Fourier, y el resultado complejo se agrega a una matriz, que almacena magnitud y fase y
adems el tiempo en que fue calculada. Por lo anterior, se obtiene la evolucin del
espectro en funcin del tiempo. Matemticamente, se escribe como:
Matemticamente, se escribe como:

EL ESPECTROGRAMA :

Es la magnitud cuadrada de la STFT:


EL ESPECTROGRAMA
EN MATLAB:
COMPROMISO ENTRE:
RESOLUCIN EN FRECUENCIA
VS
RESOLUCIN EN TIEMPO
EJEMPLO 1: Analizar dos tonos continuos de 20 y 40 Hz con las siguientes
duraciones: VER LA RESOLUCIN EN TIEMPO Y EN FRECUENCIA.
RESOLUCIN: EL ESPECTROGRAMA REPRESENTADO EN 2D Y 3D

clear all; close all;


% El espectrograma en 2D:
fs = 500; % frecuencia de muestreo
N = 1024; % Longitud de la seal figure
f1 = 20; % Frecuencia del primer tono specgram(x,nFFT,fs,LongVentana,Solapamiento)
f2 = 40; % SFrecuencia del segundo tono colorbar('vert')
nFFT = 1024; %64; % 512; %64; % nFFT

% Ver COMPROMISO: resolucion tiempo - frecuencia: % EN 3D:


% Para un caso: mejorresolucion en tiempo y para [B,f,t] = specgram(x,nFFT,fs,LongVentana,Solapamiento);
% el otro, mejor resolucion en frecuencia B = abs(B); % Get spectrum magnitude
figure;
% ------------------------------------------------- mesh(t,f,B); % Plot Spectrogram as 3-D mesh
LongVentana=256; %32 view(160,40); % Change 3-D plot view
Solapamiento=128; %16 axis([0 2 0 100 0 20]); % Example of axis and
% ------------------------------------------------- xlabel('Time (sec)'); % labels for 3-D plots
ylabel('Frequency (Hz)');
% Construct a step change in frequency figure
tn = (1:N/4)/fs; % Time vector used to create sinusoids contour(t,f,B); % Plot spectrogram as contour plot
x = [zeros(N/4,1); sin(2*pi*f1*tn)'; sin(2*pi*f2*tn)';... % ....labels and axis....
zeros(N/4,1)];
t = (1:N)/fs; % Time vector used to plot
plot(t,x,'k');
% ....labels....
LongVentana=256; Solapamiento=128;

LongVentana=32; Solapamiento=16;
CONCLUSIN:
Al aumentar la longitud de la ventana deslizant, se
mejora la RF pero obviamente se pierde en RT (caso
lmite: una sola ventana que correspondera al
periodograma simple donde tenemos la mxima RF pero
ya no existe informacin del tiempo (RT ya no existe).
DEBER (PASO A PASO)
Crear la seal en el tiempo y luego realizar el
anlisis TIEMPO-FRECUENCIA de modo que se
obtengan las siguientes grficas tiempo-
frecuencia:
a)

b)
MEZCLANDO RF, DETECCIN, RUIDO Y RT.
ANLISIS ESPECTRAL CON
PERIODOGRAMA SIMPLE,
PERIODOGRAMA MODIFICADO (BH4T),
WELCH (PORCIN =10%)
TIEMPO - FRECUENCIA

EJEMPLO:

Duracion = 10 segundos
A= 1,0.5,0.1,0.01,0.001,0.001,0.01,0.1,0.5,1
F = 100, 101, 110, 111, 120, 121, 130, 131, 140, 141
clc, close all , clear all;

duracion = 10;
fmax=145;
Fs=10*fmax;
t=1/Fs:1/Fs: duracion; % Duracin 10seg

xn1=1*sin(2*pi*100*t)+0.5*sin(2*pi*100.5*t)+...
0.1*sin(2*pi*110*t)+0.01*sin(2*pi*110.5*t)+...
0.001*sin(2*pi*120*t)+0.001*sin(2*pi*120.5*t)+...
0.01*sin(2*pi*130*t)+0.1*sin(2*pi*130.5*t)+...
0.5*sin(2*pi*140*t)+1*sin(2*pi*140.5*t); % + 0.5*randn(size(t));

plot(t,xn1);
title('xn original existente entre 0 y 10 segundos (SIN RUIDO) ')

xn2=(t>=2 & t<=8).*xn1;


figure
plot(t,xn2);
title('xn original existente entre 0 y 8 segundos (SIN RUIDO) ')

xn = xn2 + 0.001*randn(size(t));
figure
plot(t,xn);
title('xn existente entre 2 y 8 segundos y CON RUIDO = 0.001 ')

sound(xn,Fs);
N = length(xn) figure
subplot(3,1,1)
%PERIODOGRAMA SIMPLE plot(f_periodograma,10*log10(Pxx1),'k');
nFFT=2; axis([0 Fs/2 0 max(10*log10(Pxx1))]);
xlabel('Frecuencia (Hz)');
while nFFT<N ylabel('Potencia');
nFFT = nFFT*2; title('PERIODOGRAMA SIMPLE')
end grid minor

% PERIODOGRAMA SIMPLE y MODIFICADO: subplot(3,1,2)


plot(f_periodograma,10*log10(Pxx2),'r');
% 1. GENERACION DE VENTANAS: axis([0 Fs/2 0 max(10*log10(Pxx2))]);
window_1=rectwin(length(xn)); xlabel('Frecuencia (Hz)');
window_2=blackmanharris(length(xn)); ylabel('Potencia');
title('PERIODOGRAMA MODIFICADO(BH4T)')
grid minor
% 2. Enventanado de la senial temporal:
y1_enventanada=xn.*window_1'; % ---------------------------------------------------
y2_enventanada=xn.*window_2';
figure
plot(t,y2_enventanada);
title('xn enventanada con BH4T ')

% 3. Periodograma modificado:
Pxx1=abs(fft(y1_enventanada,nFFT));
Pxx2=abs(fft(y2_enventanada,nFFT));

%Eje de frecuencias:
f_periodograma=linspace(0,Fs,nFFT);
RESULTADO (NIVEL DE RUIDO: 0.001)

- El periodograma modificado (con BH4T) muestra mejores resultados que el Period. Simple.
- Welch s reduce la fuga espectral pero obtiene muy malos resultados.
% ---------------------------------------------------

% ANALISIS TIEMPO-FRECUENCIA:
% El espectrograma:

% La ventana deslizante es de longitud (10%) como en


WELCH:
LongVentana = fix(length(xn)/10);

%SOLAPAMIENTO = 50%
Solapamiento=fix(LongVentana/2);

figure
specgram(xn,nFFT_welch,Fs,LongVentana,Solapamiento)
colorbar('vert')
title('ESPECTROGRAMA: PORCIN DEL 10%')

ZOOM
Se puede apreciar que las seniales
existen entre (2 y 8) segundos. Sin
embargo, con esta longitud de
ventana no se puede distinguir que
existan tonos juntos
DEBER

a) Generar una chirp (desde 1000 Hz hasta 10 KHz en 10


segundos) y realizar el anlisis tiempo frecuencia.
b) Ahora generar dos chirps con parmetros similares a la
anterior y lo ms cercanas posible y realizar el anlisis
tiempo frecuencia considerando los problemas de
resolucin en frecuencia y de tiempo.

You might also like