Matlab GUI experiment - realizing a simple signal generator

Publisher:SereneNature7Latest update time:2022-06-30 Source: csdnKeywords:matlab Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Command line input Guide to create a blank GUI project

Arrange the controls and modify the tag name and font

insert image description here

Realize the linkage between the slider and the display box. The display box will show the number when the slider is dragged. The value of the function can also be changed by entering a number in the display box (the slider has a range of Min to Max, and the value entered in the display box must be within this range)

% Paste the code under the slider callback function

function fre_sliser_Callback(hObject)

v1 = get(handles.fre_slider,'Value');

s1 = sprintf('%f',v1);

set(handles.fre,'String',s1)

% Paste the code under the callback function of the display box corresponding to the slider

function fre_Callback(hObject)

s1 = get(handles.fre,'String');

v1 = str2double(s1);

set(handles.fre_slider,'Value',v1)


Paste the following code under the callback function of the signal button. In order to make the code concise, use global variables.

global Type;

Type = 1;

my_callback_fcn(handles);


my_callback_fcn is a custom function used to generate signals

function my_callback_fcn(handles)

global Type;

global fs;

global N;

global x;

fs = 44100;

dt = 1.0/fs;

T = 2;

N = T/dt;

t = linspace(0,T,N);

s1 = get(handles.fre,'String');

F = str2double(s1);

s1 = get(handles.amp,'String');

A = str2double(s1);

if Type == 1

x = 0.5*A*randn(1,N);

end

if Type == 2

x = A*sin(2*pi*F*t);

end

if Type == 3

x = A*square(2*pi*F*t);

end

if Type == 4

x = A*sawtooth(2*pi*F*t,0.5);

end

plot(handles.axes1,t,x,'b','LineWidth',5);

axis(handles.axes1,[0,0.01,-2500,2500]);

grid(handles.axes1);


Paste the code under the callback function corresponding to the play button

function Play_Callback(hObject)

global fs;

global x;

y = x*0.0003;% decay

sound(y,fs);


Advanced content, play and pause the signal, set the timer

global mytimer

mytimer = timer('StartDelay',1,'Period',1,'TasksToExecute',150,'ExecutionMode','fixedRate');

mytimer.TimerFcn = {@my_callback_fcn};

% Run the code under the play button callback function

global mytimer;

start(mytimer);

% Code under the Stop pause button callback function

global mytimer;

stop(mytimer);


To generate figure1_CreateFcn in the entire graphical interface, right-click CreateFcn

insert image description here

Final Result

insert image description here

The code comes from "Theory and Practice of Digital Signal Analysis" of Huazhong University of Science and Technology, only for learning summary

Keywords:matlab Reference address:Matlab GUI experiment - realizing a simple signal generator

Previous article:Function signal generator based on Multisim - square wave, triangle wave, sine wave
Next article:Sine Signal Generator Design——VHDL

Recommended ReadingLatest update time:2024-11-22 13:41

MathWorks and NVIDIA Deep Learning Institute Launch New MATLAB Course
 MathWorks today announced the launch of a comprehensive two-day course, Deep Learning with MATLAB, developed in collaboration with the NVIDIA Deep Learning Institute. Available as both an instructor-led online course and a self-paced on-demand course, the course will be available throughout the rest of 2020. After co
[Internet of Things]
Design and simulation of fuzzy control system for rotary kiln based on Matlab
0 Introduction The cement production process is a physical and chemical reaction process with the characteristics of large inertia, pure lag, and nonlinearity. The system operation conditions are complex and changeable. According to statistics, there are about 3,000 rotary kilns of various types in the
[Industrial Control]
Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号