% % This M-file is created for the first couple weeks of lectures of % EE321-Linear system I % % sigvisual.m -- Generate and visualize typical signals % @ Kefu Xue, Ph.D., Mar 27, 2001 % % signal I: f(t)= t^2[u(t)-u(t-10)] % % Creat an independent time variable deltaT=0.02; ts=-5; te=15; t=ts:deltaT:te; % -5<=t<=15 with 0.2 as deltaT, or simply t=-5:0.2:15; % %Generate the function indx01=find(t<0); %find indices for vector t such that t<0 z1=length(indx01);%find length of zeros in the first segment indx02=find(t>10);%find indices for vector t such that t>10 z2=length(indx02);%find length of zeros in the second segment indx1=find((t>=0) & (t<=10)); %find indices for vector t such that 0<=t<=10 f=[zeros(1,z1) t(indx1).^2 zeros(1,z2)]; plot(t,f); title('f(t)'); xlabel('time in second');ylabel('Unit'); pause stem(t,f); title('f(t) in stems'); xlabel('time in second');ylabel('Unit'); echo on Ef=sum(f.^2)*deltaT % check total energy echo off pause % % signal II: x(t)=2f(t-10) % tnew=t+10;% move the time index to the right by 10 units figure;subplot(2,1,1);plot(t,f,'g');title('original signal f(t)'); subplot(2,1,2);plot(tnew,2*f,'r');title('delayed signal'); % pause % % signal III: x(t)=f(-t) % tnew=-t; subplot(2,1,1);plot(t,f,'g');title('original signal f(t)'); subplot(2,1,2);plot(tnew,f,'r-.');title('flipped signal'); % pause % % signalIV: x(t)=-2f(-t+3) % tnew=-t+3; subplot(2,1,1);plot(t,f,'g');title('original signal f(t)'); subplot(2,1,2);plot(tnew,-2*f,'b--');title('flipped, reversed and shifted signal'); % pause % % signal V: x(t)=f(4t) % %Regenerate the function indx01=find(t<0); %find indices for vector t such that t<0 z1=length(indx01);%find length of zeros in the first segment indx02=find(t>10/4);%find indices for vector t such that t>10 z2=length(indx02);%find length of zeros in the second segment indx1=find((t>=0) & (t<=10/4)); %find indices for vector t such that 0<=t<=10/4 f4t=[zeros(1,z1) (4*t(indx1)).^2 zeros(1,z2)]; % (4t)^2 plot(t,f4t); title('f(4t)'); xlabel('time in second');ylabel('Unit'); % pause % signal VI: y(t)=3cos(20pit-pi/4) % w0=20*pi;% angular frequency of cos() function T0=2*pi/w0;% period of the signal % sample 20 samples for each period and plot 4 periods deltaT=T0/20; t=0:deltaT:4*T0; y=3*cos(20*pi*t-pi/4); % compared with cos() function without phase delay ynd=3*cos(20*pi*t); figure;plot(t,y,'g',t,ynd,'b--');title('cosine functions'); % echo on delayT=pi/4/w0 %check time delay pause Pav=sum(y.^2)/length(t) %check the average power, it should be 3^2/2=4.5 RMS=sqrt(Pav) % % Well what do you see? 4.5!! Mean Square Value!! echo off % pause % % if only 2 samples per period are used % deltaT=T0/2; t=0:deltaT:4*T0; y=3*cos(20*pi*t-pi/4); % compared with cos() function without phase delay ynd=3*cos(20*pi*t); plot(t,y,'g',t,ynd,'b--'); title('cosine functions with only 2 samples per period'); % pause close all %close all the open windows