Lab 12
Lab 12
Objective
In this lab we will be able:
Design suitable digital filters to remove unwanted frequency from signals.
Introduction
Digital filters are used to process signals to remove unwanted frequency components or
to enhance certain frequency characteristics. In this report, a suitable digital filter will be
designed in Matlab to remove unwanted frequency from a given signal.
Procedure
The first step in designing a digital filter is to determine the cutoff frequencies of the
unwanted frequency components. This can be done by analyzing the frequency
spectrum of the signal using tools such as the Fast Fourier Transform (FFT) in Matlab.
Once the cutoff frequencies are known, a filter design function such as the butter
function can be used to create a digital filter with those specifications.
Implementation
The digital filter can then be implemented on the signal using the filter function in
Matlab. This function applies the digital filter to the signal, resulting in a filtered signal
that has the unwanted frequency components removed.
Results
To evaluate the performance of the digital filter, the frequency spectrum of the filtered
signal can be analyzed using the FFT and compared to the original signal. The filtered
signal should show a reduction or elimination of the unwanted frequency components.
Lab Task
fs = 100; % sample rate
t = 0:1/fs:1; % time vector
f1 = 10; % frequency 1
f2 = 15; % frequency 2
f3 = 20; % frequency 3
f4 = 25; % frequency 4
y = sin(2*pi*f1*t) + sin(2*pi*f2*t) + sin(2*pi*f3*t) + sin(2*pi*f4*t);
plot(t, y);
xlabel('Time (s)');
ylabel('Amplitude');
fs = 100; % sample rate
t = 0:1/fs:1; % time vector
f1 = 10; % frequency 1
f2 = 15; % frequency 2
f3 = 20; % frequency 3
f4 = 25; % frequency 4
y = sin(2*pi*f1*t) + sin(2*pi*f2*t) + sin(2*pi*f3*t) + sin(2*pi*f4*t);
noise = 0.1*randn(size(y)); % generate noise with a standard deviation
of 0.1
y_noisy = y + noise;
subplot(2,1,1);
stem(t,y);
xlabel('Time (s)');
ylabel('Amplitude');
title('Original Signal');
subplot(2,1,2);
plot(t,y_noisy);
xlabel('Time (s)');
ylabel('Amplitude');
title('Noisy Signal');
N = 5; % number of points in the moving average filter
b = (1/N)*ones(1,N); % filter coefficients
a = 1; % filter denominator
y_moving_avg = filter(b,a,y_noisy); % filtered signal
subplot(2,1,1);
plot(t,y_moving_avg);
xlabel('Time (s)');
ylabel('Amplitude');
title('Moving Average Filtered Signal');
subplot(2,1,2);
plot(t,y_lowpass);
xlabel('Time (s)');
ylabel('Amplitude');
title('Low-Pass Filtered Signal');
fs = 1000; % sample rate
t = linspace(0, 1, fs); % time vector
f1 = 10; % frequency 1
f2 = 15; % frequency 2
f3 = 20; % frequency 3
f4 = 25; % frequency 4
s = sin(2*pi*f1*t) + sin(2*pi*f2*t) + sin(2*pi*f3*t) + sin(2*pi*f4*t);
plot(t, s);
xlabel('Time (s)');
ylabel('Amplitude');
Conclusion
In this report, a digital filter was designed in Matlab to remove unwanted frequency
components from a given signal. The methods used included determining the cutoff
frequencies of the unwanted components, designing a digital filter with those
specifications, implementing the filter on the signal, and evaluating the performance of
the filter. The result of the analysis should be a filtered signal with reduced unwanted
frequency components.