Sei sulla pagina 1di 6

FACULTAD DE INGENIERA

LABORATORIO DE ANLISIS DE SEALES

Prctica de Laboratorio # 4 Aplicacin transformada de Fourier


Objetivos:

Disear programas para la generacin del espectro de una seal y su anlisis desde el
dominio de la frecuencia.

INTRODUCTION:
Effects of Signal Operations on DFT Spectrum: In this section, we summarize the formulas for
finding the DFTs of different versions of a signal from the DFT of the original one. They will be of
help in understanding the effect of self-repetition, zero-padding, zero-insertion, and so on.
Let the DFT of a finite-duration sequence x[n] be

Short-Time Fourier Transform Spectrogram


The short-time or short-term Fourier transform (STFT) breaks a long signal into small segments,
optionally overlapped and/or windowed, and finds the DFT of each (windowed) segment
separately to record the local spectra in a matrix with frequency/time indices:

where the window sequence w[m] is used to select a finite-length (local) segment from the
sliding sequence x[m + n] and possibly to reduce the spectral leakage.
Note that the frequency and time denoted by frequency index k and time index n of X[k, n] are

Where n is set to the center of the sliding window (Fig. 3.20(b)). If we take the STFT not for
every n but only for n = iM (a multiple of M), each segment gets overlapped with its
neighboring one(s) by Noverlap = N M samples.
Note that M determines the width of interval time between the DFT computations.
The MATLAB function spectrogram() can be used to find the STFT.
We run the above MATLAB program sig03f20.m to get the STFT X[k, n] of x[n] (Fig. 3.20(a)) as
depicted in Fig. 3.20(d1) (with DFT size N = 32 and Noverlap = 8) and (d2) (with N = 48 and
Noverlap = 12), which show that the frequency becomes higher as time goes by. Such a STFT
can be used to determine and display the spectrum of a non-stationary signal (such as speech
or music) whose frequency content changes with time.
clear, clf
T=0.1; Fs=1/T; % Sampling period and Sampling frequency
w1=25*pi/16; w2=30*pi/16; w3=40*pi/16; w4=60*pi/16;
n=[0:31]; x=[cos(w1*T*n) sin(w2*T*n) cos(w3*T*n) sin(w4*T*n)];
Nx=length(x); nn=0:Nx-1; % Length and duration (period) of the signal
N=32; kk=0:N/2; ff=kk*Fs/N; % DFT size and frequency range
wnd= hamming(N).; % Hamming window of length N
Noverlap=N/4; % the number of overlap
M=N-Noverlap; % the time spacing between DFT computations
for i=1:fix((Nx-Noverlap)/M)
xiw= x((i-1)*M+[1:N]).*wnd; % ith windowed segment
Xi= fft(xiw); % DFT X(k,i) of ith windowed segment
X(:,i)= Xi(kk+1).; % insert X(0:N/2,i) into the ith column
tt(i)=(N/2+(i-1)*M)*T;
end
% Use the MATLAB signal processing toolbox function specgram()
[X sp,ff1,tt1] = spectrogram(x,wnd,Noverlap,N,Fs,yaxis);
% Any discrepancy between the above result and spectrogram()?
discrepancy= norm(X-X sp)/norm(X sp)
figure(2), clf, colormap(gray(256));
subplot(221), imagesc(tt,ff,log10(abs(X))), axis xy
subplot(222), imagesc(tt1,ff1,log10(abs(X sp))), axis xy
% specgram(x,N,Fs,wnd,noverlap) in MATLAB of version 6.x

Now, comparing Fig. 3.20(d1) and (d2), let us consider the effect of segment or
window duration NT on the time and frequency resolutions of the STFT. We might
say that the time resolution is NT [sec] (the segment duration) and the frequency
resolution is 1/N T [Hz]. This implies that if we increase or decrease the segment
duration, the time/frequency resolution gets poorer/better or better/poorer, showing the
trade-off between the time and frequency resolutions. It is an illustration
of uncertainty principle (Remark 2.9(1)) that both time resolution and frequency
resolution cannot be improved. Although the boundary of the uncertainty principle
(best simultaneous resolution of both) is reached with a Gaussian window function,
the wavelet transform or multi-resolution analysis was devised, which can give a
good time/frequency resolution for high/low-frequency components.
Problems to solve:
Short-Time Fourier Transform (STFT). Using Spectrogram Let us use the MATLAB function
spectrogram() to find the STFT for some signals.
(a) Referring to the above program play music wave.m and the layout of a piano
keyboard depicted in Fig. P3.20.1(a), use the MATLAB routine music wave to produce
a sinusoidal wave for a series of musical notes shown in Fig. P3.20.1(b) where the
frequency for the central note A4 is 440 Hz and that for any other note is fn = 440
2(n49)/12[Hz] where n is the key number. (P3.20.1)
(b) Use the MATLAB function specgram (in MATLAB of version 6.x) or spectrogram (in
MATLAB of version 7.x) to find the STFT for the sinusoidal wave produced in (a). You can
change the DFT size from its default value N = 256 to 512 and then to 1024 and localize
the frequency range if you think it to be of help in distinguishing the distinct frequency
components. Which of the frequency and time resolutions do you gain or lose by
increasing the DFT size?
(c) Use the MATLAB Produce a beat-note signal by summing two sinusoids of slightly
different frequencies 495 Hz and 505 Hz as

Determine the FFT size (as a power of 2) such that the two frequencies are
distinguishable in the spectrogram. How about the DFT size N which makes the
frequency resolution

(cf.) For example, the spectrogram with N = 512 shows a single frequency of around 500 Hz varying in
amplitude with time, while that with N = 4096 reveals the two different frequencies with
constant amplitude.

%play music wave.m


clear, clf
Fs=10000; Ts=1/Fs; % 10kHz Sampling Frequency and Sampling period
Tw=2; % Duration of a whole note
melody rhythm= [40 42 44 45 47 49 51 52; 1/4 1/4 1/4 1/4 1/8 1/8 1/8 1/8];
[x,tt]= music wave(melody rhythm,Ts,Tw); sound(x,Fs)
N=256; wnd=N; Noverlap= N/2;
subplot(221), spectrogram(x,wnd,Noverlap,N,Fs,yaxis); % specgram(x)
colormap(gray(256)) % colormap(default)
function [wave,tt]=music wave(melody rhythm,Ts,Tw)
% Ts: Sampling period, Tw: duration for a whole note
% Copyleft: Won Y. Yang, wyyang53@hanmail.net, CAU for academic use only
if nargin<3, Tw=2; end
if nargin<2, Ts=0.0001; end
[M,N]= size(melody rhythm);
wave= []; tt=[]; pi2= 2*pi; phase= 0;
for i=1:N
t= [Ts:Ts:melody rhythm(2,i)*Tw];
if i==1, tt=[tt t]; else tt=[tt tt(end)+t]; end
w= pi2*440*2((melody rhythm(1,i)-49)/12); angle= w*t + phase;
wave= [wave sin(angle)]; phase= angle(end);
end

Potrebbero piacerti anche