2020-10-30 19:54:44 +00:00
|
|
|
%% lpss_lpc.m
|
|
|
|
%%
|
|
|
|
%% Load wav and calculate LPC coeffs
|
|
|
|
|
2020-11-03 22:21:19 +00:00
|
|
|
close all;clear all;clc;
|
2020-10-30 19:54:44 +00:00
|
|
|
|
2020-11-03 22:21:19 +00:00
|
|
|
ORDER = 50;
|
2020-10-30 19:54:44 +00:00
|
|
|
DISPLAY_SAMPLES = 1000;
|
|
|
|
|
|
|
|
% READ SIGNAL
|
|
|
|
[y, Fs] = audioread('samples/hood_m.wav');
|
2020-11-03 22:21:19 +00:00
|
|
|
L = length(y) % number of samples
|
2020-10-30 19:54:44 +00:00
|
|
|
DISPLAY_SAMPLES = min([DISPLAY_SAMPLES L]);
|
|
|
|
|
2020-11-03 22:21:19 +00:00
|
|
|
% CALCULATE FFT
|
|
|
|
[freq_dom_freqs, freq_dom_vals] = fft_(y, Fs);
|
|
|
|
|
2020-11-07 18:35:24 +00:00
|
|
|
index = 1;
|
|
|
|
|
2020-11-03 22:21:19 +00:00
|
|
|
for ITER=1:5:ORDER
|
2020-10-30 19:54:44 +00:00
|
|
|
|
2020-11-07 18:35:24 +00:00
|
|
|
subplot(4, 2, index);
|
|
|
|
|
2020-10-30 19:54:44 +00:00
|
|
|
% LPC
|
|
|
|
a = lpc(y,ITER); % signal, filter order
|
2020-11-03 22:21:19 +00:00
|
|
|
|
|
|
|
% COMPARE FREQ DOMAIN
|
|
|
|
[h, filter_freqs] = freqz(1, a, length(freq_dom_freqs), Fs);
|
|
|
|
|
|
|
|
figure(1)
|
2020-11-07 18:35:24 +00:00
|
|
|
%% SIGNAL FFT RESPONSE
|
|
|
|
orig_freq_plot = plot(freq_dom_freqs, 20*log10(abs(freq_dom_vals)), 'black');
|
|
|
|
orig_freq_plot.Color(4) = 0.1;
|
|
|
|
orig_freq_plot.LineWidth = 1;
|
|
|
|
hold on
|
|
|
|
|
|
|
|
%% LPC FILTER RESPONSE
|
|
|
|
[filter_vals, filter_freqs] = freqz(1, a, length(freq_dom_freqs), Fs);
|
|
|
|
filter_vals_db = 20*log10(abs(filter_vals));
|
|
|
|
|
|
|
|
lpc_freq_plot = plot(filter_freqs, filter_vals_db, 'b');
|
|
|
|
lpc_freq_plot.LineWidth = 2;
|
|
|
|
|
|
|
|
%% ARYULE FILTER RESPONSE
|
|
|
|
ary = aryule(y, ITER);
|
|
|
|
[filter_vals, filter_freqs] = freqz(1, ary, length(freq_dom_freqs), Fs);
|
|
|
|
filter_vals_db = 20*log10(abs(filter_vals));
|
|
|
|
|
|
|
|
lpc_freq_plot = plot(filter_freqs, filter_vals_db, 'r');
|
|
|
|
lpc_freq_plot.LineWidth = 1;
|
|
|
|
|
|
|
|
%% ARCOV FILTER RESPONSE
|
|
|
|
arc = arcov(y, ITER);
|
|
|
|
[filter_vals, filter_freqs] = freqz(1, arc, length(freq_dom_freqs), Fs);
|
|
|
|
filter_vals_db = 20*log10(abs(filter_vals));
|
|
|
|
|
|
|
|
lpc_freq_plot = plot(filter_freqs, filter_vals_db, 'g');
|
|
|
|
lpc_freq_plot.LineWidth = 1;
|
|
|
|
|
|
|
|
% % MAXIMA
|
|
|
|
% % estimate formant frequencies from maxima of LPC filter freq response
|
|
|
|
% maxima = islocalmax(filter_vals_db);
|
|
|
|
% maxima_freqs = filter_freqs(maxima)
|
|
|
|
% maxima_db = filter_vals_db(maxima);
|
|
|
|
%
|
|
|
|
% if length(maxima_freqs) ~= 0
|
|
|
|
% maxima_plot = plot(maxima_freqs, maxima_db, 'rx');
|
|
|
|
% maxima_plot.MarkerSize = 12;
|
|
|
|
% maxima_plot.LineWidth = 2;
|
|
|
|
% end
|
|
|
|
|
|
|
|
% plot(freq_dom_freqs, 20*log10(freq_dom_vals), 'r', filter_freqs, 20*log10(abs(h)), 'b')
|
2020-11-03 22:21:19 +00:00
|
|
|
% plot(w/pi, 20*log10(abs(h)))
|
2020-11-07 18:35:24 +00:00
|
|
|
hold off
|
2020-10-30 19:54:44 +00:00
|
|
|
grid
|
2020-11-03 22:21:19 +00:00
|
|
|
xlabel('Frequency (Hz)')
|
|
|
|
ylabel('Magnitude (dB)')
|
2020-11-07 18:35:24 +00:00
|
|
|
% legend('Original Signal', 'LPC Filter', 'Local Maxima')
|
|
|
|
legend('Original Signal', 'LPC Filter', 'Aryule LPC Filter', 'Arcov LPC Filter')
|
|
|
|
title(strcat(['LPC Spectra: Order ' num2str(ITER)]));
|
2020-10-30 19:54:44 +00:00
|
|
|
|
2020-11-03 22:21:19 +00:00
|
|
|
% COMPARE TWO SIGNALS TIME DOMAIN
|
|
|
|
% est_y = filter(0.02, a, y);
|
|
|
|
% x = 1:DISPLAY_SAMPLES;
|
2020-10-30 19:54:44 +00:00
|
|
|
% figure(2)
|
2020-11-03 22:21:19 +00:00
|
|
|
% plot(x, y(end-DISPLAY_SAMPLES+1:end), x, est_y(end-DISPLAY_SAMPLES+1:end), '--')
|
|
|
|
% %plot(x, y(end-DISPLAY_SAMPLES+1:end))
|
|
|
|
% %plot(x, est_y(end-DISPLAY_SAMPLES+1:end))
|
2020-10-30 19:54:44 +00:00
|
|
|
% grid
|
2020-11-03 22:21:19 +00:00
|
|
|
% xlabel('Sample Number')
|
|
|
|
% ylabel('Amplitude')
|
|
|
|
% legend('Original signal','LPC estimate')
|
|
|
|
|
2020-11-07 18:35:24 +00:00
|
|
|
index = index + 1;
|
2020-10-30 19:54:44 +00:00
|
|
|
|
|
|
|
end
|