Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function x = gen_fn(c)
- global sp ep sf bp t;
- %t=linspace(sp,ep,sf*(ep-sp)+1);
- clc;
- fprintf('Do you want to plot a continuous or a discrete signal ?\n');
- cd=lower(input('Your Choice : ','s'));
- if not(strcmp(cd,'continuous') || strcmp(cd,'discrete'))
- fprintf('Invalid Input !\n\n');
- x=-1;
- return;
- end
- switch c
- case 1
- %Here comes the code for Sinusoidal Plotting .
- %f=A*sin(2*pi*f*t+(ph*pi/180))
- fprintf('\nYour choice was Sinusoidal !\n\n');
- if bp
- sep=str2num(input('Enter this function''s end point ','s'));
- t=linspace(sp,sep,sf*(sep-sp)+1);
- bp=bp-1;
- sp=sep;
- end
- A=str2num(input('Amplitude : ','s'));
- ps=str2num(input('Phase Shift in degrees : ','s'));
- fq=str2num(input('Frequency : ','s'));
- f=A*sin(2*pi*fq*t+(ps*pi)/180);
- if strcmp(cd,'continuous')
- plot(t,f,'r');
- else
- stem(t,f,'r');
- end
- hold on;
- case 2
- %Here comes the code for DC Plotting .
- fprintf('\nYour choice was DC !\n\n');
- if bp
- sep=str2num(input('Enter this function''s end point ','s'));
- t=linspace(sp,sep,sf*(sep-sp)+1);
- bp=bp-1;
- sp=sep;
- end
- dcv=str2num(input('DC value : ','s'));
- x=linspace(sp,ep,sf*(ep-sp)+1);
- y=x*0;
- z=0;
- for i=linspace(sp,ep,sf*(ep-sp)+1);
- z=z+1;
- if (i==0) y(z:length(y))=1;break; end
- end
- if strcmp(cd,'continuous') plot(x,dcv*y);
- else stem(x,dcv*y); end
- axis();
- xlabel('t');
- ylabel('DC Function');
- hold on;
- case 3
- %Here comes the code for Ramp Plotting .
- fprintf('\nYour choice is Ramp !\n\n');
- if bp
- sep=str2num(input('Enter this function''s end point ','s'));
- t=linspace(sp,sep,sf*(sep-sp)+1);
- bp=bp-1;
- sp=sep;
- end
- slope=str2num(input('Ramp slope : ','s'));
- intrspt=str2num(input('Interception with Y-axix : ','s'));
- if strcmp(cd,'continuous') plot(t,slope*t+intrspt);
- else stem(t,slope*t+intrspt); end
- xlabel('t');
- ylabel('Ramp function');
- hold on;
- case 4
- %Here comes the code for Exponential Plotting .
- fprintf('\nYour choice was Exponential !\n\n');
- if bp
- sep=str2num(input('Enter this function''s end point ','s'));
- t=linspace(sp,sep,sf*(sep-sp)+1);
- bp=bp-1;
- sp=sep;
- end
- A=str2num(input('Amplitude : ','s'));
- ec=str2num(input('Exponential constant : ','s'));
- f=exp(ec*t);
- if strcmp(cd,'continuous')
- plot(t,f,'b');
- else
- stem(t,f,'b');
- end
- hold on;
- case 5
- %Here comes the code for impulse Plotting .
- fprintf('\nYour choice was Impulse !\n\n');
- if bp
- sep=str2num(input('Enter this function''s end point ','s'));
- t=linspace(sp,sep,sf*(sep-sp)+1);
- bp=bp-1;
- sp=sep;
- end
- loc=str2num(input('Impulse location : ','s'));
- if loc>ep||loc<sp
- fprintf('Wrond entry !');
- x=-1;return;
- end
- for i = 1 : length(t)
- if (t(i)==loc) x(i)=1;
- else x(i)=0;
- end
- end
- if strcmp(cd,'continuous')
- plot(t,x);
- else
- stem(t,x);
- end
- axis();
- xlabel('n');
- ylabel('Impulse Function');
- hold on;
- case 6
- %Here comes the code for Unit Step Plotting .
- fprintf('Your choice is Unit step Function\n\n');
- if bp
- sep=str2num(input('Enter this function''s end point ','s'));
- t=linspace(sp,sep,sf*(sep-sp)+1);
- bp=bp-1;
- sp=sep;
- end
- amp=str2num(input('Amplitude : ','s'));
- tl=str2num(input('Location of transition : ','s'));
- x=linspace(sp,ep,sf*(ep-sp)+1);
- y=x*0;
- z=0;
- for i=linspace(sp,ep,sf*(ep-sp)+1);
- z=z+1;
- if (i==tl) y(z:length(y))=1;break; end
- end
- if strcmp(cd,'continuous') plot(x,amp*y);
- else stem(x,amp*y); end
- axis();
- xlabel('t');
- ylabel('Unit Step Function');
- hold on;
- case 7
- %Here comes the code for Rectangular Plotting .
- fprintf('\nYour choice was Rectangular !\n\n');
- if bp
- sep=str2num(input('Enter this function''s end point ','s'));
- t=linspace(sp,sep,sf*(sep-sp)+1);
- bp=bp-1;
- sp=sep;
- end
- wids=(str2num(input('Rectangle Width : ','s'))/2);
- amp=str2num(input('Rectangle Amplitude : ','s'));
- center=str2num(input('Rectangle Center : ','s'));
- x=linspace(sp,ep,sf*(ep-sp)+1);
- %y=not((abs(x) <= (center-wids)) | ( abs(x) >= (center+wids)));
- y=not((x <= (center-wids)) | ( x >= (center+wids)));
- y=y*amp;
- if strcmp(cd,'continuous') plot(x,y);
- else stem(x,y); end
- xlabel('t');
- ylabel('Rectangular Function');
- hold on;
- %x=1;syms x;
- %if strcmp(cd,'continuous')
- %ezplot(A*rectangularPulse(-wid,wid,x-cor),[sp ep]);
- otherwise
- disp('Nothing to be done !')
- end
- hold on;
- x=0;
- end
- %HAMID'S FUNCTIONS :
- %%%%%%%%%%%%%%%%%%%%
- %fprintf('Your choice is Unit step Function\n\n');
- %
- %start_point=input('The start point is = ');
- %end_point=input('The end point is = ');
- %%%smpl_freq=input('The sampling frequancy is = ');
- %amp=input('The Amplitude is :');
- %trans_location=input('The location of transition is = ');
- %
- %t=[trans_location-abs(start_point):trans_location trans_location:abs(end_point)+trans_location] %%el zero mara bib2a sorto zero, w mara bib2a sorto 1 3shan nozbot el rasma fel plot
- %q=[zeros(1,abs(start_point)+1) ones(1,abs(end_point)+1)]
- %plot (t,amp*q);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement