MATLAB: Need help to write a program to plot a magnitude response and phase response of a signal x (n) = a^n*u(n) .a) using loop b) using MATLAB command for DFT. magnitude responseMATLABphase responseSignal Processing Toolbox Hi all, Please suggest a code for a program to plot a magnitude response and phase response of a signal x (n) = a^n*u(n). a) using loop b) using MATLAB command for DFT. Best Answer DFT is:so you can make it by using loop or matlab FFT function directly, hope this help:%%using loop%a is a constantcleara=2;N=100;for k=1:N X(k)=0; for n=1:N %this include u(n) x(n)=a.^n; X(k)= X(k)+(x(n)*exp(-j*2*pi*(k-1)*(n-1)/N)); endendsubplot(2,1,1),plot(abs(X)) %magnitudesubplot(2,1,2),plot(angle(X)) %phase%%using FFT%a is a constantcleara=2;N=100;n=[1:1:N];x=a.^n;X=fftshift(fft(x),N);subplot(2,1,1),plot(n,abs(X)) %magnitudesubplot(2,1,2),plot(n,angle(X)) %phase Related SolutionsMATLAB: N(x) CODE1)a=[0 1]; % you tell MATLAB a is a vectorfor r=3:100 % the for loop you understand, right? a(r)=(r-1)+(r-2); % you're attributing to the rth term of your vector a values of (r - 1) + (r - 2) % the 1st iteration will be a(3) = (3 - 1) + (3 - 2); a(4) = (4 - 1) + (4 - 2); so on...enddisp(a)CODE2) a=[0 1]; %from this line, a(1) = 0 and a(2) = 1.for r=3:100 a(r)=a(r-1)+a(r-2); % the difference between this and code 1) is that you're performing % the summation calling the indexes in the vector a, rather than r values. % so a(3) = a(2) + a(1) = 0 + 1 = 1 % In code 1, a(3) = 2 + 1 = 3enddisp(a)Code 3) is the same as 2) Walter mentioned.Hope that helps...Cheers MATLAB: Generate y(n)=y(n-1)+x(n) n=10y0=0; % Initial conditions y(1)=y0+x(1); for k=2:n y(k)=y(k-1)+x(k)end Related QuestionMedian of n*nI want to write matlab code that calculates fourier transform of following sequence and also plots its magnitude x(k)
Best Answer