I want to add PSNR, MSError and SNR to my ready code.
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (1)
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 Kommentare
Mert Sari
am 16 Jan. 2024
- Made some adjustments regarding padding. Please re-check.
- If still facing the issue. It would be helpful if you can share your specific 'f_ENCODER' and 'wav' file.
-----------------------------------------------------------------------------------------------------------------------------------------------------
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
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Feel free to contact me.
Image Analyst
am 16 Jan. 2024
@Mert Sari please attach 'C:\Users\user\Desktop\WAV\a1.wav' so we can try it ourselves.
Mert Sari
am 16 Jan. 2024
Kategorien
Mehr zu Audio and Video Data finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!