数字信号调制基于matlab GUI PCM编码+QAM调制含Matlab源码 1095期
Posted 紫极神光(Q1564658423)
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数字信号调制基于matlab GUI PCM编码+QAM调制含Matlab源码 1095期相关的知识,希望对你有一定的参考价值。
一、简介
数字信号是对连续变化的模拟信号进行抽样、量化和编码产生的,称为PCM(Pulse Code Modulation),即脉冲编码调制。
脉冲编码调制就是把一个时间连续,取值连续的模拟信号变换成时间离散,取值离散的数字信号后在信道中传输。脉冲编码调制就是对模拟信号先抽样,再对样值幅度量化,编码的过程。
抽样,就是对模拟信号进行周期性扫描,把时间上连续的信号变成时间上离散的信号。该模拟信号经过抽样后还应当包含原信号中所有信息,也就是说能无失真的恢复原模拟信号。它的抽样速率的下限是由抽样定理确定的。抽样速率采用8Kbit/s。
量化,就是把经过抽样得到的瞬时值将其幅度离散,即用一组规定的电平,把瞬时抽样值用最接近的电平值来表示。
一个模拟信号经过抽样量化后,得到已量化的脉冲幅度调制信号,它仅为有限个数值。
编码,就是用一组二进制码组来表示每一个有固定电平的量化值。然而,实际上量化是在编码过程中同时完成的,故编码过程也称为模/数变换,可记作A/D。
话音信号先经防混叠低通滤波器,进行脉冲抽样,变成8KHz重复频率的抽样信号(即离散的脉冲调幅PAM信号),然后将幅度连续的PCM信号用“四舍五入”办法量化为有限个幅度取值的信号,再经编码后转换成二进制码。对于电话,CCITT规定抽样率为8KHz,每抽样值编8位码,即共有2^8=256个量化值,因而每话路PCM编码后的标准数码率是64kb/s。为解决均匀量化时小信号量化误差大,音质差的问题,在实际中采用不均匀选取量化间隔的非线性量化方法,即量化特性在小信号时分层密,量化间隔小,而在大信号时分层疏,量化间隔大。
均匀量化的小信号的信噪比小。
非均匀量化: 由于一些信源信号, 如语音信号, 小幅度信号发生的概率大于大幅度信号的概率, 采用非均匀量化(即小幅度信号的量化步长小于大幅度信号的的量化步长) 效果更好好 (表现在语音信号上, 可以使信号具有足够的信噪比)。
非均匀量化特性通常是把信号通过一个非线性的设备, 小信号幅度进行放大, 大信号幅度进行压缩, 再通过均匀量化实现。
二、源代码
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)
三、运行结果
四、备注
版本:2014a
以上是关于数字信号调制基于matlab GUI PCM编码+QAM调制含Matlab源码 1095期的主要内容,如果未能解决你的问题,请参考以下文章
数字信号调制基于matlab GUI PCM编码+QAM调制含Matlab源码 1095期
通信仿真基于matlab数字信号增量调制含Matlab源码 2381期
Matlab基于μ律15折线的PCM语音编解码系统(GUI设计simulink附完整代码)