How to plot the frequency response of a discrete cosine function?

My attempt:
I tried doing it but I can't get the freq response to be plotted between pi and pi. Any help would be appreciated.

回答 (1 件)

Rick Rosson
Rick Rosson 2015 年 11 月 14 日
編集済み: Rick Rosson 2015 年 11 月 14 日

0 投票

L = 1000;
n = 0:L-1;
x1 = fftshift(fft(x))/L;
dw = 2*pi/L;
w = -pi:dw:pi-dw;
stem(w,mag);

5 件のコメント

Daniel Ramirez
Daniel Ramirez 2015 年 11 月 15 日
編集済み: Daniel Ramirez 2015 年 11 月 15 日
Thank you Rick. I got the magnitude right this time. But the phase plot I get a a lot of fluctuations, like noise.
L = 1000;
n = 0:L-1;
x=5*cos((0.13*pi*n)+(pi/13));
x1 = fftshift(fft(x))/L;
dw = 2*pi/L;
w = -pi:dw:pi-dw;
mag=abs(x1)
stem(w,mag);
title('Magnitude Plot');
phase=angle(x1);
figure
plot(w,phase)
title('Phase Plot');
Rick Rosson
Rick Rosson 2015 年 11 月 15 日
phase = angle(x1);
phase(mag<0.01) = nan;
figure;
plot(w,phase/pi);
ylabel('Phase Angle (pi-radians)');
Daniel Ramirez
Daniel Ramirez 2015 年 11 月 16 日
編集済み: Daniel Ramirez 2015 年 11 月 16 日
Rick sorry but I still can't get the phase response. I uploaded the image.
L = 1000;
n = 0:L-1;
x=5*cos((0.13*pi*n)+(pi/13));
x1 = fftshift(fft(x))/L;
dw = 2*pi/L;
w = -pi:dw:pi-dw;
mag=abs(x1)
stem(w,mag);
title('Magnitude Plot');
phase = angle(x1);
phase(mag<0.01) = nan;
figure;
plot(w,phase/pi);
ylabel('Phase Angle (pi-radians)');
Rick Rosson
Rick Rosson 2015 年 11 月 16 日
Try using stem instead of plot:
stem(w,phase/pi);
Daniel Ramirez
Daniel Ramirez 2015 年 11 月 17 日
Thank you so much Rick. It's working now.

サインインしてコメントする。

質問済み:

2015 年 11 月 13 日

コメント済み:

2015 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by