Discrete Fourier Series Lab

Solution

Task 2

ali_rahmanlab3

Contents

Audio Input

Read audio file and extract one thousand samples from it.

close all;clear all; clc;
[y Fs]=audioread('FunFreq100_corr.wav');
x=y(1:1000);

Configure analysis parameters

Set the period of the audio in number of samples and the number of fourier coefficients to be analyzed.

N=441;

K_thresh is equal to half of (number of coefficients - 1)

k_thresh=50;

Calculate Discrete fourier coefficients

Analysis equation is implemented to evaluate the coefficients.

for k=(-1*k_thresh):1:k_thresh
    sum=0;
    for n=1:N
        inter=x(n)*exp(-j*2*pi*k*n/N);
        sum=sum+inter;
    end
    a_k(k+k_thresh+1)=sum/N;
    al=abs(a_k);
end

Plot of Fourier Series Coefficients

coff_vector= (-1*k_thresh):1:k_thresh;
figure
stem(coff_vector,al);
xlabel('a_k');
ylabel('Magnitude');
title('Fourier coefficients of audio sample');

Reconstruction

Synsthesis equation is implemented to reconstruct signal using fourier series coefficents

for n=1:1000
    sum2=0;
    for k2=1:((2*k_thresh)+1)
        inter2=a_k(k2)*exp(j*2*pi*k2*n/N);
        sum2=sum2+inter2;
    end
    z(n)=abs(sum2);
end

Plot of reconstructed signal

The synthesised signal is plotted and compared to the original signal.

figure
subplot(2,1,1);
plot(x);
xlabel('Samples');
ylabel('Amplitude');
title('Original');
subplot(2,1,2);
plot(z);
xlabel('Samples');
ylabel('Amplitude');
title('Reconstruction');

Robotics & Dynamic Systems Lab