【数字信号调制】基于matlab GUI PCM编码调制【含Matlab源码 453期】

举报
海神之光 发表于 2022/05/29 04:35:12 2022/05/29
【摘要】 一、获取代码方式 获取代码方式1: 完整代码已上传我的资源: 【数字信号调制】基于matlab GUI PCM编码调制【含Matlab源码 453期】 获取代码方式2: 通过订阅紫极神光博客付费专栏,...

一、获取代码方式

获取代码方式1:
完整代码已上传我的资源: 【数字信号调制】基于matlab GUI PCM编码调制【含Matlab源码 453期】

获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

备注:订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、简介

数字信号是对连续变化的模拟信号进行抽样、量化和编码产生的,称为PCM(Pulse Code Modulation),即脉冲编码调制。

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

均匀量化的小信号的信噪比小.
非均匀量化: 由于一些信源信号, 如语音信号, 小幅度信号发生的概率大于大幅度信号的概率, 采用非均匀量化(即小幅度信号的量化步长小于大幅度信号的的量化步长) 效果更好好 (表现在语音信号上, 可以使信号具有足够的信噪比)

非均匀量化特性通常是把信号通过一个非线性的设备, 小信号幅度进行放大, 大信号幅度进行压缩, 再通过均匀量化实现.

三、部分源代码

function varargout = PCM(varargin)
% PCM M-file for PCM.fig
%      PCM was designed in order to show how PCM works
%
%      To simplify the undesrtanding of this method, the program first takes
%      a sine wave. Then you can choose a sampling scheme, and you can see
%      the output of the sampler. You can choose one out of three sampling 
%      methods.
%      If you choose natural sampling; then you will have the chance to modify
%      the sampling window, and see the effects of this change in the output of
%      the sampler.
%
%      Once you got the sampled signal you can quantize it by a method that is 
%      known as two rules and an alorithm.
%      The option Squeezing and Stretching shows the best G(x) tha minimizes 
%      the MSE. You can better understand this using the book
%      Telecommunications Demystified written by Carl Nassar. You can find
%      information about this on Chapter four of that book. 
%      You can edit the bit's number and the number of iterations of the
%      algorithm. The bigger the number of bits, the smaller the MSE.
%      The picture shows the signal after quantization, the first iteration
%      in the quantization process and the output of the quantizer
%      
%      Then, by pressing the Bit Stream button you will see the PCM output
%      of the signal that you have selected in the input area.
%      
%      Everytime you change something, you must push the button that is
%      related with the change you have just made. For example if don't
%      want to work anymore with the sine wave and you choose the random
%      signal, then you have to push the plot button in order to see the
%      plot of the random signal, and if you change of sampling method you
%      have to push the sampling button, when you changhe the sampling 
%      window. So if you change the number of codewords or the number of 
%      the iterations you will have to press the quantize button again. 

% Edit the above text to modify the response to help PCM

% Last Modified by GUIDE v2.5 14-Mar-2007 12:32:35

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @PCM_OpeningFcn, ...
                   'gui_OutputFcn',  @PCM_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 PCM is made visible.
function PCM_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 PCM (see VARARGIN)

% Choose default command line output for PCM
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes PCM wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = PCM_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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if (get(handles.radiobutton2,'Value') == get(handles.radiobutton2,'Max')) % Verifies if Sine wave was selected
    t=linspace(0,1,60); % Creates the time variable from 0 to 1 with a length of 60 or 60 points
    y=sin(2*pi*t); % Creates a sine wave of frequency 1 with the t vector 
    axes(handles.axesanalog) % Select the proper axes  
    plot(t,y); 
    xlabel('Time');
    ylabel('Amplitude');
    grid on;
elseif (get(handles.radiobutton3,'Value') == get(handles.radiobutton3,'Max')) % Verifies if Random signal was selected
    t=linspace(0,60,60); % Creates the time variable from 0 to 60 with a length of 60 or 60 points
    y=rand([1 60]); % Creates a random signal of length 60 or with 60 points
    axes(handles.axesanalog) % Select the proper axes    
    plot(t,y);
    xlabel('Time');
    ylabel('Amplitude');
    grid on;
end
handles.amp=y; % Saves the input signal y in the amp variable at the handles structure
handles.time=t; % Saves the input signal t in the time variable at the handles structure
guidata(gcbo,handles); % Save the changes made to the handles structure

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close; % Close the application

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if (get(handles.radiobutton4,'Value') == get(handles.radiobutton4,'Max'))
    t=handles.time; % recover the saved variable t from the handles structure
    y=handles.amp; % recover the saved variable y from the handles structure
    p=ones(1, length(t)); % creates a vector containing only ones 
    outideal=p.*y; % Multiplies the two vectors to get the output of an ideal sampler
    axes(handles.axessampled) % Select the proper axes
    stem(t,outideal,'ro');
    xlabel('Time');
    ylabel('Amplitude');
    grid on;
    handles.signal=outideal;
    guidata(gcbo,handles);
elseif (get(handles.radiobutton5,'Value') == get(handles.radiobutton5,'Max'))
    t=handles.time; % recover the saved variable t from the handles structure
    y=handles.amp; % recover the saved variable y from the handles structure
    p=ones(1, length(t)); % creates a vector containing only ones 
    outhold=p.*y; % Multiplies the two vectors to get the output of an ideal sampler
    axes(handles.axessampled) % Select the proper axes
    stairs(t,outhold,'r'); %Plot the signal in a stairs shape making it looks like a zero order hold sampler
    xlabel('Time');
    ylabel('Amplitude');
    grid on;
    handles.signal=outhold;
    guidata(gcbo,handles);
elseif (get(handles.radiobutton6,'Value') == get(handles.radiobutton6,'Max'))
    t=handles.time; % recover the saved variable t from the handles structure
    y=handles.amp; % recover the saved variable y from the handles structure
    test1=eval(get(handles.edit1,'String')); % Evals the value that is contained in the Edit 1
    if isnan(test1) % Test if it is a number or not. If not it displays an error message
        errordlg('You must enter a numeric value','Bad Input','modal')
    end
    lenp=length(t)/length(test1); %Calculates the length of the vector so it can make it a periodic signal with the 
    %right size so it can work properly
    p=ones(1, lenp); %  Creates a vector of only ones of lenght lenp 
    per=test1'*p; % Creates a matrix, containing lenp times the vector test1
    per=per(:); % Concatenates the columns of the matrix so it becomes a vector
    outnormal=per'.*y; % Multiplies the two vectors to get the output of a normal sampler
    axes(handles.axessampled) % Select the proper axes
    plot(t,outnormal,'r');
    xlabel('Time');
    ylabel('Amplitude');
    grid on;
    handles.signal=outnormal;
    guidata(gcbo,handles);
end

function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in radiobutton6.
function radiobutton6_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton6
if (get(handles.radiobutton6,'Value') == get(handles.radiobutton6,'Max'))    
    set(handles.edit1,'Enable', 'on'); % Enables the Edit1 object once this radiobutton is selected
end

% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton4
if (get(handles.radiobutton6,'Value') == get(handles.radiobutton6,'Min'))    
    set(handles.edit1,'Enable', 'off'); % Disables the Edit1 object once this radiobutton is selected
end

% --- Executes on button press in radiobutton5.
function radiobutton5_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton5
if (get(handles.radiobutton6,'Value') == get(handles.radiobutton6,'Min'))    
    set(handles.edit1,'Enable', 'off'); % Disables the Edit1 object once this radiobutton is selected
end


  
 
  • 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
  • 225

四、运行结果

在这里插入图片描述

五、备注

1 matlab版本
2014a

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

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

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

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

评论(0

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

全部回复

上滑加载中

设置昵称

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

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

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