Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
Mert Sari
Mert Sari am 20 Jan. 2024
Kommentiert: Mert Sari am 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);

Akzeptierte Antwort

Shubh
Shubh am 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!

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by