
%load c:\Matlab\MYFILES\adc_samples_final.csv
%save c:\interim\ma.mat
load c:\interim\ma.mat
sam =adc_samples_final;
sam=sam(2:end); %gerade Anzahl
sam=sam-mean(sam); % DC raus

spsam=fft(sam);
n=length(sam);
spsam((n/2+1):end)=0; % Analytisches Signal basteln
spsam(1)=0; %DC nochmal raus
anasam=ifft(spsam);
diffangle=angle(anasam(2:end)./anasam(1:end-1)); % Winkeldifferenzen
diffangle(find(diffangle> 1.5))=[]; %Artefakte raus
diffangle(find(diffangle<-1.5))=[];
diffangle=diffangle-mean(diffangle); %DC raus
ton=decimate(diffangle,round(500000/8192)); % resample auf 8192er Audio
% Jetz mit nem Hilbertpärchen
% www.mikrocontroller.net/topic/308292#new
inphase=[ ...
0.000210129754790, ...
0.000435686890851, ...
0.001141127330285, ...
-0.000474463384430, ...
0.003228639378579, ...
0.015798773063932, ...
0.016068342201175, ...
-0.008791323992589, ...
-0.023622650882713, ...
-0.002444248072844, ...
-0.003613471987776, ...
-0.082509515298895, ...
-0.141251242309150, ...
-0.022156774160222, ...
0.215723703269164, ...
0.295359239543522, ...
0.089596245788314, ...
-0.177039867952018, ...
-0.224961503288498, ...
-0.075500361981124, ...
0.044102254749162, ...
0.036688196782744, ...
-0.002005942552907, ...
0.007165852803285, ...
0.028981111275206, ...
0.019579331622486, ...
-0.001556043330388, ...
-0.006040359426444, ...
-0.000887658558481, ...
0.000112391232169, ...
-0.000530886012554, ...
0.000692704968094];

quadphase=[ ...
0.000692704968094, ...
-0.000530886012554, ...
0.000112391232169, ...
-0.000887658558481, ...
-0.006040359426444, ...
-0.001556043330388, ...
0.019579331622486, ...
0.028981111275206, ...
0.007165852803285, ...
-0.002005942552907, ...
0.036688196782744, ...
0.044102254749162, ...
-0.075500361981124, ...
-0.224961503288498, ...
-0.177039867952018, ...
0.089596245788314, ...
0.295359239543522, ...
0.215723703269164, ...
-0.022156774160222, ...
-0.141251242309150, ...
-0.082509515298895, ...
-0.003613471987776, ...
-0.002444248072844, ...
-0.023622650882713, ...
-0.008791323992589, ...
0.016068342201175, ...
0.015798773063932, ...
0.003228639378579, ...
-0.000474463384430, ...
0.001141127330285, ...
0.000435686890851, ...
0.000210129754790];

Hi=freqz(inphase,1,1024);
Hq=freqz(quadphase,1,1024);

hisig=filter(inphase,1,sam)+i*filter(quadphase,1,sam);

diffanglehi=angle(hisig(2:end)./hisig(1:end-1)); % Winkeldifferenzen
diffanglehi(find(diffanglehi> 1.5))=[]; %Artefakte raus
diffanglehi(find(diffanglehi<-1.5))=[];
diffanglehi=diffanglehi-mean(diffanglehi); %DC raus
tonhi=decimate(diffanglehi,round(500000/8192)); % resample auf 8192er Audio

plot(1:length(tonhi),tonhi,1:length(ton),ton);

return
 
