Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to calculate PSNR of audio files using MATLAB

Status
Not open for further replies.

mariach

Newbie level 3
Joined
May 23, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,309
hello,

i'm working on my project and i have some difficulty in calculating PSNR of an audio file(.wav) using matlab.
can anyone give me a code or tell me how to calculate it?

thanks in advance.
 
Last edited:

Hi

Well from your statement, it seems that you might have two audio files .. one which is original and other would be with some distorted.

Then you can create a function

1. Read two files in variables (Lets say A & B)
2. get the diff. of variables as follow
if A ==B -> display message that "Two file is identical" and PSNR = inf
otherwise
get diff of two vector as diff = A-B;

3. use PSNR formula 20*log10(max(original_sig/ variable which store original sig)/(sqrt(mean(mean(diff.^2)))));
20* log10 ensures that o/p is in dB


Thanks
 
  • Like
Reactions: sogi

    sogi

    Points: 2
    Helpful Answer Positive Rating
In order to calculate the Signal to Noise ratio....you first know the reference signal and signal corrupted with noise then the konarkk methodology works.....But in case you want to analysis of single file then you need to first fix what kind of noise that you want to analysis....like low frequency noise or high frequency noise etc....

Good Luck
 

- - - Updated - - -

Hi

Well from your statement, it seems that you might have two audio files .. one which is original and other would be with some distorted.

Then you can create a function

1. Read two files in variables (Lets say A & B)
2. get the diff. of variables as follow
if A ==B -> display message that "Two file is identical" and PSNR = inf
otherwise
get diff of two vector as diff = A-B;

3. use PSNR formula 20*log10(max(original_sig/ variable which store original sig)/(sqrt(mean(mean(diff.^2)))));
20* log10 ensures that o/p is in dB


Thanks


Thank you konarkk for your reply. But i cannot exactly understand when you write on the psnr formula "original_sig/ variable which store original sig".

in my code i have to audio files :

[temp,f]=wavread('voice1.wav');
temp=temp';
s=temp(1,:);
N=length(s);

[temp,f]=wavread('voice2.wav');
temp=temp';
s(2,:)=temp(1,1:N);

i mix them and then using fastICA i get back the unmixed signs.
I study 4 cases. 2,3,4 and 5 microphones and i'm trying to find if the increase of mics gives better results(higher psnr).

"variable which store original sig" :do you mean my s(1,;) ?
but which is the "original_sig" ?

Any help would be appreciated! thank you
 

- - - Updated - - -




Thank you konarkk for your reply. But i cannot exactly understand when you write on the psnr formula "original_sig/ variable which store original sig".

in my code i have to audio files :

[temp,f]=wavread('voice1.wav');
temp=temp';
s=temp(1,:);
N=length(s);

[temp,f]=wavread('voice2.wav');
temp=temp';
s(2,:)=temp(1,1:N);

i mix them and then using fastICA i get back the unmixed signs.
I study 4 cases. 2,3,4 and 5 microphones and i'm trying to find if the increase of mics gives better results(higher psnr).

"variable which store original sig" :do you mean my s(1,;) ?
but which is the "original_sig" ?

Any help would be appreciated! thank you



@ Mariach:-

From code snipplet it is evident that you are reading two signal as voice1.wav & voice2.wav. From Later steps it is clear , "s" is your signal which is mixed.
Since your code snipplet used temp variable to store original signal data, so in technical sense , original signal has been lost, though temp variable still remain in MATLAB workspace , however it will point to voice2.wav data which is not helpful. so first clear off temp

Now as you have mentioned that you have recovered two unmixed signals using FastICA so now you have two signals : recovered_voice1.wav & recovered_voice2.wav

and your mixed signal "s"

So to get PSNR of your "s" signal -> "s" is the orig_signal (Technically , mixed signal) or in other words an referenced signal

so you will get 2 cases for psnr :- "s" (original signal) & recovered_voice1(derived ) (though it was actual before implementation of algo.)

& other "s" (original signal) & recovered_voice2(derived )

Hope this helps

Thanks
Konark
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top