the app I created in MATLAB App designer is not responding, it worked before but now it has stopped responding, even I can't close the desktop window
37 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I was working on the app in app designer to record audio,add noise, and then filter the noise with suitable filter, for this I also plotted the time domain and frequency domain spectrum of each signal , i also have difficulting in plotting the filtered signal spectrums, like when I added the code to plot the filtered signal , I started encountering the problem, the app in not running.even I can't close the window! my matlab version is R2018a.
here is my code
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
RecordButton matlab.ui.control.Button
durationTextAreaLabel matlab.ui.control.Label
durationTextArea matlab.ui.control.TextArea
playButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
UIAxes2 matlab.ui.control.UIAxes
wanttoaddnoiseCheckBox matlab.ui.control.CheckBox
ButtonGroup matlab.ui.container.ButtonGroup
noiseaddedButton matlab.ui.control.RadioButton
playnoisysignalButton matlab.ui.control.Button
SNRTextAreaLabel matlab.ui.control.Label
SNRTextArea matlab.ui.control.TextArea
UIAxes3 matlab.ui.control.UIAxes
UIAxes4 matlab.ui.control.UIAxes
filterButton matlab.ui.control.Button
UIAxes5 matlab.ui.control.UIAxes
UIAxes6 matlab.ui.control.UIAxes
showfilteredsignalButton matlab.ui.control.Button
end
properties (Access = private)
% Description
SNR % Description
play % Description
filteredData % Description
Property4 % Description
Property5 % Description
end
methods (Access = private)
function results = func(app)
end
end
methods (Access = private)
% Button pushed function: RecordButton
function RecordButtonPushed(app, event)
audioObject= audiorecorder(44100,16,1);
Duration=str2double(app.durationTextArea.Value{1});
msgbox('recording start');
recordblocking(audioObject,Duration);
msgbox('recording stopped');
assignin('base','audioObject',audioObject);
end
% Button pushed function: playButton
function playButtonPushed(app, event)
audioObject=evalin('base','audioObject');
audioData=getaudiodata(audioObject);
sound(audioData,audioObject.SampleRate);
audiowrite('input_audio.wav',audioData,44100);
% plotting the audio signal in time domain
t=(0:length(audioData)-1)/44100;
plot(app.UIAxes,t,audioData);
%plotting the amplitude spectrum of audio signal
f_InputData = linspace(-44100/2,44100/2,length(audioData));
INPUTDATA = fft(audioData);
INPUTDATA_f = fftshift(INPUTDATA);
INPUTDATA_f_abs = abs( INPUTDATA_f);
plot(app.UIAxes2,f_InputData,INPUTDATA_f_abs);
end
% Value changed function: wanttoaddnoiseCheckBox
function wanttoaddnoiseCheckBoxValueChanged(app, event)
value = app.wanttoaddnoiseCheckBox.Value;
switch value
case 0
app.noiseaddedButton.Visible = 'off';
case 1
app.noiseaddedButton.Visible = 'on';
end
end
% Button pushed function: playnoisysignalButton
function playnoisysignalButtonPushed(app, event)
audioObject = evalin('base','audioObject');
app.SNR= str2double(app.SNRTextArea.Value{1});
noisyData=awgn(getaudiodata(audioObject),app.SNR,'measured');
switch app.wanttoaddnoiseCheckBox.Value
case 1
if(app.noiseaddedButton.Value)
app.play = audioplayer(noisyData,44100);
playblocking(app.play);
assignin('base','noisyData',noisyData);
%plotting the noisy signal in time domain
audiowrite('noisy_input_audio.wav', noisyData, 44100);
t=(0:length(noisyData)-1)/44100;
plot(app.UIAxes3,t,noisyData);
% plotting amplitude density spectrum of noisy signal
f_InputData = linspace(-44100/2,44100/2,length(noisyData));
INPUTDATA=fft(noisyData);
INPUTDATA_f = fftshift(INPUTDATA);
INPUTDATA_f_abs = abs(INPUTDATA_f);
plot(app.UIAxes4,f_InputData,INPUTDATA_f_abs);
end
case 0
msgbox('noise not added')
end
end
% Button pushed function: filterButton
function filterButtonPushed(app, event)
fc = 4000; % Cut-off frequency in Hz
order = 30; % Filter order
% Design the low-pass filter
[b, a] = butter(order, fc/(44100/2), 'low');
% Apply the filter to the noisy audio signal
noisyData = evalin('base','noisyData');
v_filtered = filter(b, a,noisyData);
% Play the filtered audio
app.filteredData = audioplayer(v_filtered, 44100);
playblocking(app.filteredData);
assignin('base','v_filtered',v_filtered);
v_filtered = evalin('base','v_filtered');
end
% Button pushed function: showfilteredsignalButton
function showfilteredsignalButtonPushed(app, event)
v_filtered = evalin('base','v_filtered');
audiowrite('filtered_audio.wav',v_filtered, 44100);
t_filt= (0:length(app.filteredData)-1)/44100;
plot(app.UIAxes5,t_filt,v_filtered);
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 1523 509];
app.UIFigure.Name = 'UI Figure';
% Create RecordButton
app.RecordButton = uibutton(app.UIFigure, 'push');
app.RecordButton.ButtonPushedFcn = createCallbackFcn(app, @RecordButtonPushed, true);
app.RecordButton.Position = [39 440 100 22];
app.RecordButton.Text = 'Record';
% Create durationTextAreaLabel
app.durationTextAreaLabel = uilabel(app.UIFigure);
app.durationTextAreaLabel.HorizontalAlignment = 'right';
app.durationTextAreaLabel.Position = [39 406 49 22];
app.durationTextAreaLabel.Text = 'duration';
% Create durationTextArea
app.durationTextArea = uitextarea(app.UIFigure);
app.durationTextArea.HorizontalAlignment = 'right';
app.durationTextArea.Position = [103 404 139 26];
app.durationTextArea.Value = {'10'};
% Create playButton
app.playButton = uibutton(app.UIFigure, 'push');
app.playButton.ButtonPushedFcn = createCallbackFcn(app, @playButtonPushed, true);
app.playButton.Position = [39 361 100 22];
app.playButton.Text = 'play';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Input Audio Signal')
xlabel(app.UIAxes, 'time')
ylabel(app.UIAxes, 'magnitude')
app.UIAxes.Position = [251 292 444 197];
% Create UIAxes2
app.UIAxes2 = uiaxes(app.UIFigure);
title(app.UIAxes2, 'Amplitude Density spectrum of Audio Signal')
xlabel(app.UIAxes2, 'frequency')
ylabel(app.UIAxes2, 'magnitude')
app.UIAxes2.Position = [255 70 436 207];
% Create wanttoaddnoiseCheckBox
app.wanttoaddnoiseCheckBox = uicheckbox(app.UIFigure);
app.wanttoaddnoiseCheckBox.ValueChangedFcn = createCallbackFcn(app, @wanttoaddnoiseCheckBoxValueChanged, true);
app.wanttoaddnoiseCheckBox.Text = 'want to add noise?';
app.wanttoaddnoiseCheckBox.Position = [75 276 123 22];
% Create ButtonGroup
app.ButtonGroup = uibuttongroup(app.UIFigure);
app.ButtonGroup.BorderType = 'none';
app.ButtonGroup.Position = [64 227 123 30];
% Create noiseaddedButton
app.noiseaddedButton = uiradiobutton(app.ButtonGroup);
app.noiseaddedButton.Visible = 'off';
app.noiseaddedButton.Text = 'noise added';
app.noiseaddedButton.Position = [11 4 87 22];
app.noiseaddedButton.Value = true;
% Create playnoisysignalButton
app.playnoisysignalButton = uibutton(app.UIFigure, 'push');
app.playnoisysignalButton.ButtonPushedFcn = createCallbackFcn(app, @playnoisysignalButtonPushed, true);
app.playnoisysignalButton.Position = [89 144 104 22];
app.playnoisysignalButton.Text = 'play noisy signal';
% Create SNRTextAreaLabel
app.SNRTextAreaLabel = uilabel(app.UIFigure);
app.SNRTextAreaLabel.HorizontalAlignment = 'right';
app.SNRTextAreaLabel.Position = [64 185 31 22];
app.SNRTextAreaLabel.Text = 'SNR';
% Create SNRTextArea
app.SNRTextArea = uitextarea(app.UIFigure);
app.SNRTextArea.HorizontalAlignment = 'right';
app.SNRTextArea.Position = [110 185 77 24];
app.SNRTextArea.Value = {'12'};
% Create UIAxes3
app.UIAxes3 = uiaxes(app.UIFigure);
title(app.UIAxes3, 'Noisy signal')
xlabel(app.UIAxes3, 'time')
ylabel(app.UIAxes3, 'magnitude')
app.UIAxes3.Position = [726 292 414 197];
% Create UIAxes4
app.UIAxes4 = uiaxes(app.UIFigure);
title(app.UIAxes4, 'Amplitude Density spectrum of Noisy Signal')
xlabel(app.UIAxes4, 'frequecny')
ylabel(app.UIAxes4, 'magnitude')
app.UIAxes4.Position = [726 70 414 207];
% Create filterButton
app.filterButton = uibutton(app.UIFigure, 'push');
app.filterButton.ButtonPushedFcn = createCallbackFcn(app, @filterButtonPushed, true);
app.filterButton.Position = [103 70 100 22];
app.filterButton.Text = 'filter';
% Create UIAxes5
app.UIAxes5 = uiaxes(app.UIFigure);
title(app.UIAxes5, 'Title')
xlabel(app.UIAxes5, 'X')
ylabel(app.UIAxes5, 'Y')
app.UIAxes5.Position = [1170 292 382 197];
% Create UIAxes6
app.UIAxes6 = uiaxes(app.UIFigure);
title(app.UIAxes6, 'Title')
xlabel(app.UIAxes6, 'X')
ylabel(app.UIAxes6, 'Y')
app.UIAxes6.Position = [1170 70 382 207];
% Create showfilteredsignalButton
app.showfilteredsignalButton = uibutton(app.UIFigure, 'push');
app.showfilteredsignalButton.ButtonPushedFcn = createCallbackFcn(app, @showfilteredsignalButtonPushed, true);
app.showfilteredsignalButton.Position = [94 32 118 22];
app.showfilteredsignalButton.Text = 'show filtered signal';
end
end
methods (Access = public)
% Construct app
function app = app1
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
3 Kommentare
Antworten (1)
Sandeep Mishra
am 8 Aug. 2024 um 11:33
Hi Nayab,
I understand you are encountering an error while running the ‘Show Filtered Signal’ button in the App designer.
I observed that the ‘t_filt’ variable contains a scalar value 0 while the ‘v_filtered’ variable is a vector in the MATLAB ‘plot’ function.
This discrepancy causes the increase in the processing time. For a 10-second audio duration signal, it took 132 seconds to display the filtered signal.
To resolve the error, you can replace the ‘t_filt’ value with a vector of same size as ‘v_filtered’ value on Line #157 of the provided code.
Refer to the below example code snippet which replaces scalar value with a vector value:
t_filt= (0:app.filteredData.TotalSamples-1)/44100;
I hope this will help you resolve the error and successfully plot the filtered signals.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Audio Processing Algorithm Design finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!