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 samplest03 = 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