MATLAB Answers

Is concatenation of signals possible in matlab

59 views (last 30 days)
Neels
Neels on 25 Jul 2011
I am trying to have a single graph, which has an exponential wave followed by an impulse and sine wave.
i can generated the signals independently.
My question is, how can i join the signals(like string concatenation).
Any idea is appreciated

  2 Comments

Chirag Gupta
Chirag Gupta on 25 Jul 2011
How are you generating the signals? Can you put some sample code in the question? If the signals are just vectors then you can just concatenate them like:
concat_signal = [exp_curve; imp_curve; sin_curve];
Neels
Neels on 25 Jul 2011
Hi thanks for the help. My program has the main program x.m which calls the subroutine y.m. I am trying to concatenate the two signals in the subroutine y.m
%% x.m
L=0.018
t_step= 0.1221
alpha= 0
L1=0.018
t_step1= 0.1221
alpha1= 0
m = y(L,t_step,alpha)+ y(L1,t_step1,alpha1);
%%y.m
function nt=y(L,t_step,alpha)
bt_new=0
ft_new=0
t_step=0.1221
vgroup = 2e8
it_new=0
t=-5:t_step:100
dx= (t_step*vgroup*1e-9)/2
N= L/t_step;
bt_new= exp(-alpha*t);
for l=0:2.0930e-03:N
ft = 10*exp(-((t-(l.*ones(size(t))*t_step)).^2-(2*l/vgroup))).*dx ;
ft_new =ft_new+ft;
end
yt= conv(ft_new,bt_new);
it= 20*log(yt)/log(10);
imp=zeros(size(t)*t_step);
imp(1.0)=1;
nt=[it;imp]
plot(nt,'-rx');
title 'intensity '
xlabel ''
ylabel ''
It shows the following error in the command window
Warning: Log of zero.
> In y at 26
In x at 9
Warning: Size vector should be a row vector with integer elements.
> In y at 28
In x at 9
??? Error using ==> vertcat
All rows in the bracketed expression must have the same
number of columns.
Error in ==> y at 31
nt=[it;imp]
Error in ==> x at 9
m = y(L,t_step,alpha)+ y(L1,t_step1,alpha1);

Sign in to comment.

Accepted Answer

Rick Rosson
Rick Rosson on 25 Jul 2011
Please try the following:
% Exponential signal:
u = exp(...);
% impulse signal:
v = zeros(...);
v(...) = 1;
% Sine wave:
w = cos(...);
% Concatinate the three signals:
x = [ u ; v ; w ] ;
The last line assumes that each of the tree signals is a column vector, where the rows are the discrete-time samples of the signals.
HTH.
Rick

  0 Comments

Sign in to comment.

More Answers (2)

Jan
Jan on 25 Jul 2011

  0 Comments

Sign in to comment.


Praveen Suvarna
Praveen Suvarna on 5 Nov 2012
x = [ u ; v ; w ] ; command may not work in all cases... It will overlap one signal on another.
try x = [ u v w ] ; command also. It will help you out.

  0 Comments

Sign in to comment.

Sign in to answer this question.