Stack Exchange
Add a sinusoid to a speech file in MATLAB
I have a speech file and I am attempting to add a sinusoid of frequency 300 Hz to this speech sample, with the following code:
% Add sine wave to speech signal
clear all; close all;
load spf2.mat;
% sound(speech)
pxx= pwelch(speech);
plot(pxx);
xlim([0 500]);
F0 = 300; %hz
Fs = 8000;                   % samples per second
dt = 1/Fs;                   % seconds per sample
StopTime = 2.74775;          % seconds
t = (0:dt:StopTime-dt)';     % seconds
y = sin(2*pi*F0*t);
newspeech = speech + y;
sound(newspeech)
pxx= pwelch(newspeech);
figure
plot(pxx);
xlim([0 500]);

However, this does not appear to be added to my signal properly.
The power spectrum of the original signal and the power spectrum of 'newspeech' (which should contain the original speech and the sinusoid) are exactly the same!

Fig 1: Power spectrum of original speech file from 0 to 500 Hz 

Fig 2: Power spectrum of new speech signal from 0 to 500 Hz 
Please let me know where I am going wrong.

Cold you post both images? there should be a bar at 300Hz on newspeach. Maybe you need to increase the power of the sinusoid

I meant to do that, sorry! it is editted.

Are they exactly the same? plot the difference to see...  There is a lot of power in the speech spectrum you're showing, and you're only adding a sine wave of amplitude 1.  Try multiplying the sine by some larger constant.

thank you, @tmpearce, that is true. If I use an amplitude of about 100000 you can notice the sine wave.

You have an scaling issue, this is the power of the sinusoid alone:

And the peak power of your audio signal is ~1E8
