I want to add PSNR, MSError and SNR to my ready code.
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(1 个)
Hassaan
2024-1-16
编辑:Hassaan
2024-1-16
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 个评论
Image Analyst
2024-1-16
@Mert Sari please attach 'C:\Users\user\Desktop\WAV\a1.wav' so we can try it ourselves.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!