📄 rolloff.m
字号:
% roll-off factor
% page 198 & 221 --6.9
% 写一个matlab 程序,产生具有任意滚降系数α,由式(6.5.9)给出的发送滤波器冲击响应
% gT(t)的样本,求并画出α= 1/2和N=31的gT(t).同时也求并画出这个滤波器的频率响应特性的
% 幅度特性(通过将gT(t)补上3N个零值,再求4N点的DFT)
% 2009.20.17
function [] = RollOff(alp,N)
if nargin < 2;
N = 31;
end;
if nargin < 1
alp = 1/2;
end;
echo on;
T = 1;
n = -(N-1)/2:(N-1)/2;
%
for i = 1:length(n),
g_T(i) = 0;
for m = -(N-1)/2:(N-1)/2,
g_T(i) = g_T(i) + sqrt(Xrc(4*m/(N*T),alp,T)) * exp(j*2*pi*m*n(i)/N);
echo off;
end;
end;
%echo on;
g_T1 = real(g_T); % The imaginary part is due to the finite machine precision.
% Derive g_T(n-(N-1)/2).
n2 = 0:N-1;
% Get the frequency response characteristics
[G_T1,W] = freqz(g_T1,1);
% Normalized magnitude response
magG_T1_in_dB = 20*log10(abs(G_T1)/max(abs(G_T1)));
% impulse response of the cascade of the transmitter and the reciver
% filters
g_R = g_T1;
imp_resp_of_cascade = conv(g_R,G_T1);
% plotting commands follows.
% plot(imp_resp_of_cascade,'b');
% hold on ;
figure('Name',' THE g_T(t)');
stem(g_R,'--');set(gca,'Color',[0.6,0.8,0.6]);
title('脉冲响应','fontname','宋体','fontsize',12);
xlabel('N为滤波器长度','fontname','宋体','fontsize',12);
grid on;
figure('Name','maG_T1_in_dB');
plot(magG_T1_in_dB,'m');set(gca,'Color',[0.8,0.8,0.6]);
set(gcf,'Color',[0.6,0.8,0.6]);
title('频率响应','fontname','宋体','fontsize',12);
xlabel('f','fontname','宋体','fontsize',12);
grid on;
%
hold on ;
N = 41;
n = -(N-1)/2:(N-1)/2;
%
for i = 1:length(n),
g_T(i) = 0;
for m = -(N-1)/2:(N-1)/2,
g_T(i) = g_T(i) + sqrt(Xrc(4*m/(N*T),alp,T)) * exp(j*2*pi*m*n(i)/N);
echo off;
end;
end;
%echo on;
g_T1 = real(g_T); % The imaginary part is due to the finite machine precision.
% Derive g_T(n-(N-1)/2).
n2 = 0:N-1;
% Get the frequency response characteristics
[G_T1,W] = freqz(g_T1,1);
% Normalized magnitude response
magG_T1_in_dB = 20*log10(abs(G_T1)/max(abs(G_T1)));
plot(magG_T1_in_dB,'--b');
%
hold on ;
N = 51;
n = -(N-1)/2:(N-1)/2;
%
for i = 1:length(n),
g_T(i) = 0;
for m = -(N-1)/2:(N-1)/2,
g_T(i) = g_T(i) + sqrt(Xrc(4*m/(N*T),alp,T)) * exp(j*2*pi*m*n(i)/N);
echo off;
end;
end;
%echo on;
g_T1 = real(g_T); % The imaginary part is due to the finite machine precision.
% Derive g_T(n-(N-1)/2).
n2 = 0:N-1;
% Get the frequency response characteristics
[G_T1,W] = freqz(g_T1,1);
% Normalized magnitude response
magG_T1_in_dB = 20*log10(abs(G_T1)/max(abs(G_T1)));
plot(magG_T1_in_dB,'k');
%figure();
%p = unwrap(angle(g_T)); % Phase
%f = (0:length(g_T)-1)'/length(g_T); % Frequency vector
%plot(p);
%Phase = atan2(imag(g_T),real(g_T)) % angle(g_T)
%figure(4);
%plot(Phase);
% 4N FFT
xN_fft = fft(g_R,4*N)/length(g_T);
xN_fft = abs(xN_fft);
xN_fftshift = fftshift(xN_fft);
figure('Name','4N_FFT');
plot(xN_fftshift,'m');set(gca,'Color',[0.8,0.8,0.6]);
title('DFT','fontname','宋体','fontsize',12);
xlabel('Data length: 4N ','fontname','宋体','fontsize',12);
grid on;
%----------------------------------------------------------------------
% (6.5.9)式子中的Xrc
function [y] = Xrc(f,alpha,T);
% [y] = Xrc(f,alpha,T)
% The parameters alpha and T must be given as inputs to function.
if (abs(f) > ((1 + alpha) / (2*T))),
y = 0;
elseif (abs(f) > ((1 - alpha) / (2 * T))),
y = (T/2) * (1 + cos((pi*T/alpha)*(abs(f)-(1-alpha)/(2*T)) ));
else
y = T;
end;
% End of .M file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -