This action might not be possible to undo. Are you sure you want to continue?

# Frequency Domain Signal Processing Using MATLAB

Mohammad Sadgh Talebi Sharif University of Technology

**Fourier Transform in Matlab
**

Y = fft(X,n) Computes n-point Discrete Fourier Transform (DFT) of each column of X with a FFT algorithm If length(x) < n => zero-padding If length(x) > n => truncate x

Y = ifft(X,n) Similarly, IFFT computes n-point Inverse Discrete Fourier Transform (IDFT) of each column of X with a IFFT algorithm If length(x) < n => zero-padding If length(x) > n => truncate x

**Signal Analysis > Convolution
**

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.

subplot(212).Signal Analysis > Convolution x(1:20)=0. subplot(212). plot(angle(fftshift(X))). figure(3). subplot(211). plot(angle(X)). subplot(211). plot(abs(fftshift(X))). figure(2). plot(x). X=fft(x). figure(1). x(31:50)=0. plot(abs(X)). . x(21:30)=1.

Signal Analysis > Step Response .

Signal Analysis > Step Response .

Signal Analysis > Bode Diagrams Filtering Frequency Domain Time Domain .

Frequency Domain Filtering Take FFT from input signal and just multiply it by frequency response of filter. you can filter any signal using “filter” command. Finally take inverse FFT from result. . Alternatively. with the knowledge of Pole-Zero plot or Transfer Function.

...A.a(2)*y(n-1) .. + b(nb+1)*x(n-nb). a(na+1)*y(n-na) .X) Filter data with an infinite impulse response (IIR) or finite impulse response (FIR) filter y(n) = b(1)*x(n) + b(2)*x(n-1) + .Y = FILTER(B..

the main problem. computing the impulse response is still left.e. thus filtering can be carried out using: Conv Fftfilt However. . i.Time Domain Filtering Frequency response of desired filter yields the impulse response of filter.

Elliptic. etc. Filter Design & Analysis Tool . with a desired characteristics Parks-McClellan .Filter Design Several approaches for computing impulse response of filters. (firpm and remez commands) Traditional approximations for filters. such as Butterworth. Chebychev.

W] = FREQS(B. [H.A.F) picks f number of frequencies on which to compute the frequency response h.Analog filter frequency response H = FREQS(B.A.W) returns the complex frequency response of the analog filter specified by coefficient vectors b and a. .

A.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. If N isn't specified. .Digital filter frequency response [H. [H. frequency response is evaluated at N points equally spaced around the upper half of the unit circle. it defaults to 512.N.'whole') uses N points around the whole unit circle.W] = FREQZ(B.

. semilogy(w.a. [H.w]=freqz(b.Example: Frequency Response Using FREQZ a=[1 3 2 1]. b=1.128).abs(H)).

3 1].phase) .4 1]. b = [0.Example: Frequency Response Using FREQS Evaluate frequency response of a = [1 0. w = logspace(-1. phase = angle(h). loglog(w. semilogx(w.2 0.1.1).1.a.2).mag) subplot(2. h=freqs(b. subplot(2.1).w) mag = abs(h).

Example: Frequency Response Using FREQS .

and rolls off towards zero in the stopband.Butterworth Filter The frequency response of the Butterworth filter is maximally flat (has no ripples) in the passband. A Butterworth LP prototype has the following characteristic function: .

Butterworth Filter (Cont’d) .

. but with ripples in the passband or stopband.Chebyshev 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 has ripple in the passband.Chebyshev Filter (Cont’d) Chebyshev Type I It has no ripple in the stopband. . The transfer function is: where Tn() is a chebyshev polynomial.

Chebyshev Filter (Cont’d) Chebyshev Type II It has no ripple in the passband. but has ripple in the stopband. The transfer function is: where Tn() is a chebyshev polynomial .

Chebyshev Filter (Cont’d) .

.Elliptic Filter is a filter with equiripple behavior in both the passband and the stopband. as opposed to a Chebyshev filter which exhibits equiripple behavior in the passband. or the inverse Chebyshev filter which has ripples in the stopband. It minimizes the maximum error in both bands.

.Elliptic Filter (Cont’d) The magnitude of the frequency response of a lowpass elliptic filter is given by: where Rn() is a chebyshev rational function.

Elliptic Filter (Cont’d) .

Filters : Comparison .

. bandpass. highpass.0. The cutoff frequency Wn must be 0 <Wn < 1.Butterworth Filter butter designs lowpass.A] = BUTTER(N. and bandstop digital and analog Butterworth filters. [B.Wn) designs an Nth order lowpass digital Butterworth filter and returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator).

Wn. [B. Wn = [W1 W2].Butterworth Filter (Cont’d) If Wn is a two-element vector. [B.Wn.'stop') is a bandstop filter if Wn = [W1 W2].'low') designs a lowpass filter.Wn. .A] = BUTTER(N.A] = BUTTER(N. BUTTER returns an order 2N bandpass filter with passband W1 < W < W2.'high') designs a highpass filter. [B.A] = BUTTER(N.

Wp) designs an order n Chebyshev lowpass digital Chebyshev filter with normalized passband edge frequency Wp and R dB of peak-to-peak ripple in the passband.Chebyshev Filter [b. Normalized passband edge frequency is the frequency at which the magnitude response of the filter is equal to -R dB.R.a] = cheby1(n. .

.128). [H.32)..abs(H)). plot(w.a]=butter(7.a.Butterworth Example [b.w]=freqz(b.

a): returns n+1 coefficients of the order n FIR filter whose frequencyamplitude characteristics match those given by vectors f and a. b = firpm(n. . Chebyshev approximation is used to fit the optimal fit between desired and actual response.f.Filter Design with Parks-McClellan FRIPM command designs a linear-phase FIR filter using the Parks-McClellan algorithm.

Filter Design with Parks-McClellan (Cont’d) f is a vector of pairs of normalized frequency points. a is a vector containing the desired amplitudes at the points specified in f. specified in the range between 0 and 1 in increasing order. f and a must be the same length. . The length must be an even number.

The desired amplitude at frequencies between pairs of points (f(k). a(k+1)). a(k)) and (f(k+1). f(k+1)) for k even is unspecified. .Filter Design with Parks-McClellan (Cont’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). The areas between such points are transition or "don't care" regions.

1.6 0.Example of FIRPM Filter Design f = [0 0.f. .a).512). [h.w] = freqz(b. a = [0 0 1 1 0 0].7 1]. b = firpm(17.3 0.4 0.

.How to read a sound [y.[N1 N2]) Read Microsoft WAVE (.Fs.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.bits] = wavread('filename'.

16.N. or 32 .'filename') writes the data stored in the variable y to a WAVE file called ‘filename’. N = 8. Amplitude values outside the range [-1. Fs is sample rate and N is the number of bits used for encoding.Fs. 24.+1] are clipped prior to writing.How to write a signal as a sound wavwrite(y.

first we convert a sound into a vector. then we add noise term to it. . Common forms of noises are Gaussian and Uniform.How to make a sound noisy! By using wavread command.

Gaussian Noise Gaussian Noise Y = randn(m. multiply the output of randn by the standard deviation and then add the desired mean .n) generates normally distributed random numbers (noises) In order to generate a Gaussian noise sequence with arbitrary statistics.

b]. multiply the output of rand by (b-a). then add a.1] interval. In order to generate a uniform distribution of random numbers on a specified interval [a. .n) generates unifromly distributed random numbers (noises) over [0.Uniform Noise Uniform Noise Y = rand (m.

Questions … 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. .