%-------------------------------------------------------------------------- %Jeniffer Estrada %All rights reserved. %This is for educational purposes only. %November 8, 2008 %-------------------------------------------------------------------------- %Problem 1: Time Domain convolution using two user input functions. %Part A: Sample h(t) and x(t) over the interval (0,T) using N samples. %Gives the sampled values h(n) and x(n) in a discrete plot or list. %Give the values of time corresponding to n. T=input('Enter Interval: 0-'); t=0:0.1:T; %60 samples x=input('Enter first function to be convolved:'); h=('Enter second function to be convolved:'); a =conv(h,x); n= 0:length(a)-1; t1=t'; x_sampled=exp(-n); %values of h(n) h_sampled=2*exp(-n); %values of h(n) samples=[x_sampled; h_sampled]'; %List of h(n) and x(n) conversion=[t n]; % The value of time corresponding to n %%-------------------------------------------------------------------------- %Part B: Gives the sample values y(n)=h(n)*x(n) in a discrete plot. y=conv(h,x); figure plot(n,y,'.'); title('Discrete Representation of Convolution with n samples') xlabel('n'); ylabel('y(n)'); %-------------------------------------------------------------------------- %Part C: Give a plot of y(t). Label the axies properly. figure plot(t,y(1:61),'.'); title('Discrete Representation of Convolution with t samples') xlabel('t'); ylabel('y(t)'); %-------------------------------------------------------------------------- %Problem 2: Using the Discrete Fourier Transform for convolution: %Part A: Gives both the magnitude and phase of the DFT's H(k) and X(k). %Gives a list or discrete plot. Gives the value of w corresponding to k. X=fft(x); %Conversion from time domain to Fourier Domain. X_Magnitude=abs(X); X_Phase=angle(X); k_limit=length(X); k=1:k_limit; figure plot(k,X_Magnitude,'.'); title('Discrete Representation of X Magnitude in Fourier Domain') xlabel('k'); ylabel('Magnitude'); figure plot(k,X_Phase,'.'); title('Discrete Representation of X Phase in Fourier Domain') xlabel('k'); ylabel('Phase'); H=fft(h); %Conversion to Fourier Domain. H_Magnitude=abs(H); H_Phase=angle(H); figure plot(k,H_Magnitude,'.'); title('Discrete Representation of H Magnitude in Fourier Domain') xlabel('k'); ylabel('Magnitude'); figure plot(k,H_Phase,'.'); title('Discrete Representation of H Phase in Fourier Domain') xlabel('k'); ylabel('Phase'); %-------------------------------------------------------------------------- %Part B: Give the magitude and phase of the DFT's Y(k)=H(k)*X(k). Y=H.*X; magnitude=abs(Y); phase=angle(Y); %Discrete plot of Magnitude and Phase of Y with respect to k. figure plot(k,magnitude, '.'); title('Discrete Representation of Y Magnitude in Fourier Domain') xlabel('k'); ylabel('Magnitude'); %Continous plot of Magnitude and Phase of Y with respect to k. figure plot(k,magnitude); title('Continuous Representation of Y Magnitude in Fourier Domain') xlabel('k'); ylabel('Magnitude'); %Discrete plot of Magnitude and Phase of Y with respect to k. figure plot(k,phase,'.'); title('Discrete Representation of Y Phase in Fourier Domain') xlabel('k'); ylabel('Phase'); %Continous plot of Magnitude and Phase of Y with respect to k. figure plot(k,phase); title('Continuous Representation of Y Phase in Fourier Domain') xlabel('k'); ylabel('Phase');