moving average formant added

This commit is contained in:
Loic Delattre 2023-03-27 15:16:46 +02:00
parent 97901aa917
commit 23a92f55cb
5 changed files with 18 additions and 13 deletions

View File

@ -2,7 +2,7 @@ clear all
close all close all
clc clc
% Modify the desired frequency foir the whole code here % Modify the desired frequency for the whole code here
desired_freq = 4000; desired_freq = 4000;
% Read and Set up coeficient % Read and Set up coeficient
[y, fs] = audioread("sound/modulator22.wav"); [y, fs] = audioread("sound/modulator22.wav");

BIN
one.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 263 KiB

View File

@ -3,32 +3,37 @@ close all
clc clc
[y, fs] = audioread("sound/modulator22.wav"); [y, fs] = audioread("sound/modulator22.wav");
ranges = [17000, 20000; 29000, 37000; 41000, 46000]; ranges = [17000, 21000; 30500, 36000; 41500, 46000];
one = y(ranges(1,1):ranges(1,2)); one = y(ranges(1,1):ranges(1,2));
two = y(ranges(2,1):ranges(2,2)); two = y(ranges(2,1):ranges(2,2));
three = y(ranges(3,1):ranges(3,2)); three = y(ranges(3,1):ranges(3,2));
word = one; word = three;
n = length(word); n = length(word);
f = (0:n-1)*(fs/n); f = (0:n-1)*(fs/n);
f1 = 0;%Hz f1 = 0;%Hz
f2 = 4000;%Hz f2 = 2500;%Hz
idx = find(f >= f1 & f <= f2); %define the index of the freq range idx = find(f >= f1 & f <= f2); %define the index of the freq range
f = f(idx); f = f(idx);
y = fft(word, n);% compute DFT of input signal y = fft(word, n);% compute DFT of input signal
power = abs(y).^2/n; power = abs(y).^2/n;
power = power(idx); power = power(idx);%limit the signal to the frequency ROI
[val, ind] = max(power); [val, ind] = max(power);
%lowpass for the formant %lowpass for the formant, moving average
Fc = 2000; % define the cutoff frequency of the low-pass filter
[b, a] = butter(6, Fc/(fs/2), 'low'); % design a 4th-order Butterworth low-pass filter
Pxx_filt = filter(b, a, power); % apply the filter to the power spectrum
length(Pxx_filt)
length(f)
for j = 1:length(idx)
tot = 0;
for k = j-18:j
if k <=0
tot = tot + power(1);
else
tot = tot + power(k);
endif
endfor
power_avg(j) = 1/6*(tot);
endfor
figure; figure;
@ -39,7 +44,7 @@ ylabel('Amplitude (a.u.)');
subplot(1,2,2) % freq range plot subplot(1,2,2) % freq range plot
plot(f,10*log10(power/power(ind))); hold on; plot(f,10*log10(power/power(ind))); hold on;
plot(f, 10*log10(Pxx_filt), 'r'); plot(f, 10*log10(power_avg/power(ind)), 'r');
xlabel('Frequency (Hz)') xlabel('Frequency (Hz)')
ylabel('Power (dB)') ylabel('Power (dB)')

BIN
three.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 74 KiB

BIN
two.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 81 KiB