image thumbnail

self-made stroboscope with microphone

by

 

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

piece_processing
function piece_processing
global ai ps st hp LL2 fq hpmx hds dt pc fout phiout fqmx signal
if st
    stop(ai);
    delete(ai);
else
    data = getdata(ai,ps);
    %data=sin(2*pi*80*(1:ps)/44100);
    data=data-mean(data);
    f=fft(data)*(2/ps);
    ff=f(1:LL2);
	fa=abs(ff);
	set(hp,'YData',fa);
    
    f1=str2num(get(hds.f1,'string'));
    f2=str2num(get(hds.f2,'string'));
    
    [tmp f1i]=min(abs(f1-fq));
    [tmp f2i]=min(abs(f2-fq));
    
    % maximum:
    indrg=f1i:f2i; % range
    fa1=fa(indrg); % range
    [fa1mx ind0]=max(fa1);
    ind=indrg(ind0);
    fqmx=fq(ind);
    thr=str2num(get(hds.thr,'string')); % threshol
    if fa1mx<thr
        signal=false;
        set(hds.signal,'string','no signal');
    else
        signal=true;
        set(hds.signal,'string','signal');
    end
    set(hpmx,'XData',fqmx,'YData',fa1mx);
    set(hds.fd,'string',num2str(fqmx,'%4.0f'));
    %phit=angle(ff(ind)); % pahse
    %phi=phit+2*pi*fqmx*(pc-1)*ps*dt; % correct phase
    phic=2*pi*fqmx*(pc-1)*ps*dt;
    phi=angle(ff(ind)*exp(1i*phic)); % pahse
    set(hds.phi,'string',num2str(phi,'%1.3f'));
    
    fdet=str2num(get(hds.fdet,'string'));
    
    if get(hds.eq,'value')
        fout=fqmx+fdet;
        set(hds.fout,'string',num2str(fout,'%4.2f'));
    else
        fout=str2num(get(hds.fout,'string'));
    end
    
    if get(hds.pto,'value')
        phiout=phi;
        set(hds.phiout,'string',num2str(phiout,'%1.3f'));
    else
        phiout=str2num(get(hds.phiout,'string'));
    end
    
	drawnow;
    pc=pc+1;
  
end

Contact us