frequency domain signal processing using...
TRANSCRIPT
![Page 1: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/1.jpg)
Frequency Domain Signal Frequency Domain Signal Processing Using MATLABProcessing Using MATLAB
Mohammad Sadgh TalebiSharif University of Technology
![Page 2: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/2.jpg)
Fourier Transform in Fourier Transform in MatlabMatlab
Y = fft(X,n)Computes n-point Discrete Fourier Transform (DFT) of each column of X with a FFT algorithmIf length(x) < n => zero-paddingIf length(x) > n => truncate x
![Page 3: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/3.jpg)
Y = ifft(X,n)Similarly, IFFT computes n-point Inverse Discrete Fourier Transform (IDFT) of each column of X with a IFFT algorithmIf length(x) < n => zero-paddingIf length(x) > n => truncate x
![Page 4: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/4.jpg)
Signal Analysis >Signal Analysis >ConvolutionConvolution
fftshift(X) swaps the left and right halves of X. For matrices, fftshift(X) swaps the first quadrant with the third and the second quadrant with the fourth.Similarly, ifftshift(X) neutralizes the results of fftshift.
![Page 5: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/5.jpg)
Signal Analysis >Signal Analysis >ConvolutionConvolution
x(1:20)=0;x(21:30)=1;x(31:50)=0;figure(1);plot(x);X=fft(x);figure(2);subplot(211);plot(abs(X));subplot(212);plot(angle(X));figure(3);subplot(211);plot(abs(fftshift(X)));subplot(212);plot(angle(fftshift(X)));
![Page 6: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/6.jpg)
Signal Analysis >Signal Analysis >Step ResponseStep Response
![Page 7: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/7.jpg)
Signal Analysis >Signal Analysis >Step ResponseStep Response
![Page 8: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/8.jpg)
Signal Analysis >Signal Analysis >Bode DiagramsBode Diagrams
Filtering Frequency DomainTime Domain
![Page 9: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/9.jpg)
Frequency Domain FilteringTake FFT from input signal and just multiply it by frequency response of filter. Finally take inverse FFT from result.Alternatively, with the knowledge of Pole-Zero plot or Transfer Function, you can filter any signal using “filter” command.
![Page 10: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/10.jpg)
Y = FILTER(B,A,X)Filter data with an infinite impulse response (IIR) or finite impulse response (FIR) filtery(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)- a(2)*y(n-1) - ... -a(na+1)*y(n-na)
![Page 11: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/11.jpg)
Time Domain FilteringFrequency response of desired filter yields the impulse response of filter, thus filtering can be carried out using:
ConvFftfilt
However, the main problem, i.e. computing the impulse response is still left.
![Page 12: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/12.jpg)
Filter DesignFilter Design
Several approaches for computing impulse response of filters, with a desired characteristics
Parks-McClellan , (firpm and remezcommands)Traditional approximations for filters, such as Butterworth, Chebychev, Elliptic, etc.Filter Design & Analysis Tool
![Page 13: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/13.jpg)
Analog filter frequency responseAnalog filter frequency response
H = FREQS(B,A,W) returns the complex frequency response of the analog filter specified by coefficient vectors b and a.
[H,W] = FREQS(B,A,F) picks f number of frequencies on which to compute the frequency response h.
![Page 14: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/14.jpg)
Digital filter frequency responseDigital filter frequency response
[H,W] = FREQZ(B,A,N) returns the N-point complex frequency response vector H and the N-point frequency vector W in radians/sample of the filter.
frequency response is evaluated at N points equally spaced around the upper half of the unit circle. If N isn't specified, it defaults to 512.
[H,W] = FREQZ(B,A,N,'whole') uses N points around the whole unit circle.
![Page 15: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/15.jpg)
Example:Example:Frequency Response Using FREQZFrequency Response Using FREQZ
a=[1 3 2 1];b=1;[H,w]=freqz(b,a,128);semilogy(w,abs(H));
![Page 16: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/16.jpg)
Example:Example:Frequency Response Using FREQSFrequency Response Using FREQSEvaluate frequency response of
a = [1 0.4 1]; b = [0.2 0.3 1]; w = logspace(-1,1); h=freqs(b,a,w)mag = abs(h); phase = angle(h); subplot(2,1,1), loglog(w,mag)
subplot(2,1,2), semilogx(w,phase)
![Page 17: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/17.jpg)
Example:Example:Frequency Response Using FREQSFrequency Response Using FREQS
![Page 18: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/18.jpg)
Butterworth FilterButterworth Filter
The frequency response of the Butterworth filter is maximally flat (has no ripples) in the passband, and rolls off towards zero in the stopband.A Butterworth LP prototype has the following characteristic function:
![Page 19: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/19.jpg)
Butterworth Filter (ContButterworth Filter (Cont’’d)d)
![Page 20: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/20.jpg)
Chebyshev FilterChebyshev Filter
having a steeper roll-off and more passband/stopband ripple than Butterworth filters
Chebyshev filters have the property that they minimize the error between the idealized filter characteristic and the actual over the range of the filter, but with ripples in the passband or stopband.
![Page 21: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/21.jpg)
Chebyshev Filter (ContChebyshev Filter (Cont’’d)d)
Chebyshev Type IIt has no ripple in the stopband, but has ripple in the passband. The transfer function is:
where Tn() is a chebyshev polynomial.
![Page 22: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/22.jpg)
Chebyshev Filter (ContChebyshev Filter (Cont’’d)d)
Chebyshev Type IIIt has no ripple in the passband, but has ripple in the stopband. The transfer function is:
where Tn() is a chebyshev polynomial
![Page 23: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/23.jpg)
Chebyshev Filter (ContChebyshev Filter (Cont’’d)d)
![Page 24: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/24.jpg)
Elliptic FilterElliptic Filter
is a filter with equiripple behavior in both the passband and the stopband.
It minimizes the maximum error in both bands, as opposed to a Chebyshev filterwhich exhibits equiripple behavior in the passband, or the inverse Chebyshev filter which has ripples in the stopband.
![Page 25: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/25.jpg)
Elliptic Filter (ContElliptic Filter (Cont’’d)d)
The magnitude of the frequency response of a lowpass elliptic filter is given by:
where Rn() is a chebyshev rational function.
![Page 26: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/26.jpg)
Elliptic Filter (ContElliptic Filter (Cont’’d)d)
![Page 27: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/27.jpg)
Filters : ComparisonFilters : Comparison
![Page 28: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/28.jpg)
Butterworth FilterButterworth Filter
butter designs lowpass, bandpass, highpass, and bandstop digital and analog Butterworth filters. [B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator). The cutoff frequency Wn must be 0 <Wn < 1.0.
![Page 29: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/29.jpg)
Butterworth Filter (ContButterworth Filter (Cont’’d)d)
If Wn is a two-element vector, Wn = [W1 W2], BUTTER returns an order 2N bandpass filter with passband W1 < W < W2.[B,A] = BUTTER(N,Wn,'high') designs a highpass filter.[B,A] = BUTTER(N,Wn,'low') designs a lowpassfilter.[B,A] = BUTTER(N,Wn,'stop') is a bandstopfilter if Wn = [W1 W2].
![Page 30: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/30.jpg)
Chebyshev FilterChebyshev Filter
[b,a] = cheby1(n,R,Wp) designs an order n Chebyshev lowpass digital Chebyshev filter with normalized passband edge frequency Wpand R dB of peak-to-peak ripple in the passband.
Normalized passband edge frequency is the frequency at which the magnitude response of the filter is equal to -R dB.
![Page 31: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/31.jpg)
Butterworth ExampleButterworth Example
[b,a]=butter(7,.32);[H,w]=freqz(b,a,128);plot(w,abs(H));
![Page 32: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/32.jpg)
Filter Design with Filter Design with ParksParks--McClellan McClellan
FRIPM command designs a linear-phase FIR filter using the Parks-McClellan algorithm.Chebyshev approximation is used to fit the optimal fit between desired and actual response. b = firpm(n,f,a): returns n+1 coefficients of the order n FIR filter whose frequency-amplitude characteristics match those given by vectors f and a.
![Page 33: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/33.jpg)
Filter Design with Filter Design with ParksParks--McClellan (ContMcClellan (Cont’’d) d)
f is a vector of pairs of normalized frequency points, specified in the range between 0 and 1 in increasing order.
a is a vector containing the desired amplitudes at the points specified in f.
f and a must be the same length. The length must be an even number.
![Page 34: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/34.jpg)
Filter Design with Filter Design with ParksParks--McClellan (ContMcClellan (Cont’’d) d)
The desired amplitude at frequencies between pairs of points (f(k), f(k+1)) for k odd is the line segment connecting the points (f(k), a(k)) and (f(k+1), a(k+1)).
The desired amplitude at frequencies between pairs of points (f(k), f(k+1)) for keven is unspecified. The areas between such points are transition or "don't care" regions.
![Page 35: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/35.jpg)
Example of Example of FIRPM Filter Design FIRPM Filter Design
f = [0 0.3 0.4 0.6 0.7 1]; a = [0 0 1 1 0 0]; b = firpm(17,f,a); [h,w] = freqz(b,1,512);
![Page 36: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/36.jpg)
How to read a soundHow to read a sound
[y,Fs,bits] = wavread('filename',[N1 N2])
Read Microsoft WAVE (.wav) sound file specified in the ‘filename’ and load its data to vector y ( samples N1 through N2).
Fs returns the sampling frequency and bits returns the number of bits used for encoding.
![Page 37: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/37.jpg)
How to write a signal as a soundHow to write a signal as a sound
wavwrite(y,Fs,N,'filename')
writes the data stored in the variable y to a WAVE file called ‘filename’. Fs is sample rate and N is the number of bits used for encoding. Amplitude values outside the range [-1,+1] are clipped prior to writing. N = 8, 16, 24, or 32
![Page 38: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/38.jpg)
How to make a sound noisy!How to make a sound noisy!
By using wavread command, first we convert a sound into a vector, then we add noise term to it.
Common forms of noises are Gaussian and Uniform.
![Page 39: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/39.jpg)
Gaussian NoiseGaussian Noise
Gaussian NoiseY = randn(m,n) generates normally distributed random numbers (noises)
In order to generate a Gaussian noise sequence with arbitrary statistics, multiply the output of randn by the standard deviation and then add the desired mean
![Page 40: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/40.jpg)
UniformUniform NoiseNoise
Uniform NoiseY = rand (m,n) generates unifromlydistributed random numbers (noises) over [0,1] interval.
In order to generate a uniform distribution of random numbers on a specified interval [a,b], multiply the output of rand by (b-a), then add a.
![Page 41: Frequency Domain Signal Processing Using MATLABce.sharif.edu/courses/84-85/2/ce242/resources/root/Matlab... · Frequency Domain Signal Processing Using MATLAB ... plot or Transfer](https://reader033.vdocuments.mx/reader033/viewer/2022050804/5aaf478d7f8b9a22118d0e14/html5/thumbnails/41.jpg)
QuestionsQuestions
… surely, in the creation of the heavens and the earth, there are signs for the owners of wisdom …
The Holy Quran
Thanks for your attendance.