0% found this document useful (0 votes)
57 views36 pages

LAB13 (Noise Reduction)

This document describes noise reduction techniques using digital filters. It provides examples of applying filters to reduce noise in signals from data acquisition systems, speech recording systems, and vibration analysis. Filters are designed using Parks-McClellan optimal filter design and the firpmord function is introduced, which estimates the optimal order for FIR filters based on desired frequency response specifications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views36 pages

LAB13 (Noise Reduction)

This document describes noise reduction techniques using digital filters. It provides examples of applying filters to reduce noise in signals from data acquisition systems, speech recording systems, and vibration analysis. Filters are designed using Parks-McClellan optimal filter design and the firpmord function is introduced, which estimates the optimal order for FIR filters based on desired frequency response specifications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

LAB 13 : Noise Reduction

Contents
1. Noise Reduction
2. Optimal Filter Design
3. Butterworth Filter Design
4. Chebyshev Filter Design

LAB 13: Noise Reduction 2


Noise Reduction
Introduction

 A digital filter removes noise in


– A signal that is contaminated by noise existing in a
broad frequency range
 The desired signal usually occupies a certain
frequency range
– Design a digital filter to remove frequency components
other than the desired frequency range

LAB 13: Noise Reduction 3


Noise Reduction
Example1: Data Acquisition System (1)

 Record a 500 Hz sine wave with 𝑓𝑠 = 8 kHz.


 The signal is corrupted by broadband noise 𝜈 𝑛 :
𝑥 𝑛 = 1.4141 ∙ sin 2𝜋 ∙ 500𝑛/8,000 + 𝜈 𝑛
 Noise is broadband existing from 0 Hz to the
folding frequency of 4,000 Hz.
 Assuming that the desired signal has a frequency
range of only 0 to 800 Hz.
 Filter specifications
– Passband frequency range: 0 ~ 800 Hz with the
passband ripple less than 1 dB

LAB 13: Noise Reduction 4


Noise Reduction
Example1: Data Acquisition System (2)

– Stopband frequency range: 2 ~ 4 kHz with 20 dB


attenuation
 Designed filter
– Rectangular window
– Cut-off frequency : 1400 Hz
𝑓stop −𝑓pass 2000−800 3
– ∆𝑓 = = =
𝑓𝑠 8000 20
0.9
– Filter length = =6𝑁=7
∆𝑓

LAB 13: Noise Reduction 5


Noise Reduction
Example1: Data Acquisition System (3)

% MATLAB (Application of noise filtering)


close all; clear all
fs=8000; % sampling rate
T=1/fs; % sampling period
v=sqrt(0.1)*randn(1,250); % Gaussian random noise
n=0:1:249; % indexes
x=sqrt(2)*sin(2*pi*500*n*T)+v; % 500-Hz plus noise
figure(1)
subplot(2,1,1);plot(n,x);
xlabel('Number of samples');ylabel('Sample value');grid;
N=length(x);

LAB 13: Noise Reduction 6


Noise Reduction
Example1: Data Acquisition System (4)

% Calculate single side spectrum for x(n)


f=[0:N/2]*fs/N;
Axk=2*abs(fft(x))/N;
Axk(1)=Axk(1)/2;
subplot(2,1,2);
plot(f,Axk(1:N/2+1));
xlabel('Frequency (Hz)');
ylabel('Amplitude |X(f)| ');grid;
figure(2)
Fc=1400/(fs/2); % normalized cut-off frequency
B=fir1(6,Fc,boxcar(7));% design FIR filter (filter length = 7)
y=filter(B,1,x); % perform digital filtering

LAB 13: Noise Reduction 7


Noise Reduction
Example1: Data Acquisition System (5)

Ayk=2*abs(fft(y))/N;
Ayk(1)=Ayk(1)/2; % single-side spectrum of the filtered data
subplot(2,1,1); plot(n,y);
axis([0 length(v) -4 4]);
xlabel('Number of samples');
ylabel('Sample value');grid;
subplot(2,1,2);plot(f,Ayk(1:N/2+1));
axis([0 fs/2 0 1.5]);
xlabel('Frequency (Hz)');
ylabel('Amplitude |Y(f)| ');grid;

LAB 13: Noise Reduction 8


Noise Reduction
Example1: Data Acquisition System (6)

LAB 13: Noise Reduction 9


Noise Reduction
Example1: Data Acquisition System (7)

LAB 13: Noise Reduction 10


Noise Reduction
Example2: Speech Recording System (1)

 Record speech in a noisy environment at a


sampling rate of 8000 Hz
 The recorded speech contains information within
1800 Hz
 Specification
– Filter type = lowpass FIR
– Passband frequency range = 0 – 1,500 Hz
– Passband ripple = 1 dB
– Stopband frequency range = 2500 – 4000 Hz
– Stopband attenuation = 30 dB

LAB 13: Noise Reduction 11


Speech Noise Reduction
Example2: Speech Recording System (2)

 Filter design
– Window type = Hanning window
– Number of filter taps = 25
– Lowpass cutoff frequency = 2000 Hz

LAB 13: Noise Reduction 12


Speech Noise Reduction
Example2: Speech Recording System (3)

% Ex2 - Speech Recording System


close all; clear all; clc
fs=8000;T=1/fs;
load speech.dat
we=speech;
t=[0:length(we)-1]*T;
th=mean(we.*we)/4;
v=sqrt(th)*randn([1,length(we)]);
x=we+v;
subplot(2,1,1);plot(t,x);
xlabel('Number of samples');ylabel('Sample value');grid;
title('Noisy Speech and its spectrum');

LAB 13: Noise Reduction 13


Speech Noise Reduction
Example2: Speech Recording System (4)

N=length(x);
f=[0:N/2]*fs/N;
Axk=2*abs(fft(x))/N; Axk(1)=Axk(1)/2;
subplot(2,1,2); plot(f,Axk(1:N/2+1));
xlabel('Frequency (Hz)');
ylabel('Amplitude Spectrum |X(f)| '); grid;
figure
N1=24; % filter degree
fc=2000/4000; % normalized cutoff frequency of 2000 Hz
B=fir1(N1,fc,hanning(N1+1));
y=filter(B,1,x);
Ayk=2*abs(fft(y))/N;Ayk(1)=Ayk(1)/2;

LAB 13: Noise Reduction 14


Speech Noise Reduction
Example2: Speech Recording System (5)

subplot(2,1,1); plot(t,y);
xlabel('Number of samples');
ylabel('Sample value');grid;
title('Enhanced Speech and its Spectrum');
subplot(2,1,2); plot(f,Ayk(1:N/2+1));
xlabel('Frequency (Hz)');
ylabel('Amplitude Spectrum |Y(f)| ');grid;
pause;
sound(x/max(abs(x)),fs);
pause
sound(y/max(abs(y)),fs);

LAB 13: Noise Reduction 15


Speech Noise Reduction
Example2: Speech Recording System (6)

LAB 13: Noise Reduction 16


Speech Noise Reduction
Example2: Speech Recording System (7)

LAB 13: Noise Reduction 17


Noise Reduction
in Vibration Signals (1)
 Data acquisition system for vibration analysis
– Captured a vibration signal using an accelerometer
sensor in the noisy environment (𝑓𝑠 = 1,000 Hz)
– Vibration analysis requires the first dominant frequency
component in the range 35 to 50 Hz to be retrieved.
 Filter specifications
– Filter type: bandpass filter
– Passband frequency range = 35 ~ 50 Hz
– Passband ripple = 0.02 dB
– Stopband frequency ranges = 0~15 and 70~500 Hz
– Stopband attenuation = 50 dB

LAB 13: Noise Reduction 18


Noise Reduction
in Vibration Signals (2)
 Filter design
– Window type = Hamming window
– Number of filter taps = 167
– Low cutoff frequency = 25 Hz
– High cutoff frequency = 65 Hz

LAB 13: Noise Reduction 19


Noise Reduction
in Vibration Signals (3)

Noisy vibration signal and its spectrum

LAB 13: Noise Reduction 20


Noise Reduction
in Vibration Signals (4)

Retrieved vibration signal and its spectrum

LAB 13: Noise Reduction 21


firpmord
Syntax

 Parks-McClellan optimal FIR filter order


estimation
 Syntax
>> [n,fo,ao,w] = firpmord(f,a,dev)
>> [n,fo,ao,w] = firpmord(f,a,dev,fs)

LAB 13: Noise Reduction 22


firpmord
Description

>> [n,fo,ao,w] = firpmord(f,a,dev)


– Returns the approximate order n, normalized frequency band
edges fo, frequency band amplitudes ao, and weights w that
meet input specifications f, a, and dev.

>> [n,fo,ao,w] = firpmord(f,a,dev,fs)


– Specifies a sampling frequency fs. fs defaults to 2 Hz, implying a
Nyquist frequency of 1 Hz. You can specify band edges scaled
to a particular application's sample rate.

LAB 13: Noise Reduction 23


firpmord
Input Arguments (1)

 f  Frequency band edges, real-valued vector


– Frequency band edges, specified as a real-valued vector.
The argument must be in the range [0, Fs/2],
where Fs is the sampling frequency.
– The number of elements in the vector is always a
multiple of 2. The frequencies must be in increasing
order.
 a  Desired amplitude, vector
– Desired amplitudes at the points contained in f, specified
as a vector.
– f and a must satisfy the condition of length(f) =
2*length(a)–2. The desired function is piecewise
constant.
LAB 13: Noise Reduction 24
firpmord
Input Arguments (2)

 dev — Maximum allowable deviation, vector


– Maximum allowable deviation, specified as a
vector. dev has the same size as a.
– It specifies the maximum allowable deviation or ripples
between the frequency response and the desired
amplitude of the output filter for each band.
 fs — Sample rate, 2 Hz (default) | real scalar
– Sample rate, specified as a real scalar.

LAB 13: Noise Reduction 25


Firpmord
Output Arguments (1)

 n — Filter order, positive integer


– Filter order, returned as a positive integer.

 fo — Normalized frequency points, real-valued


vector
– Normalized frequency points, specified as a real-valued
vector.
– The argument must be in the range [0, 1], where 1
corresponds to the Nyquist frequency (Fs/2).
– The number of elements in the vector is always a
multiple of 2.
– The frequencies must be in increasing order.

LAB 13: Noise Reduction 26


Optimal Filter Design
firpmord: Output Arguments (2)

 ao — Amplitude response, real-valued vector


– Amplitude response, returned as a real-valued vector.
 w — weights, real-valued vector
– Weights used to adjust the fit in each frequency band,
specified as a real-valued vector.
– The length of w is half the length of f, so there is exactly
one weight per band.

 In some cases, firpmord underestimates or


overestimates the order n. If the filter does not
meet the specifications, try a higher order such
as n+1 or n+2.

LAB 13: Noise Reduction 27


Optimal Filter Design
firpmord: Example (1)

 Design a minimum-order lowpass filter with a


500 Hz passband cutoff frequency and 600 Hz
stopband cutoff frequency.
 Specify a sampling frequency of 2000 Hz.
 Require at least 40 dB of attenuation in the
stopband and less than 3 dB of ripple in the
passband.
>> rp = 3; % Passband ripple in dB
>> rs = 40; % Stopband ripple in dB
>> fs = 2000; % Sampling frequency
>> f = [500 600]; % Cutoff frequencies
>> a = [1 0]; % Desired amplitudes

LAB 13: Noise Reduction 28


Optimal Filter Design
firpmord: Example (2)

 Convert the deviations to linear units.


 Design the filter and visualize its magnitude and
phase responses.
>> dev=[(10^(rp/20)-1)/(10^(rp/20)+1), 10^(-rs/20)];
>> [n,fo,ao,w] = firpmord(f,a,dev,fs);
>> b = firpm(n,fo,ao,w);
>> freqz(b,1,1024,fs)
>> title('Lowpass Filter Designed to Specifications')

LAB 13: Noise Reduction 29


Optimal Filter Design
firpmord: Example (3)

The filter falls slightly short


of meeting the stopband
attenuation and passband
ripple specifications.
Using n+1 instead of n in
the call to firpm achieves
the desired amplitude
characteristics.

LAB 13: Noise Reduction 30


Butterworth Filter Design
BUTTER (1)

>> [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 coefficients are listed in descending powers of z.
– The cutoff frequency Wn must be 0.0 < Wn < 1.0, with
1.0 corresponding to half the sampling rate.
– If Wn is a two-element vector, Wn = [W1 W2], BUTTER
returns an order 2N bandpass filter with passband W1 <
W < W2.

LAB 13: Noise Reduction 27


Butterworth Filter Design
BUTTER (2)

>> [B,A] = BUTTER(N,Wn,ftype)


– Designs a lowpass, highpass, bandpass, or bandstop
Butterworth filter, depending on the value of ftype and
the number of elements of Wn. The resulting bandpass
and bandstop designs are of order 2N.
– [B,A] = BUTTER(N,Wn,'high') designs a highpass filter.
– [B,A] = BUTTER(N,Wn,'low') designs a lowpass filter.
– [B,A] = BUTTER(N,Wn,'stop') is a bandstop filter if Wn =
[W1 W2].

LAB 13: Noise Reduction 32


Butterworth Filter Design
BUTTORD (1)

 Butterworth filter order selection


>> [N, Wn] = BUTTORD(Wp, Ws, Rp, Rs)
– N: the lowest order of the digital Butterworth filter
– Rp dB: maximum loss in the passband
– Rs dB: minimum attenuation in the stopband.
– Wp and Ws
• the passband and stopband edge frequencies
• normalized from 0 to 1 (where 1 corresponds to 𝜋
radians/sample).
• Lowpass: Wp = .1, Ws = .2
• Bandpass: Wp = [.2 .7], Ws = [.1 .8]

LAB 13: Noise Reduction 33


Butterworth Filter Design
BUTTORD (2)
• Bandstop: Wp = [.1 .8], Ws = [.2 .7]
• Highpass: Wp = .2, Ws = .1

– Wn: the Butterworth natural frequency (or, the "3 dB


frequency") to use with BUTTER to achieve the
specifications.

LAB 13: Noise Reduction 34


Butterworth Filter Design
Example : Lowpass Butterworth Filter (1)

For data sampled at 1000 Hz, design a lowpass filter with less
than 3 dB of ripple in the passband, defined from 0 to 40 Hz,
and at least 60 dB of attenuation in the stopband, defined
from 150 Hz to the Nyquist frequency (500 Hz).

>> Wp = 40/500; Ws = 150/500;


>> [n,Wn] = buttord(Wp,Ws,3,60); % Gives min. filter order
>> [b,a] = butter(n,Wn); % Butterworth filter design
>> freqz(b,a); % Plots the frequency response

LAB 13: Noise Reduction 35


Butterworth Filter Design
Example : Lowpass Butterworth Filter (2)

LAB 13: Noise Reduction 36

You might also like