I want to add PSNR, MSError and SNR to my ready code.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mert Sari
el 16 de En. de 2024
Respondida: Mert Sari
el 17 de En. de 2024
Hello everyone, I'm doing research on an assignment that does LPC compression to a Speech file.
Here you see the code;
clear all;
clc;
%TAKING INPUT WAVEFILE,
a1 = 'C:\Users\user\Desktop\WAV\a1.wav';
[y, Fs] =audioread(a1);
% x=wavrecord(,);
%LENGTH (IN SEC) OF INPUT WAVEFILE,
t=length(y)./Fs;
sprintf('Processing the wavefile "%s"', a1)
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);
Additionally, I want this code to calculate PSNR, MSError and SNR.
dis=numel(y)-numel(A2);
A2=[A2,zeros(1,dis)];
PSNR = psnr(A2,y)
MSError=mse(A2,y)
SNR=snr(A2,y)
I found such a code on the internet. But I don't know what I should write instead of "A2" or for the others.
0 comentarios
Respuesta aceptada
Más respuestas (1)
Hassaan
el 16 de En. de 2024
Editada: Hassaan
el 16 de En. de 2024
clear all;
clc;
% TAKING INPUT WAVEFILE
a1 = 'C:\Users\user\Desktop\WAV\a1.wav';
[y, Fs] = audioread(a1);
% LENGTH (IN SEC) OF INPUT WAVEFILE
t = length(y) / Fs;
disp(['Processing the wavefile "', a1, '"'])
disp(['The wavefile is ', sprintf('%3.2f', t), ' seconds long'])
% THE ALGORITHM STARTS HERE
M = 10; % Prediction order
[aCoeff, pitch_plot, voiced, gain] = f_ENCODER(y, Fs, M); % Encoder function
synth_speech = f_DECODER(aCoeff, pitch_plot, voiced, gain); % Decoder function
% Ensure the original and reconstructed signals are of the same length
dis = numel(y) - numel(synth_speech);
% Get the size of the synth_speech array
[synth_rows, synth_cols] = size(synth_speech);
% Ensure the zero-padding array has the same number of columns
zero_padding = zeros(dis, synth_cols);
% Pad the shorter signal
synth_speech_padded = [synth_speech; zero_padding];
% Calculate PSNR, MSE, and SNR
PSNR = psnr(synth_speech_padded, y);
MSError = immse(synth_speech_padded, y); % Mean Squared Error
SNR = snr(synth_speech_padded, y);
% Display the results
disp(['PSNR: ', num2str(PSNR), ' dB']);
disp(['Mean Squared Error: ', num2str(MSError)]);
disp(['SNR: ', num2str(SNR), ' dB']);
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
4 comentarios
Image Analyst
el 16 de En. de 2024
@Mert Sari please attach 'C:\Users\user\Desktop\WAV\a1.wav' so we can try it ourselves.
Ver también
Categorías
Más información sobre Spectral Measurements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!