Title: ENTC 4337 MICROPROCESSORS
1ENTC 4337MICROPROCESSORS
2 The following MATLAB program, MAT33.m is used to
design a 33-coefficient FIR bandpass filter.
MAT33.M FIR BANDPASS WITH 33 COEFFICIENTS USING
MATLAB Fs10 kHz nu0 0.1 0.15 0.25 0.3 1)
normalized frequencies mag0 0 1 1 0
0 magnitude at normalized frequencies cremez(
32,nu,mag) invoke remez algorithm for 33
coeff bp33c coeff values transposed save
matbp33.cof bp33 -ascii save in ASCII file
with coefficients h,wfreqz(c,l,256)
frequency response with 256 points plot(5000nu
,mag,W/pi,abS(h)) plot ideal magnitude response
3The bandpass filter is represented with 3 bands
- The first band (stopband) has normalized
frequencies between 0 and 0.1 (0-500 Hz), with
corresponding magnitude of 0. - The second band (passband) has normalized
frequencies between 0.15 and 0.25 (750-1,250 Hz),
with corresponding magnitude of 1. - The third band (stopband) has normalized
frequencies between 0.3 and the Nyquist frequency
of 1 (1500-5000 Hz), with corresponding
magnitude of 0.
4The magnitude response of the ideal desired
filter
5- Note that the frequencies 750 and 1250 Hz
represent the passband frequencies with
normalized frequencies of 0.15 and 0.25,
respectively, and associated magnitudes of 1. -
- The frequencies 500 and 1500 Hz represent the
stopband frequencies with normalized frequencies
of 0.1 and 0.3, respectively, and associated
magnitudes of 0.
6- The instructions,
- cremez(32,nu,mag)
- and
- save a\matbp33.cof bp33 -ascii ,
- create a file of coefficients for the FIR
filter. -
- Note for the FIR filter, the coefficients repeat
themselves. -
- That is, the first 16 coefficients match the last
16 coefficients. -
- Thus, if you folded, the coefficients in the
middle the coefficients would fold onto their
corresponding coefficient.
7(No Transcript)
8- To have a more realistic simulation, a composite
signal may be created and filtered in MATLAB. - Consider a composite signal consisting of three
sinusoids created by the following MATLAB code
9Fs10e3 Ts1/Fs Ns512 t 0TsTs(Ns-1) f1
1000 f22500 f33000 x1sin(2pif1t) x2sin(
2pif2t) x3sin(2pif3t) xx1x2x3 plot(t,
x), grid
3 frequencies
composite
10xx1x2x3
11- The signal frequency content can be plotted by
using the MATLAB fft function.
12One-dimensional fast Fourier transform
Syntax y fft(x) y fft(x,n)
13Description
fft computes the discrete Fourier transform of a
vector or matrix. This function implements the
transform given by where WN e-j(2/N) and N
length(x). Note that the series is indexed as n
1 and k 1 instead of the usual n and k because
MATLAB vectors run from 1 to N instead of from 0
to N-1.
14Example
A common use of the Fourier transform is to find
the frequency components of a time-domain signal
buried in noise. Consider data sampled at 1000
Hz. Form a signal consisting of 50 Hz and 120 Hz
sinusoids and corrupt the signal with zero-mean
random noise
t 00.0010.6 x sin(2pi50t)
sin(2pi120t) y x 2randn(1,length(t))
plot(y(150))
15(No Transcript)
16It is difficult to identify the frequency
components by studying the original signal.
Convert to the frequency domain by taking the
discrete Fourier transform of the noisy signal y
using a 512-point fast Fourier transform (FFT)
Y fft(y,512)
17Graph the first 256 points (the other 256 points
are symmetric) on a meaningful frequency axis
f 1000(0255)/512 plot(f,Pyy(1256))
18(No Transcript)
19Sometimes it is useful to normalize the output of
fft so that a unit sinusoid in the time domain
corresponds to unit amplitude in the frequency
domain. To produce a normalized discrete-time
Fourier transform in this manner, use Pn
abs(fft(x))2/length(x)
20Back to our lab
- Three spikes should be observed at 1000 Hz, 2500
Hz, and 3000 Hz. - The frequency leakage observed on the plot is due
to windowing caused by the finite observation
period.
21The Program
X(abs(fft(x,Ns))) yX(1length(X)/2) f(11len
gth(y)) plot(fFs/Ns,y) grid on
22(No Transcript)
23- A bandpass filter is designed to filter out all
frequencies less than 750 Hz and greater than
1250 Hz. - We use the following code to verify that the FIR
filter is actually able to filter the 2.5 kHz and
3 kHz signals.
24nu0 0.1 0.15 0.25 0.3 1 normalized
frequencies mag0 0 1 1 0 0 magnitude at
normalized frequencies cremez(32,nu,mag) invok
e remez algorithm for 33 coeff a1 freqz(c,a)
grid on subplot(3,1,1) va_fft(x,1024,10000) sub
plot(3,1,2) grid on h,wfreqz(c,1,256) freq
uency response with 256 points plot(w/(2pi),10lo
g(abs(h))) subplot(3,1,3) grid
on yfilter(c,a,x) va_fft(y,1024,10000)
25(No Transcript)
26The following MATLAB code allows one to visually
inspect the filtering.
n128 subplot(2,1,1) plot(t(1n),x(1n)) grid
on xlabel('time(s)') ylabel('Amplitude') title(
'Original and Filtered Signal') subplot(2,1,2) g
rid on plot(t(1n),y(1n)) grid
on xlabel('times(s)') ylabel('Amplitude')
27(No Transcript)
28- Looking at the plots, we see that the filter is
able to remove the desired frequency components
of the composite signal. - Observe that the time response has an initial
setup time causing a few data samples to be
inaccurate.