Practical Signal Processing Concepts and Algorithms using MATLAB
description
Transcript of Practical Signal Processing Concepts and Algorithms using MATLAB
Spectral Analysis of Signals
3-1
Practical Signal Processing Concepts and Algorithms using MATLAB
Spectral Analysis of Signals_________________________________________________________________________________________________________
_
QMS Management Consultants Sdn Bhd (401766-U)
98-1-31 Prima Tanjung Jalan Fettes Tanjung Tokong 11200 Pulau Pinang Malaysia
Telephone +604 899 6020 Facsimile +604 899 4020 E-mail [email protected]
11203 FM 2222 #801 Austin Texas 78730
Spectral Analysis of Signals
3-2
Section Outline
• Signal statistics• Discrete Fourier transform• Power spectral density estimation• Time-varying spectra
Spectral Analysis of Signals
3-3
Statistical Signal Processing
System
time
time
time
ens
em
ble
Spectral Analysis of Signals
3-4
Example: Crosscorrelation
x
y
)()( dnxny
>> [c,lags] = xcorr(x,y)>> stem(lags,c)
Spectral Analysis of Signals
3-5
Correlation and CovarianceThe functions xcorr and xcov estimate the cross-correlation and cross-covariance sequences of random processes.
The cross-correlation sequence is a statistical quantity defined as
where xn and yn are stationary random processes, , and E{·} is the
expected value operator which measures the similarity between the two waveforms.The covariance sequence is the mean-removed cross-correlation sequence
,
Spectral Analysis of Signals
3-6
or, in terms of the cross-correlation,
Example on xcorrExample on xcorr
>> y = x; >> x = [1 1 1 1 1]'; >> xyc = xcorr(x,y)
>> stem(xyc)
Example on xcovExample on xcov
>>ww = randn(1000,1); % Generate uniform noise with
%mean = 1/2.
>> [cov_ww,lags] = xcov(ww,10,'coeff');
>> stem(lags,cov_ww)
Spectral Analysis of Signals
3-7
Discrete Fourier Transform (DFT)
Discrete Fourier Transform:
1
011
n
jj
jkk yY
nie /2
Complex nth roots of unity Signal y (top) and transform Y (bottom)
Spectral Analysis of Signals
3-8
Fast Fourier Transform (FFT)
EfficientDFT
Pad /Chop
y Y
Y = fft(y,n)Window length length(y)
FFT length n
fast
Buffer
FFT
Spectral Analysis of Signals
3-9
Fast Fourier Transform (FFT)
• The discrete Fourier transform, or DFT, is the primary tool of digital signal processing.
• The foundation of the Signal Processing Toolbox is the fast Fourier transform (FFT), a method for computing the DFT with reduced execution time.
• Many of the toolbox functions (including z-domain frequency response, spectrum and cepstrum analysis, and some filter design and implementation functions) incorporate the FFT.
Spectral Analysis of Signals
3-10
Cont.
t = (0:0.001:1); %0.001 is sampling
x = sin(2*pi*50*t) + 2*sin(2*pi*120*t);
y = fft(x); %Compute DFT of x
m = abs(y); %magnitude
f = (0:length(y)/2-1)*1000/length(y); %Frequency vector
plot(f,m(1:1:(length(m)-1)/2)) %before filter
grid
[b,a] = butter(9,100/500,'high'); %design filter
c=filter(b,a,x); %implement filter
figure(2)
y = fft(c); %Compute DFT of c(filtered x)
m = abs(y); % Magnitude
f = (0:length(y)/2-1)*1000/length(y); %Frequency vector
plot(f,m(1:1:(length(m)-1)/2)) %after filter
Grid
Spectral Analysis of Signals
3-11
Spectral Analysis with the FFT
y Sampled signal
Fs Samples/unit time
n = length(y) Number of samples
t = (0:n-1)/Fs Principal range
dt = 1/Fs Time increment
Y = fft(y) DFT of sampled signal
abs(Y) Amplitude of DFT
abs(Y).^2/length(Y) Power of DFT
f = (0:n-1)*(Fs/n) Frequency (cycles/unit time)
(n/2)*(Fs/n) = Fs/2 Nyquist frequency
p = 1./f Period (unit time/cycle)
Spectral Analysis of Signals
3-12
FFT Example
>> Fs = 100;>> t = 0:1/Fs:10-1/Fs;>> y = sin(2*pi*15*t) + sin(2*pi*30*t);>> Y = fft(y,512);>> f = (0:length(Y)-1)*(Fs-1)/length(Y);>> Power = Y.*conj(Y)/length(Y);>> plot(f,Power)>> title('Periodogram')
Symmetric about Fs/2 = 50
Use fftshift to center at 0
Spectral Analysis of Signals
3-13
FFT Demos >> sigdemo1>> playshow fftdemo>> phone>> playshow sunspots
Spectral Analysis of Signals
3-14
Aliasing Revisited
5 Hz sine wave sampled at 15 Hz 5 Hz sine wave sampled at 7.5 Hz
Original signal
Spectral copy
Principal range Principal range
No overlap/aliasing Overlap/aliasing
+Fs
-Fs -Fs
+Fs
Spectral Analysis of Signals
3-15
Power Spectral Density (PSD)
Nonparametric Parametric
Welchpwelch
Multitaperpmtm
Yule-Walker
pyulearMUSICpmusic
Estimate PSD from a finite sample
Subspace
Burg pburg
EVpeig
Ryy( f ) is the DFT of the autocorrelation function ryy(t)
Ryy( f )
Total signal power of analog signal y = y
yy dffR )(
Spectral Analysis of Signals
3-16
Nonparametric Methods
• Periodogram
>> [Pxx,w] = periodogram(x)
• Welch
>> [Pxx,w] = pwelch(x)
• Multitaper
>> [Pxx,w] = pmtm(x,nw)
Spectral Analysis of Signals
3-17
Parametric Methods
• Yule-Walker AR Method
>> [Pxx,f] = pyulear(x,p,nfft,fs)
• Burg Method
>> [Pxx,f] = pburg(x,p,nfft,fs)
• Covariance and Modified Covariance Methods
>> [Pxx,f] = pcov(x,p,nfft,fs)
>> [Pxx,f] = pmcov(x,p,nfft,fs)
Order of AR model
Spectral Analysis of Signals
3-18
Parametric Methods (Continued)
Burg Covariance Modified Covariance Yule-Walker
Characteristics No windowing No windowing No windowing Applies window to data
Minimizes forward and backward prediction errors
Minimizes forward prediction error
Minimizes forward and backward prediction errors
Minimizes forward prediction error
Advantages High resolution for short data sets
Better resolution than Y-W for short data sets
High resolution for short data sets
As good as other methods for large data sets
Model always stable Able to extract frequencies from data consisting of p or more pure sinusoids
Able to extract frequencies from data consisting of p or more pure sinusoids
Model always stable
No spectral line-splitting
Disadvantages Peak locations sensitive to initial phase
Model can be unstable Model can be unstable Performs relatively poorly for short data sets
Spectral line-splitting for sinusoids in noise, or very large p
Frequency bias for sinusoids in noise
Peak locations slightly dependent on initial phase
Frequency bias for sinusoids in noise
Frequency bias for sinusoids in noise
Minor frequency bias for sinusoids in noise
Conditions for Nonsingularity
p must be ≤ 1/2 the input frame size
p must be ≤ 2/3 the input frame size
Autocorrelation matrix always nonsingular
Spectral Analysis of Signals
3-19
Subspace Methods
• Eigenvector Method
>> [S,f] = peig(x,p,nfft,fs)
• Multiple Signal Classification (MUSIC) Method
>> [S,f] = pmusic(x,p,nfft,fs)
Spectral Analysis of Signals
3-20
Spectrum Viewer in SPTool
1. Select signal in Signal Viewer in SPTool.2. Select Create Spectra Spectrum Viewer.
Display window
Analysis method
Spectral Analysis of Signals
3-21
Time-Varying Spectra
>> [B,f,t] = specgram(x,nfft,fs,window,numoverlap)
Spectral Analysis of Signals
3-22
Spectrogram Demos
>> specgramdemo>> xpsound
Spectral Analysis of Signals
3-23
Example: Reduced Sampling Rate
>> HAL9000