How can i plot the magnitude and phase response my output signal?

Hi,
How can I plot the magnitude and phase response of y[n] that i have obtained? y[n] = [-3 8 5 2]
I have followed this but my magnitude graph looks weird. (a V continuous line)
Here's my code:
Trial>> t = 0:1/100:10-1/100;
Trial>> x = [-3 8 5 2]
Trial>> y = fft(x);
Trial>> m = abs(y);
Trial>> f = (0:length(y)-1)*100/length(y);
Trial>> subplot(2,1,1)
Trial>> plot(f,m)
Trial>> title('Magnitude')
Thank you

3 Comments

What is x here? If it is the signal, then should it not be the same size as t?
x is the discrete signal values y[n]. What is t?
t is the array of sample times which is the first variable that you define above (but never use thereafter). Why does your x only have four samples?

Sign in to comment.

 Accepted Answer

The correct code for the Bode plot for your signal:
t = linspace(0,10,4);
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
x = [-3 8 5 2];
y = fft(x);
m = 2*abs(y)/length(x);
f = linspace(0, 1, fix(length(y)/2)+1)*Fn;
Iv = 1:length(f); % Index Vector
subplot(2,1,1)
plot(f,m(Iv))
title('Magnitude')
subplot(2,1,2)
plot(f,angle(y(Iv)))
title('Phase')
xlabel('Frequency')

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!