I know it\'s long I just really struggle with MATLAB Use Matlab to demonstrate t
ID: 1720403 • Letter: I
Question
I know it's long I just really struggle with MATLAB
Use Matlab to demonstrate the linearity property (see Table 3-1 and section 3-5.1 in the textbook) of the Discrete Fourier Transform (discrete time Fourier series) for two signal vectors with length N = 32. You can use either the built-in ff t() which Matlab uses to calculate the DFT, or you can define the 32 Times 32 WN matrix as given in Lecture 12 and use matrix-vector multiplication to find the discrete spectral component of your signals. Matlab has the random () function that you can use to generate two vectors with random numbers that have a Gaussian distribution. (If you can demonstrate the property is true for random signal values, that is a very powerful demonstration.) The properties shown in Table 3.1 all show that there are two equivalent methods to find the spectral components (right column) from the time signals (left, column). You can show that the two methods are equivalent by the subtraction of the result from Method I from the result from Method 2. (For example, for the time shifting property, if you want to calculate the DFT of x[n - 3]. Method 1. could be taking the DFT of x[n] then multiplying each spectral component of ,X|k| by exp(-j2pi 3k/32) and Method 2 could be first (circularly) shifting x[n] to the right by 3 steps and then finding the DFT of this new (shifted) time signal.) The two results should he identical, so if you subtract the results from Method 1 and Method 2 and observe that the absolute value of the difference is always very small (on the order of the calculation precision), then the property is demonstrated. The max () and abs () commands on Matlab are useful for this demonstration. For credit for problem 4.1, you must include your commented Matlab script and a brief explanation of how your demonstration works.Explanation / Answer
%DFT linearity property close all; clear all; N=input('Howmany point DFT do you want?'); x1=input('Enter the first sequence='); x2=input('Enter the second sequence='); a=input('Enter the first constant a='); b=input('Enter the second constant b='); n1=length(x1); n2=length(x2); c=zeros(N); x1=[x1 zeros(1,N-n1)];%make both x1 and x2 x2=[x2 zeros(1,N-n2)];%of same dimension x3=a*x1 x4=b*x2 x5=x3+x4 %a*x1+b*x2 for k=1:N for n=1:N w=exp((-2*pi*i*(k-1)*(n-1))/N); %prev.step=>evaluating w-matrix x(n)=w; end c(k,:)=x; %Every row of w-matrix is inserted & end %finally c becomes the w matrix %for n-point DFT r1=c*x1'; %x1(k) r2=c*x2'; %x2(k) R3=a*r1+b*r2 %a*x1(k)+b*x2(k) R4=c*x5' %DFT of a*x1(n)+b*x2(n) %plotting magnitude and angle subplot(211) stem(abs(R4)); title('DFT of {a*x1(n)+b*x2(n)}'); subplot(212) stem(angle(R3)); title('DFT of {a*x1(k)+b*x2(k)}');