1
votes

I am trying to add a noise file (.wav) file to a speech signal(.wav).

[b fs]=audioread('AzBio_01-01_S60.wav');
[babble fs1]=audioread('cafeteria_babble.wav');

The issue is that both the files have different sampling rates (fs=22050, fs1=44100).

When i add them it distorts the other signal since the sampling rate is different. How do i solve this. I am playing the sound via

 p=audioplayer (total,fs)
  play (p)
1

1 Answers

2
votes

The distortion will be due to the sample values summing to more than 1 not the sample rate differences. To deal with that risk divide both vectors by two before summing them.

That said, you do still need to deal with the sample rate difference. There are two ways of doing this: either reduce the sampling rate of the signal with the higher sampling rate or increase the sampling rate of the other signal.

Reducing the sampling rate of the signal with the higher rate is easier but comes with the disadvantage that you are actually losing data. You could do this by using resample. resample(babble, fs, fs1)

Alternatively you can upsample the signal with the lower sampling frequency. This won't give you any more data but it will mean the sample rates match. You can do this with interp1. b = interp1(1:length(b),b,0.5:0.5:length(b))

So in summary

[b fs]=audioread('AzBio_01-01_S60.wav'); 
[babble fs1]=audioread('cafeteria_babble.wav');
b = interp1(1:length(b),b,0.5:0.5:length(b)); % interpolate b to fs1
total = b/2 + babble/2; % sum at half the sample values
p=audioplayer (total,fs1);
play (p)