Neural Networks & Fuzzy Logic (EEE 408) Assignment: Anujoy Chakraborty 12BEI0016

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

NEURAL NETWORKS & FUZZY LOGIC

(EEE 408)
ASSIGNMENT

Anujoy Chakraborty 12BEI0016

load('soundA.mat')
load('soundB.mat')
load('soundC.mat')
load('soundD.mat')
%Complete Matrix of the guitar notes
sample1=[soundA1 soundA2 soundA3 soundA4
soundA5 soundA6 soundA7 soundA8 soundA9
soundA10];
sample2=[soundB1 soundB2 soundB3 soundB4
soundB5 soundB6 soundB7 soundB8 soundB9
soundB10];
sample3=[soundC1 soundC2 soundC3 soundC4
soundC5 soundC6 soundC7 soundC8 soundC9
soundC10];
sample4=[soundD1 soundD2 soundD3 soundD4
soundD5 soundD6 soundD7 soundD8 soundD9
soundD10];
%Plotting FFT
for i=1:10
ft1(:,i)=(fft(sample1(:,i),1024));
ft2(:,i)=(fft(sample2(:,i),1024));
ft3(:,i)=(fft(sample3(:,i),1024));
ft4(:,i)=(fft(sample4(:,i),1024));
end

N=1024;
fs=48000;
%Throwing Away Second half and calculating
absolute
for i=1:10
ft1((1:N/2),i)=abs(ft1((1:N/2),i));
ft2((1:N/2),i)=abs(ft2((1:N/2),i));
ft3((1:N/2),i)=abs(ft3((1:N/2),i));
ft4((1:N/2),i)=abs(ft4((1:N/2),i));
end
f = (0:N/2-1)*fs/N;
subplot 411
plot(f,ft1(1:(size(ft1)/2),3));
title('Sample A');
xlabel('Frequency in Hertz');
ylabel('Amplitude')
subplot 412
plot(f,ft2(1:(size(ft2)/2),3));
title('Sample B');
xlabel('Frequency in Hertz');
ylabel('Amplitude');
subplot 413
plot(f,ft3(1:(size(ft3)/2),3));
title('Sample C');
xlabel('Frequency in Hertz');
ylabel('Amplitude');
subplot 414

plot(f,ft4(1:(size(ft4)/2),3));
title('Sample D');
xlabel('Frequency in Hertz');
ylabel('Amplitude');
for i=1:10
analy1((1:25),i)=ft1((1:25),i);
analy2((1:25),i)=ft2((1:25),i);
analy3((1:25),i)=ft3((1:25),i);
analy4((1:25),i)=ft4((1:25),i);
end
%LVQ Algorithm
x=[analy1 analy2 analy3 analy4];
% t=target;
t(1,1:10)=1;
t(1,11:20)=2;
t(1,21:30)=3;
t(1,31:40)=4;
% learning rate
alpha=0.11;
% initialization of weight vectors
w(:,1)=x(:,1);
w(:,2)=x(:,11);
w(:,3)=x(:,21);
w(:,4)=x(:,31);

epoch=10;
a(1)=alpha;
for k=1:epoch
a(k+1)=alpha/10;
for p=1:size(x,2)
d(1)=sum((x(:,p)-w(:,1)).^2);
d(2)=sum((x(:,p)-w(:,2)).^2);
d(3)=sum((x(:,p)-w(:,3)).^2);
d(4)=sum((x(:,p)-w(:,4)).^2);
[j h]=min(d);
if h==t(1,p)
w(:,1)=w(:,1)+a(k)*(x(:,p)-w(:,1));
else
w(:,h)=w(:,h)-a(k)*(x(:,p)-w(:,h));
end
end
a(k)=alpha/10;
end
% Testing
for p=1:size(x,2)
d(1)=sum((x(:,p)-w(:,1)).^2);
d(2)=sum((x(:,p)-w(:,2)).^2);
d(3)=sum((x(:,p)-w(:,3)).^2);
d(4)=sum((x(:,p)-w(:,4)).^2);

[j h]=min(d);
answer(p)=h;
check(p,:)=d;
end
answer
check;

ALGORITHM
1.Load the sample matrix.
2. Calculate the 1024 point FFT of the
sample data.
3. Calculate the absolute value of the FFT
array and consider only the first half of
the array (i.e 512 samples in this case)
4. Plot the samples of the FFT array.
5. Generate another array which consists of
the first 25 values of the FFT array.
6. Feed this array into the LVQ algorithm.
7. Run the algorithm for the necessary
number of epochs.
8. Generate the solution array.

Solution Array

Plot of the sample data in freq. domain

You might also like