|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
, U4 ? l( ]: ]3 X一、PCM编码+QAM调制简介7 Y% A: Y0 W8 c
1 PCM
7 r- V; o% ~' X k数字信号是对连续变化的模拟信号进行抽样、量化和编码产生的,称为PCM(Pulse Code Modulation),即脉冲编码调制。
, M: q0 b8 t: ], h! S脉冲编码调制就是把一个时间连续,取值连续的模拟信号变换成时间离散,取值离散的数字信号后在信道中传输。脉冲编码调制就是对模拟信号先抽样,再对样值幅度量化,编码的过程。
) t8 r1 ?! \9 f& u+ L* G抽样,就是对模拟信号进行周期性扫描,把时间上连续的信号变成时间上离散的信号。该模拟信号经过抽样后还应当包含原信号中所有信息,也就是说能无失真的恢复原模拟信号。它的抽样速率的下限是由抽样定理确定的。抽样速率采用8Kbit/s。1 h4 ~ O7 H9 r# Y/ t/ @# Y
量化,就是把经过抽样得到的瞬时值将其幅度离散,即用一组规定的电平,把瞬时抽样值用最接近的电平值来表示。
: W8 {' [% y) P- _一个模拟信号经过抽样量化后,得到已量化的脉冲幅度调制信号,它仅为有限个数值。编码,就是用一组二进制码组来表示每一个有固定电平的量化值。然而,实际上量化是在编码过程中同时完成的,故编码过程也称为模/数变换,可记作A/D。
! c$ O" G I/ ?. ]话音信号先经防混叠低通滤波器,进行脉冲抽样,变成8KHz重复频率的抽样信号(即离散的脉冲调幅PAM信号),然后将幅度连续的PCM信号用“四舍五入”办法量化为有限个幅度取值的信号,再经编码后转换成二进制码。对于电话,CCITT规定抽样率为8KHz,每抽样值编8位码,即共有2^8=256个量化值,因而每话路PCM编码后的标准数码率是64kb/s。为解决均匀量化时小信号量化误差大,音质差的问题,在实际中采用不均匀选取量化间隔的非线性量化方法,即量化特性在小信号时分层密,量化间隔小,而在大信号时分层疏,量化间隔大。均匀量化的小信号的信噪比小。* x" _5 Z0 b; }9 ^$ ?; Q5 v
非均匀量化: 由于一些信源信号, 如语音信号, 小幅度信号发生的概率大于大幅度信号的概率, 采用非均匀量化(即小幅度信号的量化步长小于大幅度信号的的量化步长) 效果更好好 (表现在语音信号上, 可以使信号具有足够的信噪比)。非均匀量化特性通常是把信号通过一个非线性的设备, 小信号幅度进行放大, 大信号幅度进行压缩, 再通过均匀量化实现。
6 e5 ]1 w( h, z( D* ]+ a
& N& i- ?+ J' y+ K2 常规双边带调幅AM2 [9 M' s# o- f
t 域:已调信号的波形,调制/解调方法! T& x: E7 k/ O+ m! R
f 域:已调信号的频谱,带宽B
4 D5 U8 o3 W$ O/ m! vAM信号的包络正比于消息信号的规律,因此可以采用简单的**包络检波方法(非相干解调)**解调;
3 n2 d2 b8 ^8 i- P( }2 w& Q" P: \' o! Y频谱由载波、上边带USB、下边带LSB组成。带宽BAM=2fH;
! B" Q" Y: a0 C8 W! X幅度调制又称为线性调制;
' h. R" ~; [ G: q- G" t应用:中短波调幅广播。
. R, i3 E8 T3 u) q缺点:功率利用率低,最多达到50%
2 \# J2 F! N& Q1 O/ r; d* |+ {: |4 |
# h9 ]% B. q, ~5 ~( {
二、源代码$ l9 J/ z8 ?( e8 ^2 Q% M
- function varargout = test(varargin)
- % TEST M-file for test.fig
- % TEST, by itself, creates a new TEST or raises the existing
- % singleton*.
- %
- % H = TEST returns the handle to a new TEST or the handle to
- % the existing singleton*.
- %
- % TEST('CALLBACK',hObject,eventData,handles,...) calls the local
- % function named CALLBACK in TEST.M with the given input arguments.
- %
- % TEST('Property','Value',...) creates a new TEST or raises the
- % existing singleton*. Starting from the left, property value pairs are
- % applied to the GUI before test_OpeningFunction gets called. An
- % unrecognized property name or invalid value makes property application
- % stop. All inputs are passed to test_OpeningFcn via varargin.
- %
- % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
- % instance to run (singleton)".
- %
- % See also: GUIDE, GUIDATA, GUIHANDLES
- % Edit the above text to modify the response to About test
- % Last Modified by GUIDE v2.5 04-Jul-2021 19:27:45
- % Begin initialization code - DO NOT EDIT
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @test_OpeningFcn, ...
- 'gui_OutputFcn', @test_OutputFcn, ...
- 'gui_LayoutFcn', [] , ...
- 'gui_Callback', []);
- if nargin && ischar(varargin{1})
- gui_State.gui_Callback = str2func(varargin{1});
- end
- if nargout
- [varargout{1:nargout}] = gui_maiNFCn(gui_State, varargin{:});
- else
- gui_mainfcn(gui_State, varargin{:});
- end
- % End initialization code - DO NOT EDIT
- % --- Executes just before test is made visible.
- function test_OpeningFcn(hObject, eventdata, handles, varargin)
- % This function has no output args, see OutputFcn.
- % hObject handle to figure
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % varargin command line arguments to test (see VARARGIN)
- % Choose default command line output for test
- handles.output = hObject;
- % Update handles structure
- guidata(hObject, handles);
- % UIWAIT makes test wait for user response (see UIRESUME)
- % uiwait(handles.figure1);
- % --- Outputs from this function are returned to the command line.
- function varargout = test_OutputFcn(hObject, eventdata, handles)
- % varargout cell array for returning output args (see VARARGOUT);
- % hObject handle to figure
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Get default command line output from handles structure
- varargout{1} = handles.output;
- % --- Executes on button press in LOAD.
- function LOAD_Callback(hObject, eventdata, handles)
- % hObject handle to LOAD (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global x fs t
- [x,fs] = audioread('test.wav');
- t = (1:length(x))/fs;
- t8 = length(x)*8;
- t8 = (1:t8)/fs;
- Bs = 0.5*fs;
- save('data.mat','x','fs','t','t8');
- N = length(x);
- X=fft(x,N);%进行fft变换
- mag=abs(X);%求幅值
- f=(0:length(X)-1)'*fs/length(X);%进行对应的频率转换
- subplot(2,1,1,'position',[0.3 0.57 0.6 0.3]);
- plot(t,x) %时域图
- xlabel('时间');
- ylabel('幅值');
- axis([min(t) max(t) min(x) max(x)]);
- subplot(2,1,2,'position',[0.3 0.2 0.6 0.3]);
- plot(f,mag);%做频谱图
- xlabel('频率');
- ylabel('幅值');
- axis([0 max(f) 0 1.1*max(abs(X)) ]);
- set(handles.LOAD,'enable','off');
- set(handles.PCM,'enable','on');
- %set(handles.Play_origin,'enable','on');
- set(handles.text1,'String','测试音频文件波形如图所示');
- % --- Executes on button press in PCM.
- function PCM_Callback(hObject, eventdata, handles)
- % hObject handle to PCM (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- load data.mat;
- x1 = x./max(abs(x));
- sxx = floor( x1 * 4096 );
- y = pcm_encode(sxx);
- save('data.mat','y','-append');
- subplot(1,1,1,'position',[0.3 0.2 0.6 0.65]);
- plot(t8,y);
- xlabel('时间');
- ylabel('幅值');
- axis([0 0.1 -1 2]);
- set(handles.dePCM,'enable','on');
- set(handles.QAM,'enable','on');
- set(handles.text1,'String','经过PCM编码后,形成二进制码流');
- % --- Executes on button press in QAM.
- function QAM_Callback(hObject, eventdata, handles)
- % hObject handle to QAM (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- prompt={'信道SNR:'};
- name='Input';
- numlines=1;
- defaultanswer={'20'};
- answer=inputdlg(prompt,name,numlines,defaultanswer);
- if ~isempty(answer) ,
- result = str2num(answer{1,1});
- load data.mat;
- Qt = my_qammod(y);
- Qr = awgn(Qt,result);
- yy= my_qamdemod(Qr);
- save('data.mat','yy','-append');
- subplot(1,1,1,'position',[0.3 0.2 0.6 0.65]);
- plot(t8,yy);
- xlabel('时间');
- ylabel('幅值');
- axis([0 0.1 -1 2]);
- set(handles.compare2,'enable','on');
- set(handles.text1,'String','PCM信号通过QAM调制,送到AWGN信道,再经过解调还原为PCM信号');
- end
- % --- Executes on button press in dePCM.
- function dePCM_Callback(hObject, eventdata, handles)
- % hObject handle to dePCM (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- load data.mat;
- xx = pcm_decode(y,max(abs(x)));
- save('data.mat','xx','-append');
- N = length(xx);
- XX=fft(xx,N);%进行fft变换
- mag=abs(XX);%求幅值
- f=(0:length(XX)-1)'*fs/length(XX);%进行对应的频率转换
- function qt = my_qammod(b)
- [nrow,ncol]=size(b);
- col=ncol/4;
- b_2=reshape(b,4,col);
- b_2=b_2';
- b_str2=int2str(b_2);
- b_10=bin2dec(b_str2);
- b_10=b_10';
- % --- Executes on button press in Play_arrive.
- %function Play_arrive_Callback(hObject, eventdata, handles)
- % hObject handle to Play_arrive (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %load data.mat;
- %wavplay(xx);
- % --- Executes on button press in BYE.
- function BYE_Callback(hObject, eventdata, handles)
- % hObject handle to BYE (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- close
- % --------------------------------------------------------------------
- function About_Callback(hObject, eventdata, handles)
- % hObject handle to About (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- msgbox({' 本程序完成对简单音频信号的取样,' 'PCM编码,QAM调制, 通过AWGN信道, ' 'QAM解调,PCM解码的一系列方针操作。' '作者:吕非彼' '电信工程学院 05114班 ' '学号:050430 序号:12'},'About','Help')
- % --- Executes during object creation, after setting all properties.
- %function Play_origin_CreateFcn(hObject, eventdata, handles)
- % hObject handle to Play_origin (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % --- Executes during object deletion, before destroying properties.
- %function Play_origin_DeleteFcn(hObject, eventdata, handles)
- % hObject handle to Play_origin (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % --- If Enable == 'on', executes on mouse press in 5 pixel border.
- % --- Otherwise, executes on mouse press in 5 pixel border or over Play_origin.
- %function Play_origin_ButtonDownFcn(hObject, eventdata, handles)
- % hObject handle to Play_origin (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
5 J8 _! Q7 G8 s3 Q- X$ k, r$ l : x% e- N% E9 q- [0 p- u4 R' ~' x
$ z. H, }; }$ `9 f0 v& J三、运行结果! Z2 T6 ?/ m' _
9 X! ~! b" A* G7 q* c+ `# V% h
( p$ y! s- W% f( A
k' @: }: t/ P/ y* F! P
& D( U* v$ ~1 C& L% j( z7 F0 C$ `
5 C: k1 F! x' D( |6 G
2 ?# d; h, P! W% B* L% ]2 k
e' j$ H- Z w
) _# a. u! L& V2 T% q! R7 f' f( o
. k- k" }4 D2 a j n/ o5 U) W
. v7 w2 L8 c( u) b
. m7 x) D" h& e9 ^: G& Y& P" _/ @+ \% m+ e# Z/ x U! D
. {% W7 `+ Q; l# u& V
; r" o$ W+ }0 k/ s. {( C
, f* e/ S# B& S* x8 f& o% H5 G5 n/ ~9 X1 J, |6 p8 @6 H$ J3 l
' Y) ^. h& m- x. t3 S# B
9 H- A2 R) P+ K) v$ u. u* O |
|