You are on page 1of 4

19BCT0021

Swayam Shresth Mohapatra

Digital Signal Processing Lab Task

Task-2:
Using MATLAB

(i) Read an audio signal in MATLAB, add random noise to get the noisy signal. Use
moving average filter to remove the noise from the contaminated audio signal to get
de-noised audio signal.

o Objective :
To demonstrate the addition of noise to a signal and using filter to remove the noise.

o Algorithm / Procedure :

Step-1: Read the signal using audioread() function.


Step-2: Create a continuous noise signal.
Step-3: Create a kernel with window width of 4
Step-4: Apply the filter to find the running average of this kernel to the noisy signal
Step-5: Use subplot to display the waves of the various forms

o Program :
clc;
clear all;
[signal, fs] = audioread("sample.wav");
signal = signal(:,1);
noise= 0.02*randn(268237,1);
noisy_signal = signal + noise;
windWid = 4;
kernel = ones(windWid,1) / windWid;
denoise_signal = filter(kernel, 1, noisy_signal);

figure;
subplot(4,1,1)
plot(signal);
title('Original Sound')

subplot(4,1,2)
plot(noise);
title("Noise")

subplot(4,1,3)
plot(noisy_signal);
title("Noise added to Sound")
subplot(4,1,4)
plot(denoise_signal);
title("De-noised Sound")

o Experimental result & inference :

As we can see from the above plots, the noise in the signal is removed to great extent
by using the moving average filter.

(ii) Write a MATLAB program to generate a square wave. Find the Fourier series
coefficients. Explain Gibb’s phenomenon in Fourier series through programming.
Also explain the ringing effect when the number of Fourier components are enhanced
while synthesising.

o Objective :
To Demonstrate Gibb’s phenomenon in Fourier series and also the ringing effect.

o Algorithm / Procedure :

Step-1: Initialise the values of Sampling frequency, time period, Omega, k and N
Step-2: Generate a square wave y
Step-3: To find the fourier coefficients a0, an and bn, integrate t
Step-4: Run a for loop till N(the no of harmonics)
Step-4.1: Use the fourier coefficients to calculate the fourier series
Step-5: Display the Harmonics
Step-6: Plot the graphs
o Program :

clear all;
close all;
clc

fs=80;
T=2;

w0=2*pi/T;
k=0:1/fs:10-1/fs;
y=1+square(w0*k,50);

syms t
N=3;
n=1:N;

a0=(2/T)*(int(2,t,0,1)+int(0,t,1,2));
an=(2/T)*(int(2*cos(n*w0*t),t,0,1)+(int(-0*cos(n*w0*t),t,1,2)));
bn=(2/T)*(int(2*sin(n*w0*t),t,0,1)+(int(-0*sin(n*w0*t),t,1,2)));

F=a0/2;
for i=1:N
F=F+an(i)*cos(i*w0*k)+bn(i)*sin(i*w0*k);
end
disp('For First 3 Harmonics "a0", "an" and "bn" are: ')
disp(a0)
disp(an)
disp(bn)
figure
hold on
plot(k,y)
plot(k,F)
legend('Square Wave', 'Fourier Approx')
hold off
grid on

o Experimental result & inference :


For N=3: For N=10:

For N=30: For N=50:

The Gibbs phenomenon is observable with transient signals that contain a step or
discontinuity. The phenomenon does not occur on sinusoidal signals. It only occurs
when a part of the frequency content of a signal is removed during data acquisition.
As we can compare from the above graphs, as the number of Harmonics increases,
the ringing effect increases.
In other words, As more frequency harmonics are truncated, the ringing artifact has
a longer duration and the transition is less sharp.
If the signal has no frequency content that is truncated, the Gibbs phenomenon does
not occur.
Finally at the infinite harmonic state, the ringing ceases and the perfect square wave
is formed.
The Gibbs phenomenon primary effects are in the time domain, not frequency
domain.

You might also like