【数字信号调制】基于matlab GUI PCM编码和QAM调制系统【含Matlab源码 2080期】

举报
海神之光 发表于 2022/09/24 22:47:38 2022/09/24
【摘要】 一、PCM编码+QAM调制简介 1 PCM 数字信号是对连续变化的模拟信号进行抽样、量化和编码产生的,称为PCM(Pulse Code Modulation),即脉冲编码调制。 脉冲编码调制就是把一个时...

一、PCM编码+QAM调制简介

1 PCM
数字信号是对连续变化的模拟信号进行抽样、量化和编码产生的,称为PCM(Pulse Code Modulation),即脉冲编码调制。
脉冲编码调制就是把一个时间连续,取值连续的模拟信号变换成时间离散,取值离散的数字信号后在信道中传输。脉冲编码调制就是对模拟信号先抽样,再对样值幅度量化,编码的过程。
抽样,就是对模拟信号进行周期性扫描,把时间上连续的信号变成时间上离散的信号。该模拟信号经过抽样后还应当包含原信号中所有信息,也就是说能无失真的恢复原模拟信号。它的抽样速率的下限是由抽样定理确定的。抽样速率采用8Kbit/s。
量化,就是把经过抽样得到的瞬时值将其幅度离散,即用一组规定的电平,把瞬时抽样值用最接近的电平值来表示。
一个模拟信号经过抽样量化后,得到已量化的脉冲幅度调制信号,它仅为有限个数值。编码,就是用一组二进制码组来表示每一个有固定电平的量化值。然而,实际上量化是在编码过程中同时完成的,故编码过程也称为模/数变换,可记作A/D。
话音信号先经防混叠低通滤波器,进行脉冲抽样,变成8KHz重复频率的抽样信号(即离散的脉冲调幅PAM信号),然后将幅度连续的PCM信号用“四舍五入”办法量化为有限个幅度取值的信号,再经编码后转换成二进制码。对于电话,CCITT规定抽样率为8KHz,每抽样值编8位码,即共有2^8=256个量化值,因而每话路PCM编码后的标准数码率是64kb/s。为解决均匀量化时小信号量化误差大,音质差的问题,在实际中采用不均匀选取量化间隔的非线性量化方法,即量化特性在小信号时分层密,量化间隔小,而在大信号时分层疏,量化间隔大。均匀量化的小信号的信噪比小。
非均匀量化: 由于一些信源信号, 如语音信号, 小幅度信号发生的概率大于大幅度信号的概率, 采用非均匀量化(即小幅度信号的量化步长小于大幅度信号的的量化步长) 效果更好好 (表现在语音信号上, 可以使信号具有足够的信噪比)。非均匀量化特性通常是把信号通过一个非线性的设备, 小信号幅度进行放大, 大信号幅度进行压缩, 再通过均匀量化实现。

2 常规双边带调幅AM
t 域:已调信号的波形,调制/解调方法
f 域:已调信号的频谱,带宽B
AM信号的包络正比于消息信号的规律,因此可以采用简单的**包络检波方法(非相干解调)**解调;
频谱由载波、上边带USB、下边带LSB组成。带宽BAM=2fH;
幅度调制又称为线性调制;
应用:中短波调幅广播。
缺点:功率利用率低,最多达到50%

二、源代码

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)

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224

三、运行结果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 沈再阳.精通MATLAB信号处理[M].清华大学出版社,2015.
[2]高宝建,彭进业,王琳,潘建寿.信号与系统——使用MATLAB分析与实现[M].清华大学出版社,2020.
[3]王文光,魏少明,任欣.信号处理与系统分析的MATLAB实现[M].电子工业出版社,2018.

3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除

文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。

原文链接:qq912100926.blog.csdn.net/article/details/126681787

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。