image thumbnail

self-made stroboscope with microphone

by

 

GUI for the stoboscope. FFT spectrum, detect frequency, generate drive signal.

stroboscope(varargin)
function varargout = stroboscope(varargin)
% STROBOSCOPE M-file for stroboscope.fig
%      STROBOSCOPE, by itself, creates a new STROBOSCOPE or raises the existing
%      singleton*.
%
%      H = STROBOSCOPE returns the handle to a new STROBOSCOPE or the handle to
%      the existing singleton*.
%
%      STROBOSCOPE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in STROBOSCOPE.M with the given input arguments.
%
%      STROBOSCOPE('Property','Value',...) creates a new STROBOSCOPE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before stroboscope_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to stroboscope_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 help stroboscope

% Last Modified by GUIDE v2.5 23-Dec-2010 22:29:28

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @stroboscope_OpeningFcn, ...
                   'gui_OutputFcn',  @stroboscope_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 stroboscope is made visible.
function stroboscope_OpeningFcn(hObject, eventdata, handles, varargin)
global hds
global hpp
global ai p ps LL2 pc
global ao po pso pco
global st hp fq hpmx dt fqmx signal fout phiout
% 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 stroboscope (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

hds=handles; % globalize

st=false;





hpp1=plot([0 1],[0 0],'k--','parent',handles.axes2);
set(handles.axes2,'NextPlot','add');
str=get(handles.duty,'string');
duty=str2num(str);

if duty<1
    hpp=plot([0 0.5-duty/2 0.5-duty/2 0.5+duty/2 0.5+duty/2 1],[0 0 0.9 0.9 0 0],'r-','parent',handles.axes2);
else
    hpp=plot([0 1],[0.9 0.9],'r-','parent',handles.axes2);
end
set(hpp,'LineWidth',2);

change_peak;

set(handles.axes2,'xlim',[0 1]);
set(handles.axes2,'ylim',[-1 1]);
set(handles.axes2,'xlimMode','manual');
set(handles.axes2,'ylimMode','manual');
    

set(handles.axes2,'XTick',[],'XTickLabel',[]);
set(handles.axes2,'YTick',[],'YTickLabel',[]);
set(handles.axes2,'box','on');

ai = analoginput('winsound');
chan = addchannel(ai,1);
Fs=44100;  % sampling frequency
dt=1/Fs;
set(ai,'SampleRate',Fs);
set(ai,'SamplesPerTrigger',Inf);

p=0.5; % sec, piece size
ps=round(p*Fs);
LL=ps;
dataa=zeros(LL,1);
LL2=round(LL/2);

fq=(Fs/2)*(0:(LL2-1))'/LL2;
hp=plot(fq,zeros(LL2,1),'.k-','parent',handles.axes1);
set(handles.axes1,'NextPlot','add');
hpmx=plot(NaN,NaN,'rx','parent',handles.axes1); % to plot maximum

v=1;
prests_calb;

xlabel(handles.axes1,'frequency, Hz');
ylabel(handles.axes1,'amplitude');
set(handles.axes1,'xlimMode','manual');
set(handles.axes1,'ylim',[0 1]);
set(handles.axes1,'ylimMode','manual');

set(ai,'BufferingConfig',[ps 8]);
set(ai,'SamplesAcquiredFcn','piece_processing');
set(ai,'SamplesAcquiredFcnCount',ps);

po=0.1; % for output
pso=round(p*Fs);
ao = analogoutput('winsound');
ch = addchannel(ao,1:2);
set(ao,'SampleRate',Fs);
set(ao,'BufferingConfig',[pso 4]);
set(ao,'SamplesOutputFcn','add_to_buffer');
set(ao,'SamplesOutputFcnCount',pso);
for mc=1:3 % 3 pieces margin
    d1=zeros(ps,2);
    putdata(ao,d1);
end
fqmx=0;
signal=false;
phiout=0;
fout=0;

pc=1; % piece counter
pco=1;
start(ai);
start(ao);

% --- Outputs from this function are returned to the command line.
function varargout = stroboscope_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 selection change in presets.
function presets_Callback(hObject, eventdata, handles)
v=get(hObject,'Value');
prests_calb;

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

% Hint: popupmenu 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



function f1_Callback(hObject, eventdata, handles)
f1=str2num(get(handles.f1,'string'));
f2=str2num(get(handles.f2,'string'));
set(handles.axes1,'xlim',[f1 f2]);


% --- Executes during object creation, after setting all properties.
function f1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to f1 (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



function f2_Callback(hObject, eventdata, handles)
f1=str2num(get(handles.f1,'string'));
f2=str2num(get(handles.f2,'string'));
set(handles.axes1,'xlim',[f1 f2]);

% --- Executes during object creation, after setting all properties.
function f2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to f2 (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



function fd_Callback(hObject, eventdata, handles)
% hObject    handle to fd (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 fd as text
%        str2double(get(hObject,'String')) returns contents of fd as a double


% --- Executes during object creation, after setting all properties.
function fd_CreateFcn(hObject, eventdata, handles)
% hObject    handle to fd (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



function phi_Callback(hObject, eventdata, handles)
% hObject    handle to phi (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 phi as text
%        str2double(get(hObject,'String')) returns contents of phi as a double


% --- Executes during object creation, after setting all properties.
function phi_CreateFcn(hObject, eventdata, handles)
% hObject    handle to phi (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



function fdet_Callback(hObject, eventdata, handles)
% hObject    handle to fdet (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 fdet as text
%        str2double(get(hObject,'String')) returns contents of fdet as a double


% --- Executes during object creation, after setting all properties.
function fdet_CreateFcn(hObject, eventdata, handles)
% hObject    handle to fdet (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



function fout_Callback(hObject, eventdata, handles)
% hObject    handle to fout (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 fout as text
%        str2double(get(hObject,'String')) returns contents of fout as a double


% --- Executes during object creation, after setting all properties.
function fout_CreateFcn(hObject, eventdata, handles)
% hObject    handle to fout (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 pto.
function pto_Callback(hObject, eventdata, handles)
if get(hObject,'value')
    set(handles.phiout,'Enable','off');
else
    set(handles.phiout,'Enable','on');
end



function phiout_Callback(hObject, eventdata, handles)
% hObject    handle to phiout (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 phiout as text
%        str2double(get(hObject,'String')) returns contents of phiout as a double


% --- Executes during object creation, after setting all properties.
function phiout_CreateFcn(hObject, eventdata, handles)
% hObject    handle to phiout (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



function duty_Callback(hObject, eventdata, handles)
global hpp
change_peak;

% --- Executes during object creation, after setting all properties.
function duty_CreateFcn(hObject, eventdata, handles)
% hObject    handle to duty (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 neg.
function neg_Callback(hObject, eventdata, handles)
global hpp
change_peak;


% --- Executes on button press in rmv.
function rmv_Callback(hObject, eventdata, handles)
global hpp
change_peak;


% --- Executes on button press in mute.
function mute_Callback(hObject, eventdata, handles)
% hObject    handle to mute (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 mute


% --- Executes on button press in x1.
function x1_Callback(hObject, eventdata, handles)
set(handles.axes1,'ylim',[0 1]);

% --- Executes on button press in x5.
function x5_Callback(hObject, eventdata, handles)
set(handles.axes1,'ylim',[0 1/5]);


% --- Executes on button press in x20.
function x20_Callback(hObject, eventdata, handles)
set(handles.axes1,'ylim',[0 1/20]);


% --- Executes on button press in eq.
function eq_Callback(hObject, eventdata, handles)
if get(hObject,'value')
    set(handles.fout,'Enable','off');
else
    set(handles.fout,'Enable','on');
end
    


% --- Executes on button press in pushbutton4stop.
function pushbutton4stop_Callback(hObject, eventdata, handles)
global st;
st=true;


% --- Executes on button press in x50.
function x50_Callback(hObject, eventdata, handles)
set(handles.axes1,'ylim',[0 1/50]);


% --- Executes on button press in x100.
function x100_Callback(hObject, eventdata, handles)
set(handles.axes1,'ylim',[0 1/100]);


% --- Executes on button press in x200.
function x200_Callback(hObject, eventdata, handles)
set(handles.axes1,'ylim',[0 1/200]);


% --- Executes on button press in x500.
function x500_Callback(hObject, eventdata, handles)
set(handles.axes1,'ylim',[0 1/500]);



function thr_Callback(hObject, eventdata, handles)
% hObject    handle to thr (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 thr as text
%        str2double(get(hObject,'String')) returns contents of thr as a double


% --- Executes during object creation, after setting all properties.
function thr_CreateFcn(hObject, eventdata, handles)
% hObject    handle to thr (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



function signal_Callback(hObject, eventdata, handles)
% hObject    handle to signal (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 signal as text
%        str2double(get(hObject,'String')) returns contents of signal as a double


% --- Executes during object creation, after setting all properties.
function signal_CreateFcn(hObject, eventdata, handles)
% hObject    handle to signal (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

Contact us