1. 程式人生 > >離散傅立葉變換(DTFT) MATLAB例項

離散傅立葉變換(DTFT) MATLAB例項

image

w = [0:1:500]*pi/500;
X= exp(1i*w) ./ (exp(1i*w) - 0.5*ones(1,501));        %ones : Create array of all ones
magX= abs(X);
angX = angle(X);
realX = real(X);
imagX = imag(X);
subplot(2,2,1); plot(w/pi, magX);grid
xlabel('frequency in pi unit' );
title ('magnitude part');      
ylabel('magnitude');       
subplot(2,2,2);plot(w/pi,angX);grid                     %subplot 為圖表定位 2X2圖表中第2張
xlabel('frequevcy in pi unit');                                 %X軸座標
title('angle part');
ylabel('radians');
subplot(2,2,3);plot(w/pi, realX );grid                      %grid為圖示加網格線
xlabel('frequency in pi unit' );
title('real part');
ylabel('real');
subplot(2,2,4);plot(w/pi, imagX);grid
xlabel('frequency in pi unit');
title('imag part');
ylabel('imag');

image

n = -1:3;
x = 1:5;
w= (0:1:500)*pi/500;                             
X= x* exp(-j).^(n'*w);                                          %n'  :矩陣n的轉制
realX = real(X);
imagX = imag(X);
angX = angle(X);
magX = abs(X);
subplot(2,2,1);plot(w/pi,magX);grid
xlabel('fequency in pi unit');
title('magnitude part');
subplot(2,2,2);plot(w/pi,realX);grid
xlabel('frequency in pi unit');
title('real part');
subplot(2,2,3);plot(w/pi,imagX);grid
xlabel('frequency in pi unit');
title( 'imaginary part');
subplot(2,2,4);plot(w/pi, angX);grid
xlabel('frequency in pi unit');
title('angle part');

image

%求出某一f上   所有時間上所有值
n= 0:10;%確定n的範圍
w= (-200:1:200)*pi/100;%確定要觀察的頻率範圍
x = (0.9*exp(1i*pi/3)).^n;%確定時間軸上的函式值
X = x*(exp(-1i)).^(n'*w);%轉換到頻率軸上
magX = abs(X);
angX = angle(X);
subplot(2,1,1);
plot(w/pi,magX);grid
subplot(2,1,2);
plot(w/pi, angX);grid

image

%axis 軸        axis()     axis([xmin xmax ymin ymax])
%當輸入函式為實數時     觀察幅值(偶)與相位(奇)的對稱性
n = -10:10 ;
w = (-200:1:200)*pi/100;
x = (-0.9).^n;
X = x * (exp(-1i).^(n'*w));
magX = abs(X);
angX = angle(X);
subplot(2,1,1);
plot(w/pi,magX);grid
axis([-2,2,0,30]);
title('magnitude part');
subplot(2,1,2);
plot(w/pi, angX);grid
title('angle part')