Adding noise to speech signal - matlab

I'm attempting to add noise to a speech signal (.wav file) in matlab using the following method:
load handel.mat;
hfile= 'noisy.wav';
y = wavread('daveno.wav');
y = y + randn(size(y)) * (1/100);
wavwrite(y, Fs, hfile);
nsamples=Fs;
This adds the noise, however, it removes the actual speech spoken word and therefore, the noise is only contained. Do I need to multiply by a bigger number, or, could anyone please suggest a way to fix this problem?

The issue is that you are writing the file at the wrong sampling frequency. Find the correct sampling frequency (i.e. the value for Fs) using the second output of wavread
[y, Fs] = wavread('daveno.wav')

Related

detecting DTMF digits from mat file [duplicate]

Here is the context of the problem: I have a DTMF signal in wav format, I have to identify the number sequence it has encoded. I must do so using fast fourier transform in Matlab, implying that I read the wav file using wavread and to identify each number that is seperated by 40ms silence or more.
Here is my code so far:
[signal, fs] = wavread( 'C:\Temp\file.wav' ); % here, fs = 8000Hz
N = 512;
T = 1/fs;
L = length( signal )
samples = fs / 1000 * 40
windows = floor(L / samples)
t = (1:L)/fs;
figure(1), plot(t, signal);
Here is what the figure 1 looks like, that is the signal read from the wav:
How can I effectively split the signal into pieces so that I can then do an FFT on each of the 10 pieces seperately to decode the corresponding numbers?
I would recommend the following approach:
Find the envelope of the signal in the time domain (see Hilbert transform).
Smooth the envelope a bit.
Take the diff and find peaks to get the onsets of the tones.
Use the onsets to pick frames and find the spectrum using fft.
Find the index of the max in each of the spectrums and convert them to a frequency.
The tricky part in this is to get a robust onset detector in point 3. The peaks in the difference you pick, has to be of a certain size in order to qualify as on onset. If your tones are of varying strength this might pose a problem, but from your image of the time signal it doesn't seem like a problem.
Regards
This worked for me:
windowSize = 256;
nbWindows = floor(L / windowSize);
for i=1:nbWindows
coeffs = fft(signal((i-1)*windowSize+1:i*windowSize));
plot(abs(coeffs(1:N)));
waitforbuttonpress
end;
This way it is possible to shift the window until the end of the input signal

How to convert a signal into sound in MATLAB?

I'm trying to make a MATLAB program that converts a input 128-bit data using quadrature amplitude modulation (QAM, function qammod):
M = 16;
x = randint( 5000, 1, M);
y = modulate( modem.qammod(M), x);
But when I try to play the modulated signal using the sound(y) command, it does not allow me to do so.
I tried to make it work by doing real(y). It can be played, but data was lost. How do I make this data heard by a human while keeping its data?
I think it is possible, because in the old time people accessed the Internet over a phone line, on which the digital data can be converted to a sound signal.
Instead of using only in-phase component with real(y), you can use abs(y) which gives the magnitude of in-phase and quadrature components.
But, I would assign 16 distinct frequencies to each 16 symbols and perform something similar to FM (frequency modulation).

Splitting a DTMF signal from a wav file using Matlab

Here is the context of the problem: I have a DTMF signal in wav format, I have to identify the number sequence it has encoded. I must do so using fast fourier transform in Matlab, implying that I read the wav file using wavread and to identify each number that is seperated by 40ms silence or more.
Here is my code so far:
[signal, fs] = wavread( 'C:\Temp\file.wav' ); % here, fs = 8000Hz
N = 512;
T = 1/fs;
L = length( signal )
samples = fs / 1000 * 40
windows = floor(L / samples)
t = (1:L)/fs;
figure(1), plot(t, signal);
Here is what the figure 1 looks like, that is the signal read from the wav:
How can I effectively split the signal into pieces so that I can then do an FFT on each of the 10 pieces seperately to decode the corresponding numbers?
I would recommend the following approach:
Find the envelope of the signal in the time domain (see Hilbert transform).
Smooth the envelope a bit.
Take the diff and find peaks to get the onsets of the tones.
Use the onsets to pick frames and find the spectrum using fft.
Find the index of the max in each of the spectrums and convert them to a frequency.
The tricky part in this is to get a robust onset detector in point 3. The peaks in the difference you pick, has to be of a certain size in order to qualify as on onset. If your tones are of varying strength this might pose a problem, but from your image of the time signal it doesn't seem like a problem.
Regards
This worked for me:
windowSize = 256;
nbWindows = floor(L / windowSize);
for i=1:nbWindows
coeffs = fft(signal((i-1)*windowSize+1:i*windowSize));
plot(abs(coeffs(1:N)));
waitforbuttonpress
end;
This way it is possible to shift the window until the end of the input signal

Using Matlab FFT to extract frequencies from EEG signal

I am new to BCI. I have a Mindset EEG device from Neurosky and I record the Raw data values coming from the device in a csv file. I can read and extract the data from the csv into Matlab and I apply FFT. I now need to extract certain frequencies (Alpha, Beta, Theta, Gamma) from the FFT.
Where Delta = 1-3 Hz
Theta= 4-7 Hz
Alpha = 8-12 Hz
Beta = 13-30 Hz
Gamma = 31-40 Hz
This is what I did so far:
f = (0:N-1)*(Fs/N);
plot(rawDouble);
title ('Raw Signal');
p = abs(fft(rawDouble));
figure,plot (f,p);
title('Magnitude of FFT of Raw Signal');
Can anyone tell me how to extract those particular frequency ranges from the signal?? Thank you very much!
For convenient analysis of EEG data with MatLab you might consider to use the EEGLAB toolbox (http://sccn.ucsd.edu/eeglab/) or the fieldtrip toolbox (http://fieldtrip.fcdonders.nl/start).
Both toolboxes come with good tutorials:
http://sccn.ucsd.edu/eeglab/eeglabtut.html
http://fieldtrip.fcdonders.nl/tutorial
You may find it easier to start off with MATLAB's periodogram function, rather than trying to use the FFT directly. This takes care of windowing the data for you and various other implementation details.
I think the easiest way is to filter your signal in those ranges after you load your data.
E.g.
band=[30 100] eeglocal.lowpass(band(2)).highpass(band(1));
then you can use select the time you want to process.
That should be all you need.

MATLAB - Mixing wav files of different sampling frequencies

Basically I have a school project where I must create a new wave file from a given wave file. This new wave must be created in Matlab and the only difference is that a sine wave is to be mixed with the given wav file (not concatenated onto the end..). The sine wave is to be of 500hz.
My code so far is:
clear;
filename = 'C:\Documents and Settings\cmh0007\My Documents\rofl.wav';
[y, Fs, nbits, readinfo] = wavread(filename);
duration = numel(y) / Fs;
sinefs = 0:0.002:duration;
sinwave = 0.5*sin(2*pi*sinefs);
disp(size(y));
disp(size(sinwave));
newsignal = y + sinwave;
subplot(2,2,1), plot(y), title('Entire waveform');
subplot(2,2,3), plot(sinwave), title('sine waveform');
subplot(2,2,2), plot(newsignal), title('added waveform');
however, this code fails on creating the newsignal variable. The issue is that the two matrices are of different sizes due to the sampling rates differing between the two waves.
The output of the size calls are as follows:
797696 2
1 18089
Seeing as these files differ in sizes by a factor of ~44 I figured I could simply use the same sample from the sin wave 44 times over for each sample of the given wave file. However, because the difference is not exactly 44 I don't know if this is even an option.
Does anyone have any suggestions on how to go about mixing these two files?
Try changing 0.002 to 1/Fs. That way you'll have the same sampling rate. You should also choose only one of the stereo channels for y and do an appropriate transpose.
You might also consider changing the name sinefs to sinet or something as it represents the time parameter and not the sampling frequency.