|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
& c4 R7 U9 D# f1 Z& m一、PCM编码+QAM调制简介# t, j. f$ ]# N0 @; s
1 PCM* h7 \0 X# {* T
数字信号是对连续变化的模拟信号进行抽样、量化和编码产生的,称为PCM(Pulse Code Modulation),即脉冲编码调制。: r0 h, k& ]2 \
脉冲编码调制就是把一个时间连续,取值连续的模拟信号变换成时间离散,取值离散的数字信号后在信道中传输。脉冲编码调制就是对模拟信号先抽样,再对样值幅度量化,编码的过程。5 r' _% W1 o3 \. B9 w% f0 ]8 P- W
抽样,就是对模拟信号进行周期性扫描,把时间上连续的信号变成时间上离散的信号。该模拟信号经过抽样后还应当包含原信号中所有信息,也就是说能无失真的恢复原模拟信号。它的抽样速率的下限是由抽样定理确定的。抽样速率采用8Kbit/s。
* x- p0 O+ k+ N/ t( }! E. M8 L量化,就是把经过抽样得到的瞬时值将其幅度离散,即用一组规定的电平,把瞬时抽样值用最接近的电平值来表示。1 b6 ?7 [3 c6 t; P6 ~
一个模拟信号经过抽样量化后,得到已量化的脉冲幅度调制信号,它仅为有限个数值。编码,就是用一组二进制码组来表示每一个有固定电平的量化值。然而,实际上量化是在编码过程中同时完成的,故编码过程也称为模/数变换,可记作A/D。
% G- `. K! L p5 @5 G话音信号先经防混叠低通滤波器,进行脉冲抽样,变成8KHz重复频率的抽样信号(即离散的脉冲调幅PAM信号),然后将幅度连续的PCM信号用“四舍五入”办法量化为有限个幅度取值的信号,再经编码后转换成二进制码。对于电话,CCITT规定抽样率为8KHz,每抽样值编8位码,即共有2^8=256个量化值,因而每话路PCM编码后的标准数码率是64kb/s。为解决均匀量化时小信号量化误差大,音质差的问题,在实际中采用不均匀选取量化间隔的非线性量化方法,即量化特性在小信号时分层密,量化间隔小,而在大信号时分层疏,量化间隔大。均匀量化的小信号的信噪比小。
* }; O0 b. d4 C2 m6 w& Y非均匀量化: 由于一些信源信号, 如语音信号, 小幅度信号发生的概率大于大幅度信号的概率, 采用非均匀量化(即小幅度信号的量化步长小于大幅度信号的的量化步长) 效果更好好 (表现在语音信号上, 可以使信号具有足够的信噪比)。非均匀量化特性通常是把信号通过一个非线性的设备, 小信号幅度进行放大, 大信号幅度进行压缩, 再通过均匀量化实现。$ Z' h" O3 G; O. C6 W
: y. c9 f" L, ^) G
2 常规双边带调幅AM
: E, b' _5 _9 O- nt 域:已调信号的波形,调制/解调方法( L6 G' m4 [% c0 I% w
f 域:已调信号的频谱,带宽B
. t! P% d& @- m; c+ q' _5 F6 JAM信号的包络正比于消息信号的规律,因此可以采用简单的**包络检波方法(非相干解调)**解调;. P) X' ^- F* `0 M: P
频谱由载波、上边带USB、下边带LSB组成。带宽BAM=2fH;; F: m& b' {- ?. Y! E" O0 ~4 m
幅度调制又称为线性调制;' k P. m, M* X$ l+ c
应用:中短波调幅广播。& o% q* W! g' Z
缺点:功率利用率低,最多达到50%
5 `& s8 r: _2 t1 a7 m3 |; e
$ W. y2 Y7 R' L2 l/ e6 ?6 u
% `8 r. E3 O' U8 c- E二、源代码9 r3 w: `, p; a3 L
- 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)7 C# {# |2 @+ R( Q! _9 O9 |
, U, \7 e5 B5 T5 i% G n( H, W+ y+ j2 A5 S0 \
三、运行结果2 y$ T2 ~2 K2 L# P( p
* R' M/ Z2 o! C% q8 f
7 z3 Y0 k" U, ^* G8 \
; y0 e; I, d, y P3 J% V
. c# R5 c/ i {1 ~' I a
3 y! B. R) [% b' n$ @" f; `2 a6 o# j G. j3 E
w! ^4 A, T5 U B! L$ ~
+ j' j4 q; r2 f* C6 ]
! Z( O( J8 {2 o& ?
b& v5 E) b! h" o1 f' J' I- p
" ^3 J, C' U" u
7 v0 }( c" _' C! M" a
+ A2 y) e- p1 w* l
. X0 G8 |! |) U* T# t! ]8 R* a3 h0 }6 W0 i- ?) C$ ?
; J8 i8 h, v* {9 P& d
* }- w/ n9 c4 `7 g Y
; F- l4 y; e7 W! \! b |
|