MATLAB: Mixing two signals together

lengthmatrix manipulationsignals

Hi there, I am trying to mix two signals together in order to display the frequency spectrum. I am running into matrix dimension errors however. How do I fix this? I am fairly new to matlab so if someone could provide code that would be great! Here is what I have so far:
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load chirp.mat;
fs=8192; % sampling frequency in hz. The "laughter" samples were obtained using Fs=8192. You should not change this value here.
length(y) = 0:1/fs:70000;
lngth2=length(y); % get the number of samples

load handel;
length(y) = 0:1/fs: 70000;
lngth1 = length(y);
lngth3=lngth1 + lngth2; % get the number of samples
t03 = lngth3/fs; % signal duration
t=0:1/fs:t03-1/fs; % create the time index (for t-axis), 0, ts, 2ts,....
ylau3=y(1:lngth3)'; % save the first lngth samples to a variable ylau.
% this step is optional
sound(ylau3,fs); % play the samples
fylau3=fft(ylau3,2*lngth3); % FFT of ylau, this results in the one-sided spectrum
fylaus3=fftshift(fylau3); % fftshift to make the spectrum plot symmetric about f=0, i.e., two-sided spectrum
df3 = fs/length(fylaus3); % create unit frequency step for the frequency-axis (horizontal axis)
fw3=[-fs/2:df3:fs/2-df3]; % frequency range is between -fs/2 to fs/2
y_db3 = 20*log10(abs(fylaus3)./max(abs(fylaus3)));%normalized magnitude spetrum in dB
% axis is in Hz
plot(fw3/1000,y_db3); % obtain the magnitude spectrum plot where frequency axis is in kHz
xlabel('frequency (KHz)');
ylabel('Magnitude (dB)');
title('Frequency spectrum');
grid;

Best Answer

By the way, "mixing" in signal processing means multiplying. However after looking at the spectrum of the signals I am taking the guess that the problem is meant to show how signal spectra sum. To see what I mean try to run this, then see the difference replacing y3 = y1+y2 with y3 = y1.*y2
load chirp.mat;
y1 = y;
load handel.mat;
y2 = y;
MinimumLength = min([length(y1), length(y2)]);
y1 = y1(1:MinimumLength);
y2 = y2(1:MinimumLength);
y3 = y1+y2;
NFFT = 2^nextpow2(MinimumLength);
f = Fs/2*linspace(0,1,NFFT/2+1);
Y1 = fft(y1,NFFT)/MinimumLength;
figure;
plot(f,2*abs(Y1(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
Y2 = fft(y2,NFFT)/MinimumLength;
figure;
plot(f,2*abs(Y2(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
Y3 = fft(y3,NFFT)/MinimumLength;
figure;
plot(f,2*abs(Y3(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')