DSP using MATLAB 示例 Example3.19

代码:

% Analog Signal
Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t));

% Discrete-time Signal
Ts = 0.0002; n = -25:1:25; x = exp(-1000*abs(n*Ts));

% Discrete-time Fourier Transform
%Wmax = 2*pi*2000;
K = 500; k = 0:1:K; w = pi*k/K;                 % index array k for frequencies
X = x * exp(-j*n‘*w); 

magX  = abs(X);  angX  = angle(X);  realX  = real(X);  imagX  = imag(X);
%% --------------------------------------------------------------------
%%              START X‘s  mag ang real imag
%% --------------------------------------------------------------------
figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Example3.19a X its mag ang real imag‘);
set(gcf,‘Color‘,‘white‘);
subplot(2,2,1); plot(w/pi,magX); grid on;  %axis([0,1,0,1.5]);
title(‘Magnitude Response‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Magnitude  |X|‘);
subplot(2,2,3); plot(w/pi, angX/pi); grid on; % axis([-1,1,-1,1]);
title(‘Phase Response‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Radians/\pi‘);

subplot(‘2,2,2‘); plot(w/pi, realX); grid on;
title(‘Real Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Real‘);
subplot(‘2,2,4‘); plot(w/pi, imagX); grid on;
title(‘Imaginary Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘);
%% -------------------------------------------------------------------
%%             END X‘s  mag ang real imag
%% -------------------------------------------------------------------

X = real(X);

w = [-fliplr(w), w(2:K+1)];                     % Omega from -Wmax to Wmax
X = [fliplr(X), X(2:K+1)];                      % X over -Wmax to Wmax interval
%% --------------------------------------------------------------------
%%
%% --------------------------------------------------------------------
figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘<<DSP MATLAB>> Example3.19a‘);
set(gcf,‘Color‘,‘white‘);
subplot(2,1,1); plot(t*1000,xa); grid on;  %axis([0,1,0,1.5]);
title(‘Discrete Signal‘);
xlabel(‘t in msec units.‘); ylabel(‘x1(n)‘); hold on;
stem(n*Ts*1000,x); gtext(‘Ts=0.2 msec‘); hold off;

subplot(2,1,2); plot(w/pi, X); grid on; % axis([-1,1,-1,1]);
title(‘Discrete-time Fourier Transform‘);
xlabel(‘frequency in \pi units‘); ylabel(‘X1(w)‘);

%% -------------------------------------------------------------------
%%
%% -------------------------------------------------------------------

  运行结果:

b

代码:

% Analog Signal
Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t));

% Discrete-time Signal
%Ts = 0.0002; n = -25:1:25; x = exp(-1000*abs(n*Ts));
Ts = 0.001; n = -5:1:5; x = exp(-1000*abs(n*Ts));

% Discrete-time Fourier Transform
%Wmax = 2*pi*2000;
K = 500; k = 0:1:K; w = pi*k/K;                 % index array k for frequencies
X = x * exp(-j*n‘*w); 

magX  = abs(X);  angX  = angle(X);  realX  = real(X);  imagX  = imag(X);
%% --------------------------------------------------------------------
%%              START X‘s  mag ang real imag
%% --------------------------------------------------------------------
figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Example3.19b X its mag ang real imag‘);
set(gcf,‘Color‘,‘white‘);
subplot(2,2,1); plot(w/pi,magX); grid on;  %axis([0,1,0,1.5]);
title(‘Magnitude Response‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Magnitude  |X|‘);
subplot(2,2,3); plot(w/pi, angX/pi); grid on; % axis([-1,1,-1,1]);
title(‘Phase Response‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Radians/\pi‘);

subplot(‘2,2,2‘); plot(w/pi, realX); grid on;
title(‘Real Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Real‘);
subplot(‘2,2,4‘); plot(w/pi, imagX); grid on;
title(‘Imaginary Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘);
%% -------------------------------------------------------------------
%%             END X‘s  mag ang real imag
%% -------------------------------------------------------------------

X = real(X);

w = [-fliplr(w), w(2:K+1)];                     % Omega from -Wmax to Wmax
X = [fliplr(X), X(2:K+1)];                      % X over -Wmax to Wmax interval
%% --------------------------------------------------------------------
%%
%% --------------------------------------------------------------------
figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘<<DSP MATLAB>> Example3.19b‘);
set(gcf,‘Color‘,‘white‘);
subplot(2,1,1); plot(t*1000,xa); grid on;  %axis([0,1,0,1.5]);
title(‘Discrete Signal‘);
xlabel(‘t in msec units.‘); ylabel(‘x1(n)‘); hold on;
stem(n*Ts*1000,x); gtext(‘Ts=0.1 msec‘); hold off;

subplot(2,1,2); plot(w/pi, X); grid on; % axis([-1,1,-1,1]);
title(‘Discrete-time Fourier Transform‘);
xlabel(‘frequency in \pi units‘); ylabel(‘X1(w)‘);

%% -------------------------------------------------------------------
%%
%% -------------------------------------------------------------------

  运行结果:

时间: 2024-10-25 00:36:39

DSP using MATLAB 示例 Example3.19的相关文章

DSP using MATLAB 示例Example3.21

代码: % Discrete-time Signal x1(n) % Ts = 0.0002; n = -25:1:25; nTs = n*Ts; Fs = 1/Ts; x = exp(-1000*abs(nTs)); Ts = 0.001; n = -5:1:5; nTs = n*Ts; Fs = 1/Ts; x = exp(-1000*abs(nTs)); % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = x * sinc(Fs*

DSP using MATLAB示例Example3.18

代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Continuous-time Fourier Transform Wmax = 2*pi*2000; K = 500; k = 0:1:K; % index array k for frequencies W = k*Wmax/K; % freqency between 0 and +pi, [0,pi] axis divided i

DSP using MATLAB示例Example3.16

代码: b = [0.0181, 0.0543, 0.0543, 0.0181]; % filter coefficient array b a = [1.0000, -1.7600, 1.1829, -0.2781]; % filter coefficient array a m = 0:length(b)-1; l = 0:length(a)-1; % index arrays m and l K = 500; k = 0:1:K; % index array k for frequenci

DSP using MATLAB 示例 Example3.15

上代码: subplot(1,1,1); b = 1; a = [1, -0.8]; n = [0:100]; x = cos(0.05*pi*n); y = filter(b,a,x); figure('NumberTitle', 'off', 'Name', 'Input and Output sequence'); set(gcf,'Color','white'); subplot(2,1,1); stem(n,x); title('Input sequence'); xlabel('n'

DSP using MATLAB 示例Example3.17

DSP using MATLAB示例Example3.6

代码: n = [-5:5]; x = (-0.9).^n; % x(n) = k = -200:200; w = (pi/100)*k; % [0,pi] axis divided into 101 points. X = x * (exp(-j*pi/100)) .^ (n'*k); magX = abs(X); angX = angle(X); realX = real(X); imagX = imag(X); set(gcf,'Color','white'); subplot(2,2,1

DSP using MATLAB 示例Example3.9

用到的性质 上代码: n = 0:100; x = cos(pi*n/2); k = -100:100; w = (pi/100)*k; % freqency between -pi and +pi , [0,pi] axis divided into 101 points. X = x * (exp(-j*pi/100)) .^ (n'*k); % DTFT of x % signal multiplied y = exp(j*pi*n/4) .* x; % signal multiplied

DSP using MATLAB 示例Example3.7

上代码: x1 = rand(1,11); x2 = rand(1,11); n = 0:10; alpha = 2; beta = 3; k = 0:500; w = (pi/500)*k; % [0,pi] axis divided into 501 points. X1 = x1 * (exp(-j*pi/500)) .^ (n'*k); % DTFT of x1 X2 = x2 * (exp(-j*pi/500)) .^ (n'*k); % DTFT of x2 x = alpha *

DSP using MATLAB 示例Example3.1 3.2 3.3

上代码: w = [0:1:500]*pi/500; % [0,pi] axis divided into 501 points. X = exp(j*w) ./ (exp(j*w) - 0.5*ones(1,501)); magX = abs(X); angX = angle(X); realX = real(X); imagX = imag(X); set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi,magX); grid on; titl