Effacer les filtres
Effacer les filtres

How do I calculate the compression ratio of my LPC code.

3 vues (au cours des 30 derniers jours)
Mert Sari
Mert Sari le 20 Jan 2024
Commenté : Mert Sari le 22 Jan 2024
%MAIN BODY
clear all;
clc;
%TAKING INPUT WAVEFILE,
inpfilenm = 'a1.wav';
[y, Fs] =audioread(inpfilenm);
% x=wavrecord(,);
%LENGTH (IN SEC) OF INPUT WAVEFILE,
t=length(y)./Fs;
sprintf('Processing the wavefile "%s"', inpfilenm)
sprintf('The wavefile is %3.2f seconds long', t)
%THE ALGORITHM STARTS HERE,
M=10; %prediction order
[aCoeff, pitch_plot, voiced, gain] = f_ENCODER(y, Fs, M); %pitch_plot is pitch periods
synth_speech = f_DECODER (aCoeff, pitch_plot, voiced, gain);

Réponse acceptée

Shubh
Shubh le 22 Jan 2024
Hi,
The compression ratio is a measure of how much the data has been reduced in size after applying a compression algorithm. In this case, I assumed a simple compression model where the original signal is represented by LPC (Linear Predictive Coding) coefficients. Here's the complete code:
%MAIN BODY
clear all;
clc;
% TAKING INPUT WAVEFILE
inpfilenm = 'a1.wav';
[y, Fs] = audioread(inpfilenm);
% LENGTH (IN SEC) OF INPUT WAVEFILE
t = length(y) / Fs;
sprintf('Processing the wavefile "%s"', inpfilenm)
sprintf('The wavefile is %3.2f seconds long', t)
% THE ALGORITHM STARTS HERE
M = 10; % prediction order
[aCoeff, pitch_plot, voiced, gain] = f_ENCODER(y, Fs, M); % pitch_plot is pitch periods
synth_speech = f_DECODER(aCoeff, pitch_plot, voiced, gain);
% CALCULATING COMPRESSION RATIO
original_size = numel(y) * 2 * 8; % 16 bits per sample
encoded_size = numel(aCoeff) * 8; % assuming each coefficient is 64 bits
compression_ratio = original_size / encoded_size;
disp(['Compression Ratio: ', num2str(compression_ratio)]);
The compression ratio is then displayed using "disp(['Compression Ratio: ', num2str(compression_ratio)]);".
Hope this helps!

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by