## How can I generated Speech Shaped Noise(SSN)

### Eason (view profile)

on 3 Aug 2012
Latest activity Edited by Jacob D

on 14 Nov 2016

### Nike (view profile)

Hello all
I had followed a document from The University of Texas at Dallas, Speech Perception Laboratory. Thanks them. http://www.utdallas.edu/~assmann/hcs7367/lec8.pdf
They also provide code to calculate the long-term average speech spectrum. And according to the document I generated a Speech shaped noise already.
But, there some problem here. I use the code as below to generated SSN.
mag=10.^(ltass/20);
freq=linespace(0,1,length(mag));
FIR_ltass=fir2(512,freq,mag);
noise=randn(npts,1);
SSN=conv(noise,FIR_ltass);
where ltass as the Speech's LTASS that I used, and npts as the sample points of the speech shaped noise that I want to create. This is to make a FIR filter which had the response that same as the LTASS, then convoluted the FIR filter and white noise to generated a noise which had the same LTASS as speech.
After all, I calculated the Speech shaped noise's LTASS. As we can seen, the red line is Speech's LTASS and blue line is SSN's LTASS. Although they have same trend, but the SSN's amplitude was lower then Speech. They speech which I used to calculated LTASS are 320 sentences and all of those RMS are 0.075. And the SSN also adjust RMS to 0.075 to calculated LTASS.
I didn't know that this is normal result or I did wrong at somewhere?

### Nike (view profile)

on 9 Nov 2012

This should beable to solve your problem... cheers..
file = uigetfile('*.wav', 'Select the wave file');
data = data/sqrt((sum(data.^2))/length(data));
[a,g]= lpc(data,6);
noise = randn(length(data),1);
out= filter(g,a,noise);
finout = out/sqrt((sum(out.^2))/length(data));
[H,F] = freqz(g,a,256,fs);
plot(F,log(abs(H)),'b');
hold on
[a,g]= lpc(finout,6);
[H,F] = freqz(g,a,256, fs);
plot(F,log(abs(H)),'r');

Eason

### Eason (view profile)

on 9 Nov 2012
But, I had some problems. I change the lpc order from 6 to 125. Can I do that for more precise result?
And how can I produce the total 300 sentences' LTASS? This figure's red line is out from above code, and I use the code I had to calculate it's ltass and blue line is the code I had to calculate 300 sentences' Ltass then make SSN, and put back to calucate the SSN's LTASS. I thought the different may because the red line only present one sentence's LTASS and blue line is present total 300 sentences' average LTASS? If I use above code to make SSN, how can I get average LTASS from 300 sentences? wavread each file and divided by it's RMS and produce each file's lpc and then average [a,g] or RMS [a,g]?

### Jacob D (view profile)

on 14 Nov 2016
Edited by Jacob D

### Jacob D (view profile)

on 14 Nov 2016

I know this question is a few years old but here is a simple solution for the record...
(2) Put the toolbox into a class folder, +Tools, on the MATLAB search path.
(3) Run the following code with your noise signal and you'll get (1/n)-th octave smoothed speech shaped noise, SSN:
Fs = 16000; % Sampling frequency
Nfft = 1024; % FFT length
OctaveBandSpace = 1/6; % 1/6 octave band smoothing
noise; % White Gaussian Noise
% (or other statistically distributed white spectrum noise)
SpeechFolderOrVector = ... A folder path or vector of speech samples
'SpeechFiles\';
[spect, frqs] = Tools.LTASS... Compute LTASS spectrum
(SpeechFolderOrVector, Nfft, Fs );
SSN = Tools.ArbitraryOctaveFilt... Speech shaped noise
(noise, spect, frqs, Nfft, Fs, OctaveBandSpace);
Here is the spectrum I obtain with White Gaussian Noise and speech files from the TIMIT corpus:
sxx=pwelch(SSN/rms(SSN),rectwin(Nfft),0,Nfft,Fs,'power').^.5;
pl=plot(frqs/1e3,mag2db([spect,sxx]),'linewidth',2);pl(1).Color='r';pl(2).Color='b';
ax=gca;ax.XScale='log';fm=Fs/2/1e3;xlim([0.05 fm]);ax.XTick=[0.1,1,fm];grid on; grid minor;
xlabel('Frequency (kHz)');ylabel('Magnitude (dB)');legend({'LTASS';'SSN'}); ### Nike (view profile)

on 14 Nov 2012

Reading each file will take a rather long time, why dont you just normalize all the speech files, concatenate them and find the lpc of the whole signal and use its coefficients to generate the speech noise.typically it should bedone for all the speech files together.
You can use the below mentioned code for concatenating all the speech files in one go.
Coming to your other question about the order, I don't think an order of 125 should be a problem as long as the order is less than length(data)-1
files = uigetdir('C:\*.wav', 'Select the directory with the speech stimuli');
type = '\*.wav';
filepath = strcat(files,type);
files = dir(filepath);
nfiles = length(files);
list=1:1:nfiles;
files = char(files.name);
stimlist=files(list,:);
maxdur = 2;
for i = 1:nfiles
z = stimlist(i,:) ;
n = length(speech);
silence = maxdur*fs + 2*fs;
sil = silence-length(speech);
gap = zeros(sil,1);
signal = [speech;gap];
mix(:,i) = signal;
stretch = mix(:);
end
stretch = stretch/sqrt((sum(stretch.^2))/length(stretch));
[a,g]= lpc(stretch,125);
noise = randn(length(stretch),1);
out= filter(g,a,noise);
finout = out/sqrt((sum(out.^2))/length(stretch));
[H,F] = freqz(g,a,256,fs);
plot(F,log(abs(H)),'b');
hold on
[a,g]= lpc(finout,125);
[H,F] = freqz(g,a,256, fs);
plot(F,log(abs(H)),'r');
wavwrite(finout,fs,'speechnoise.wav')
Hope you find it useful,
Cheers
Nike

### Nike (view profile)

on 8 Mar 2016

Hi,
You can find a better version of code for generating the speech shaped noise in the attached link
regards,
Nike