Question: My Matlab code is not plotting. Could you please tell me what is wrong? the code: % defyining the signal attributes x = 1 +

My Matlab code is not plotting. Could you please tell me what is wrong?
the code:
% defyining the signal attributes
x =1+cos(0.5*pi*n);
n =0:127;
% ftt calculation
X = fft(x,128);
W = linspace(0,2*pi,128)';
L = length(X);
% plotting the signal
figure;
plot(W, abs(X)/L, 'LineWidth',2);
title('FFT - Range 0 to 2PI');
xlabel('W ->0 to 2*pi');
ylabel('Magnetude');
X_shift = fftshift(X)/L;
W_pi2pi = linspace(-pi, pi,128);
figure;
plot(W_pi2pi, abs(X_shift), 'LineWidth',2);
title('FFT - Shift in the Range of -pi to pi');
xlabel('W ->-pi to pi');
ylabel('Magnetude');
Ts =1e-4;
fs =1/Ts;
f = linspace(-fs/2, fs/2,128);
figure;
plot(f/1000, abs(X_shift), 'LineWidth',2);
title('FFT in the Range of -fs/2 to fs/2');
xlabel('W ->-fs/2 to fs/2 in kHz');
ylabel('Magnetude');

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!