1. 程式人生 > 實用技巧 >隨機解調之低通濾波

隨機解調之低通濾波

隨機解調在混頻後,多頻點訊號被均勻的塗抹到整個頻率軸,低通濾波將高頻濾除,然後再均勻取樣。

%%-----------------------------------------------------------------------------
%%生成m序列,繪製m序列的時域和頻域圖
%%-------------------------------------------------
clc;clear all;close all;
%%-------------------------------------------------
Fs = 10000;%取樣頻率
dt = 1/Fs;%取樣時間間隔

L = 1000;
t = (0:L-1)*dt;%生成時間向量

FN = 8;%濾波器階數
wc = 1000;%濾波器截止頻率為1KHz

f1=3000;%頻率1
f2=4000;%頻率2
x1=cos(2*pi*f1*t);
x2=cos(2*pi*f2*t);
x = x1+x2;

F1 = fft(x)/L;
WF = (0:L/2-1)*(Fs/L);%實際頻率
subplot(2,1,1);%2行3列,第一個區域
plot(t(1:40),x(1:40),'o');%繪製取樣點,只取了一部分割槽間

figt = (0:400)/100000;
figx = cos(2*pi*f1*figt)+cos(2*pi*f2*figt);
hold on;

plot(figt,figx);
%axis([0 0.1 -2.2 2.2]);
xlabel('時間/s');ylabel('幅值/v');title('頻域稀疏訊號的時域圖');
subplot(2,1,2);%2行1列,第一個區域
stem(WF,abs(F1(1:L/2)));%stem用於繪製莖狀圖
xlabel('頻率/Hz');ylabel('幅值');title('頻域稀疏訊號的頻域圖');


figure;
pn = randsrc(1,L);
subplot(2,1,1);%2行1列,第一個區域
stairs(t(1:100),pn(1:100));%繪製階梯圖
axis([0 0.01 -1.2 1.2]);%調節座標軸刻度

xlabel('時間/s');ylabel('幅值/v');title('m序列時域圖');

F = fft(pn)/L;%對pn進行離散傅立葉變換,F為m序列的頻譜
W = (0:L/2-1)*(Fs/L);
subplot(2,1,2);%2行1列,第2個區域
plot(WF,abs(F(1:L/2)));%stem用於繪製莖狀圖
xlabel('頻率/Hz');ylabel('幅值');title('m序列頻域圖');
%%---------------------------------------------------------
%%繪製混頻後訊號頻譜的自相關函式
absF = abs(F*L);%對F取絕對值
Fcor = xcorr(absF);
figure;
plot([-999:1:999],Fcor);
%axis([-1000 1000 0 10]);
%-----------------------------------------------------------
figure;
y = x.*pn;%y為混頻訊號
subplot(2,1,1);
plot(t,y);
axis([0 0.1 -2.5 2.5]);
xlabel('時間/s');ylabel('幅值/v');title('原訊號和m序列相乘後的訊號的波形圖');
Fy = fft(y)/L;%混頻訊號的傅立葉變換
subplot(2,1,2);
plot(WF,abs(Fy(1:L/2)));
xlabel('頻率/Hz');ylabel('幅值');title('混頻後的訊號頻譜');

%%-------------------------------------------------------
%%濾波器
[b,a] = butter(FN,wc*2/Fs);%濾波器分子分母多項式
lowPFy = filter(b,a,y);
[H,W] = freqz(b,a);
figure;
plot(W*wc,abs(H));title('低通濾波器幅頻特性曲線');
%%-------------------------------------------------------
Flowpfy = fft(lowPFy);
plot(WF,abs(Flowpfy(1:L/2)));

figure;
plot(t,lowPFy);
title('濾波後的時域波形圖');

由上圖可以看到,低通濾波後,高於1500Hz的訊號分量幾乎為0。後續低速取樣,取樣頻率高於低通濾波器截止頻率的2倍。