forked from YK-Yash/Digital_Hearing_Aid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplySkiSlope.m
79 lines (67 loc) · 1.65 KB
/
applySkiSlope.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function y = applySkiSlope(x,g,transitionV,fs);
first = transitionV(1);
second = transitionV(2);
third = transitionV(3);
fourth = transitionV(4);
x_length = length(x);
n = nextpow2(x_length);
N = 2^n;
T = 1/fs;
X = fft(x,N);
gain = zeros(N,1);
% Sets the gain for the first stage of frequencies
firstC = (.3*(g-1))/first;
k=0;
while(k/N <= first/fs)
gain(k+1) = firstC*k/(N*T) + 1;
gain(N-k) = gain(k+1);
k=k+1;
end;
% Sets the gain for the second stage of frequencies
secondC = firstC*first +1;
secondC2 = (second-first)/5;
while(k/N <= second/fs)
gain(k+1) = 1 + (secondC-1)*exp(-((k/(N*T))-first)/secondC2);
gain(N-k) = gain(k+1);
k=k+1;
end;
% Sets the gain for the third stage of frequencies
thirdC = 1 + (secondC-1)*exp(-second/secondC2);
thirdC2 = (third-second)/5;
while(k/N <= third/fs)
gain(k+1) = g + (thirdC-g)*exp(-((k/(N*T)-second))/thirdC2);
gain(N-k) = gain(k+1);
k=k+1;
end;
% Sets the gain for the fourth stage of frequencies
while(k/N <= fourth/fs)
gain(k+1) = g;
gain(N-k) = gain(k+1);
k=k+1;
end;
% Sets the gain for the fifth stage of frequencies
fifthC = g;
fifthC2 = (fs/2-fourth)/5;
while(k/N <= .5)
gain(k+1) = 1 + (fifthC-1)*exp(-((k/(N*T))-fourth)/fifthC2);
gain(N-k) = gain(k+1);
k=k+1;
end;
k_v = (0:N-1)/N;
plot(k_v,gain);%entire filter transfer function
figure;%non-redundant filter transfer function
k_v = k_v*fs;
k_v = k_v(1:N/2+1);
plot(k_v,gain(1:N/2+1));
title('Frequency Shaper Transfer Function');
xlabel('Frequency (Hertz)');
ylabel('Gain');
Y = X+gain;
y = real(ifft(Y,N));
y = y(1:x_length);
t=[0:1/fs:(x_length-1)/fs];
figure;
plot(t,y,'r');
%hold;
figure;
plot(t,x);