MATLAB SignalProcessing
MATLAB SignalProcessing
MATLAB SignalProcessing
12/11/2014
A Training Session on
PART I
Study of Signals, Systems and Transforms
60 Minutes (2:00 pm 3:00 pm)
pm)
12 November 2014
12/11/2014
Outline
Related Toolboxes & Built-in Functions
Signals in MATLAB Environment
Correlation & Convolution
Laplace Transform
Z-Transform
Circular Convolution and Parsevals Theorem
Systems Impulse Response & Frequency Response
Transfer Function and Pole-Zero Plots
12 November 2014
Statistics Toolbox
Wavelet Toolbox
Optimization Toolbox
RF Toolbox
12 November 2014
12/11/2014
exp()
dirac()
sinc()
erf()
erfc()
gamma()
xcorr()
corr()
laplace()
ztrans()
fft()
dct()
hilbert()
12 November 2014
filter()
conv()
cconv()
impz
step()
freqz()
fir1()
firpm()
butter()
buttord()
cheby1()
cheby2()
sptool()
12/11/2014
12 November 2014
12/11/2014
%12.8f\n',y);
fclose(fid);
wavwrite(s,fs,au.wav) / sound(s,fs)
save(filename,
(
, var)
)
save menu
12 November 2014
t = 1:20;
;
a = 0.2;
x = exp(a*t);
plot(x);
Define the time span
Define other parameters
Generate the signal and plot it
10
12/11/2014
n = 1:20;
;
a = 0.2;
x = exp(a*n);
stem(x);
Define sampling instants
Define other parameters
Generate the signal and plot it
11
12
12/11/2014
Autocorrelation function
ACF is given by c = xcorr(x), where x is a vector
when x is an M x N matrix, is a large matrix with 2*M 1 rows whose
N^2 columns contain the cross-correlation sequences for all combinations
of the columns of x
The zeroth lag of the output correlation is in the middle of the sequence, at
element or row M
>> x = 1:5
>> c = xcorr(x)
yields c = [5.0 14.0 26.0 40.0 55.0 40.0 26.0 14.0 5.0 ]
12 November 2014
13
Linear Correlation
Linear or Rank Correlation : corr(x)
Returns a P x P matrix containing the pairwise linear correlation
coefficient between each pair of columns in the N x P matrix x
rho = corr(x,y) returns a P1 x P2 matrix containing the pairwise
correlation coefficient between each pair of columns in the N x P1 and
N x P2 matrices x and y
[rho,
[rho pval] = corr(x,y)
corr(x y) also returns a pval,
pval a matrix of pp
values for testing the hypothesis of no correlation against the alternative
that there is a non-zero correlation
Each element of pval is the p-value for the corresponding element of rho
12 November 2014
14
12/11/2014
= corr(x,y)
gives
>> rho =
0
>> pval =
12 November 2014
15
16
12/11/2014
17
18
12/11/2014
Laplace Transform
Laplace Transform : laplace(); Inverse LT : ilaplace()
>> syms t n
>> f = t^2;
>> disp(f);
>> F = laplace(f);
>> disp(F);
>> disp('Inverse Laplace transform is')
>> f1 = ilaplace(F);
>> disp(f1);
12 November 2014
19
Z-Transform
Z-Transform : ztrans(); Inverse ZT : iztrans()
>> x = 0.5^n;
>> disp(x);
>> X = ztrans(x);
>> disp(X);
>> disp('Inverse Z-Transform is');
>> x1 = iztrans(X);
>> disp(x1);
12 November 2014
20
10
12/11/2014
21
Circular Convolution
Modulo-N circular convolution : cconv()
c = cconv(x, y, N) circularly convolves vectors x and y.
c is of length N. If omitted, N defaults to length(x) + length(y) 1
When N = length(x) + length(y) 1, the circular convolution is
equivalent to the linear convolution computed by conv()
>> a = [1
2 -1
1];
>> b = [1
1];
>> c = cconv(a,b,11)
>> cref = conv(a,b)
12 November 2014
22
11
12/11/2014
Parsevals Theorem
The energy of a signal/sequence is a constant, irrespective of the domain
Steps:
Find out the energy in time domain
Transform the signal to frequency domain
Find out the energy of the spectra
Both values should be the same
>>
>>
>>
>>
x
e
X
E
=
=
=
=
[2 1 -2
2 3 4 -3
3 1 2];
2]
sum(x.^2);
% Energy from samples
fft(x);
sum(abs(X).^2)/8; % Energy from spectra
12 November 2014
23
12 November 2014
24
12
12/11/2014
25
12 November 2014
26
13
12/11/2014
Alternate Method
>> b = [0.0013 0.0064 0.0128 0.0128 0.0064 0.0013];
>> a = [1 -2.9754 3.8060 -2.5453 0.8811 -0.1254];
>> h = impz(b,a); N = 1024;
>> sh = fft(h,N);
>> f = [0:N/2-1]*2/N; % Frequency Normalization
>> subplot(2 1 1)
>> plot(f,20*log10(abs(sh(1:N/2))));
plot(f 20*log10(abs(sh(1:N/2))));
>> p=unwrap(angle(sh))*180/pi;
>> subplot(2 1 2)
>> plot(f,p(1:N/2));
12 November 2014
27
12 November 2014
28
14
12/11/2014
Pole--Zero Plot
Pole
Pole-zero plot of a digital system : zplane()
>> b = [0.0013 0.0064 0.0128 0.0128 0.0064 0.0013];
>> a = [1 -2.9754 3.8060 -2.5453 0.8811 -0.1254];
>> zplane(b,a);
>> title('Pole-Zero Plot');
>> grid on;
12 November 2014
29
Part I : Summary
Familiarized with signals in MATLAB environment
Computed correlation & convolution
Learnt how to find the Laplace transform using the Symbolic toolbox
Studied about Z-Transform
Studied circular convolution and verified Parsevals theorem
Studied
St di d about
b t systems
t
and
d plotted
l tt d the
th impulse
i
l response
Obtained the frequency response of discrete time systems
Studied about transfer function and pole-zero plots
12 November 2014
30
15
12/11/2014
PART II
Design of FIR and IIR digital Filters
60 Minutes (3:15 pm 4:15 pm)
pm)
12 November 2014
31
Outline
FIR transfer function
Design of FIR filters using windows
Optimal design of FIR filters
IIR transfer function
Design of Butterworth IIR filters
Design of Chebyshev Type-I and Type-II filters
1-D Filtering Process
Introduction to audio and image processing
12 November 2014
32
16
12/11/2014
FIR Filters
FIR filters are linear phase discrete time systems
Si
Since th
the FIR systems
t
are hhaving
i bns
only
l (a
( ns
are zeros exceptt a0),
) th
the
task is in finding bns the numerator coefficients
FIR filters can be designed classically by windowing technique
Here the impulse response of the ideal filter is windowed to get a finite
duration sequence
If hd(n) is the impulse response of the desired (ideal) filter, the designed
(actual) impulse response is given by h(n) = hd(n) . w(n) where w(n) is
the window function
The transition band of the filter directly determines its order
The selection of the window is based on the minimum stop band
attenuation required
12 November 2014
33
34
17
12/11/2014
35
36
18
12/11/2014
12 November 2014
37
38
19
12/11/2014
For filters with a gain other than zero at fs/2, e.g., high-pass and bandstopp filters,, N must be even. Otherwise,, N will be incremented by
y one
Alternatively, you can use a trailing 'h' flag to design a type 4 linear phase
filter and avoid incrementing N.
12 November 2014
39
12 November 2014
40
20
12/11/2014
IIR Filters
IIR systems are not having any linear phase property
Occur as having recursive structures
Since the IIR systems are having both ans and bns, the task is in finding
both of the numerator and denominator coefficients
Classical analog filter design theory could be used for designing IIR
filters
Hence there are many approximations Butterworth, Chebyshev,
Elliptical, etc.
Butterworth approximation is having a smooth passband as well as a
stopband
But a Chebyshev approximation is either the passband having a ripple
(Type-I) or the stopband having a ripple (Type-II)
12 November 2014
41
12 November 2014
42
21
12/11/2014
43
44
22
12/11/2014
45
46
23
12/11/2014
47
48
24
12/11/2014
49
50
25
12/11/2014
51
>> sound(s,fs)
( , )
>> sound(s,2*fs)
52
26
12/11/2014
53
Part II : Summary
Studied about FIR transfer function
Designed FIR filters using windows
Performed optimal design of FIR filters
Studied about IIR transfer function
Designed Butterworth IIR filters
Designed
D i d Chebyshev
Ch b h Type-I
T
I andd Type-II
T
II fil
filters
Demonstrated the 1-D filtering process
Studied how to deal with audio files and image files using MATLAB
12 November 2014
54
27
12/11/2014
Thanks
[email protected]
12 November 2014
55
28