- scl.swl [c+]
[..] L'étude de cas [swl] twvdscl
Code
int twvd_swl(){
scltracefa(§, ƒ, ∅);
scltracefc("scl-%s (%s) : %s\n", sclver(), sclsec(), temps_char(0));
double fe_mhz=1;
std::string sfx = "_fe-" + num_str<double>(fe_mhz) + "mhz";
int tn=103, ti;
double dtheta_deg=2*360/27, dθ=dtheta_deg/180*π;
double *theta1_deg = newtablin(tn, 0, 90);
double *t1_ms=new double[tn], *f1_mhz=new double[tn];
double *theta2_deg = newtablin(tn, 270, 90);
double *t2_ms=new double[tn], *f2_mhz=new double[tn];
double *theta3_deg = newtablin(tn, 270, 450);
double *t3_ms=new double[tn], *f3_mhz=new double[tn];
double *theta4_deg = newtablin(tn, 630, 450);
double *t4_ms=new double[tn], *f4_mhz=new double[tn];
double *theta5_deg = newtablin(tn, 630, 720-dtheta_deg);
double *t5_ms=new double[tn], *f5_mhz=new double[tn];
double cθ, cφ, cr, cj;
double fa=∞rd, cfa, fe=-∞rd, cfe;
double ta=∞rd, cta, te=-∞rd, cte;
for(ti=0;ti<tn;ti++){
//
cθ = theta1_deg[ti]/180*π;
cr = pow(1.02, cθ/dθ);
cφ = π/2 - cθ;
t1_ms[ti]=cr*cos(cφ); f1_mhz[ti]=cr*sin(cφ);
//
cθ = theta2_deg[ti]/180*π;
cr = pow(1.02, cθ/dθ);
cφ = π/2 - cθ;
t2_ms[ti]=cr*cos(cφ); f2_mhz[ti]=cr*sin(cφ);
//
cθ = theta3_deg[ti]/180*π;
cr = pow(1.02, cθ/dθ);
cφ = π/2 - cθ;
t3_ms[ti]=cr*cos(cφ); f3_mhz[ti]=cr*sin(cφ);
//
cθ = theta4_deg[ti]/180*π;
cr = pow(1.02, cθ/dθ);
cφ = π/2 - cθ;
t4_ms[ti]=cr*cos(cφ); f4_mhz[ti]=cr*sin(cφ);
//
cθ = theta5_deg[ti]/180*π;
cr = pow(1.02, cθ/dθ);
cφ = π/2 - cθ;
t5_ms[ti]=cr*cos(cφ); f5_mhz[ti]=cr*sin(cφ);
}
cfa=min<double>(tn, f1_mhz); if(fa>cfa){ fa=cfa; }
cfa=min<double>(tn, f2_mhz); if(fa>cfa){ fa=cfa; }
cfa=min<double>(tn, f3_mhz); if(fa>cfa){ fa=cfa; }
cfa=min<double>(tn, f4_mhz); if(fa>cfa){ fa=cfa; }
cfa=min<double>(tn, f5_mhz); if(fa>cfa){ fa=cfa; }
cfe=max<double>(tn, f1_mhz); if(fe<cfe){ fe=cfe; }
cfe=max<double>(tn, f2_mhz); if(fe<cfe){ fe=cfe; }
cfe=max<double>(tn, f3_mhz); if(fe<cfe){ fe=cfe; }
cfe=max<double>(tn, f4_mhz); if(fe<cfe){ fe=cfe; }
cfe=max<double>(tn, f5_mhz); if(fe<cfe){ fe=cfe; }
cta=min<double>(tn, t1_ms); if(ta>cta){ ta=cta; }
cta=min<double>(tn, t2_ms); if(ta>cta){ ta=cta; }
cta=min<double>(tn, t3_ms); if(ta>cta){ ta=cta; }
cta=min<double>(tn, t4_ms); if(ta>cta){ ta=cta; }
cta=min<double>(tn, t5_ms); if(ta>cta){ ta=cta; }
cte=max<double>(tn, t1_ms); if(te<cte){ te=cte; }
cte=max<double>(tn, t2_ms); if(te<cte){ te=cte; }
cte=max<double>(tn, t3_ms); if(te<cte){ te=cte; }
cte=max<double>(tn, t4_ms); if(te<cte){ te=cte; }
cte=max<double>(tn, t5_ms); if(te<cte){ te=cte; }
// Durée totale pour être à l'iso-échelle (temps [ms] - freq. [MHz])
double t_ms = fe_mhz/1400.0*1980.0;
double te_s=1/(fe_mhz*106), te_ms=te_s*103;
for(ti=0;ti<tn;ti++){
f1_mhz[ti] = (f1_mhz[ti]-fa)/(fe-fa)*fe_mhz/3 - fe_mhz/3/2;
/*if(ti<tn/2){ f1_mhz[ti]=fe_mhz/4.0; } else{ f1_mhz[ti]=fe_mhz/3.0; }*/ //🔬
f2_mhz[ti] = (f2_mhz[ti]-fa)/(fe-fa)*fe_mhz/3 - fe_mhz/3/2;
f3_mhz[ti] = (f3_mhz[ti]-fa)/(fe-fa)*fe_mhz/3 - fe_mhz/3/2;
f4_mhz[ti] = (f4_mhz[ti]-fa)/(fe-fa)*fe_mhz/3 - fe_mhz/3/2;
f5_mhz[ti] = (f5_mhz[ti]-fa)/(fe-fa)*fe_mhz/3 - fe_mhz/3/2;
t1_ms[ti] = (t1_ms[ti]-(ta+te)/2)/(fe-fa)*fe_mhz/3 + t_ms/2;
t2_ms[ti] = (t2_ms[ti]-(ta+te)/2)/(fe-fa)*fe_mhz/3 + t_ms/2;
t3_ms[ti] = (t3_ms[ti]-(ta+te)/2)/(fe-fa)*fe_mhz/3 + t_ms/2;
t4_ms[ti] = (t4_ms[ti]-(ta+te)/2)/(fe-fa)*fe_mhz/3 + t_ms/2;
t5_ms[ti] = (t5_ms[ti]-(ta+te)/2)/(fe-fa)*fe_mhz/3 + t_ms/2;
}
// On force le temps à être croissant pour l'interpolation
int t1e=0;
for(ti=1;ti<tn;ti++){
if(t1_ms[ti]>t1_ms[t1e]){
t1e++; t1_ms[t1e]=t1_ms[ti]; f1_mhz[t1e]=f1_mhz[ti];
}
}
//
int t2e=0;
for(ti=1;ti<tn;ti++){
if(t2_ms[ti]>t2_ms[t2e]){
t2e++; t2_ms[t2e]=t2_ms[ti]; f2_mhz[t2e]=f2_mhz[ti];
}
}
//
int t3e=0;
for(ti=1;ti<tn;ti++){
if(t3_ms[ti]>t3_ms[t3e]){
t3e++; t3_ms[t3e]=t3_ms[ti]; f3_mhz[t3e]=f3_mhz[ti];
}
}
//
int t4e=0;
for(ti=1;ti<tn;ti++){
if(t4_ms[ti]>t4_ms[t4e]){
t4e++; t4_ms[t4e]=t4_ms[ti]; f4_mhz[t4e]=f4_mhz[ti];
}
}
//
int t5e=0;
for(ti=1;ti<tn;ti++){
if(t5_ms[ti]>t5_ms[t5e]){
t5e++; t5_ms[t5e]=t5_ms[ti]; f5_mhz[t5e]=f5_mhz[ti];
}
}
scl::string_c imgname=scl::string_c(ƒ)+sfx+".svg",
imgpath="./srt/"+imgname;
graf_dis(imgpath.c_str(), 1, &t1_ms[0], &f1_mhz[0],
"curve", t1e+1, t1_ms, f1_mhz,
"curve", t2e+1, t2_ms, f2_mhz, "curve", t3e+1, t3_ms, f3_mhz,
"curve", t4e+1, t4_ms, f4_mhz, "curve", t5e+1, t5_ms, f5_mhz,
"curve", 1, &t5_ms[t5e], &f5_mhz[t5e],
"linespec", "hd;-h;-u;-l;-t;-q;q*", "grid", "on",
"aymin", -fe_mhz/2, "aymax", fe_mhz/2,
"axmin", 0, "axmax", t_ms,
"title", "Profil de fréquence", "linespeca", "-a",
"ylabel", "[MHz]", "xlabel", "[ms]",
"subtitlex", imgname.c_str(), ∅);
// Nombre d'echantillons
double den = t_ms/te_ms, dei;
int en = (int)floor(den), ei, ej;
scltracefc("en = %d\n", en);
double *sr=newtab<double>(en,0), *sj=newtab<double>(en,0);
double *st_ms = new double[en];
double ct, ct_ms, cf, cf_mhz, df, sf;
int pin;
scltracefc("te=%lf [s], fe=%lf\n", te_s, 1/te_s);
//---------------------------------------------------------------------
//[>FRÉQUENCES ANALYTIQUES]
//---------------------------------------------------------------------
double *f1a_mhz = new double[t1e+1];
cf=f1_mhz[0]; f1a_mhz[0]=cf;
sf = 0; // initialisation de l'integrale de frequence instantannee
for(ti=1;ti<=t1e;ti++){
df=f1_mhz[ti]; sf+=(cf+df)/2*(t1_ms[ti]-t1_ms[ti-1]);
f1a_mhz[ti] = sf/t1_ms[ti] + f1a_mhz[0]*t1_ms[0]/t1_ms[ti];
cf=df;
}
//
double *f2a_mhz = new double[t2e+1];
cf = f2_mhz[0]; f2a_mhz[0]=cf;
sf = 0; // initialisation de l'integrale de frequence instantannee
for(ti=1;ti<=t2e;ti++){
df=f2_mhz[ti]; sf+=(cf+df)/2*(t2_ms[ti]-t2_ms[ti-1]);
f2a_mhz[ti] = sf/t2_ms[ti] + f2a_mhz[0]*t2_ms[0]/t2_ms[ti];
cf=df;
}
//
double *f3a_mhz = new double[t3e+1];
cf = f3_mhz[0]; f3a_mhz[0]=cf;
sf = 0; // initialisation de l'integrale de frequence instantannee
for(ti=1;ti<=t3e;ti++){
df=f3_mhz[ti]; sf+=(cf+df)/2*(t3_ms[ti]-t3_ms[ti-1]);
f3a_mhz[ti] = sf/t3_ms[ti] + f3a_mhz[0]*t3_ms[0]/t3_ms[ti];
cf=df;
}
//
double *f4a_mhz = new double[t4e+1];
cf = f4_mhz[0]; f4a_mhz[0]=cf;
sf = 0; // initialisation de l'integrale de frequence instantannee
for(ti=1;ti<=t4e;ti++){
df=f4_mhz[ti]; sf+=(cf+df)/2*(t4_ms[ti]-t4_ms[ti-1]);
f4a_mhz[ti] = sf/t4_ms[ti] + f4a_mhz[0]*t4_ms[0]/t4_ms[ti];
cf=df;
}
//
double *f5a_mhz = new double[t5e+1];
cf = f5_mhz[0]; f5a_mhz[0]=cf;
sf = 0; // initialisation de l'integrale de frequence instantannee
for(ti=1;ti<=t5e;ti++){
df=f5_mhz[ti]; sf+=(cf+df)/2*(t5_ms[ti]-t5_ms[ti-1]);
f5a_mhz[ti] = sf/t5_ms[ti] + f5a_mhz[0]*t5_ms[0]/t5_ms[ti];
cf=df;
}
//---------------------------------------------------------------------
//[<FRÉQUENCES ANALYTIQUES]
//---------------------------------------------------------------------
for(ei=0;ei<en;ei++){
dei=(double)ei; ct=dei*te_s; ct_ms=ct*103; st_ms[ei]=ct_ms;
//
interptab(t1e+1, f1a_mhz, ∅, t1_ms, 1, &ct_ms, &cf_mhz, &pin);
if(pin>0){
cf=cf_mhz*106;
sr[ei] += cos(2*π*cf*ct);
sj[ei] += sin(2*π*cf*ct);
}
//
interptab(t2e+1, f2a_mhz, ∅, t2_ms, 1, &ct_ms, &cf_mhz, &pin);
if(pin>0){
cf=cf_mhz*106;
sr[ei] += cos(2*π*cf*ct);
sj[ei] += sin(2*π*cf*ct);
}
//
interptab(t3e+1, f3a_mhz, ∅, t3_ms, 1, &ct_ms, &cf_mhz, &pin);
if(pin>0){
cf=cf_mhz*106;
sr[ei] += cos(2*π*cf*ct);
sj[ei] += sin(2*π*cf*ct);
}
//
interptab(t4e+1, f4a_mhz, ∅, t4_ms, 1, &ct_ms, &cf_mhz, &pin);
if(pin>0){
cf=cf_mhz*106;
sr[ei] += cos(2*π*cf*ct);
sj[ei] += sin(2*π*cf*ct);
}
//
interptab(t5e+1, f5a_mhz, ∅, t5_ms, 1, &ct_ms, &cf_mhz, &pin);
if(pin>0){
cf=cf_mhz*106;
sr[ei] += cos(2*π*cf*ct);
sj[ei] += sin(2*π*cf*ct);
}
}
/*scltracefc("t1_ms : "); tracetab<double>(cout, tn, t1_ms ); cout<<endl;
scltracefc("f1_mhz : "); tracetab<double>(cout, tn, f1_mhz); cout<<endl;
scltracefc("t2_ms : "); tracetab<double>(cout, tn, t2_ms ); cout<<endl;
scltracefc("f2_mhz : "); tracetab<double>(cout, tn, f2_mhz); cout<<endl;
scltracefc("t3_ms : "); tracetab<double>(cout, tn, t3_ms ); cout<<endl;
scltracefc("f3_mhz : "); tracetab<double>(cout, tn, f3_mhz); cout<<endl;
scltracefc("t4_ms : "); tracetab<double>(cout, tn, t4_ms ); cout<<endl;
scltracefc("f4_mhz : "); tracetab<double>(cout, tn, f4_mhz); cout<<endl;
scltracefc("t5_ms : "); tracetab<double>(cout, tn, t5_ms ); cout<<endl;
scltracefc("f5_mhz : "); tracetab<double>(cout, tn, f5_mhz); cout<<endl;*/
imgname.clear(); imgname=scl::string_c(ƒ)+"-sig"+sfx+".svg";
imgpath.clear(); imgpath="./srt/"+imgname;
std::string subtitle = "Fréquence d'échantillonnage : " +
num_str<double>(fe_mhz) + " [MHz]";
int chan=2, chai=0;
int nyl = (int)round(1400.0/((double)chan));
graf_dis(imgpath.c_str(), en, st_ms, sj, "grid", "on",
"yaxislength", nyl*92/100,
"yaxisposition", 1799-(chan-1-chai)*nyl,
"title", "Signal généré",
"subtitlex", imgname.c_str(), "subtitle", subtitle.c_str(),
"linespec", "-l", "linespeca", "-a",
"ylabel", "Q [V]", "append", "on", ∅);
chai++;
graf_dis(imgpath.c_str(), en, st_ms, sr, "grid", "on",
"yaxislength", nyl*92/100,
"yaxisposition", 1799-(chan-1-chai)*nyl,
"title", "", "subtitlex", "", "subtitle", "",
"linespec", "-h", "linespeca", "-a",
"xlabel", "[ms]", "ylabel", "I [V]", /*"append", "off",*/ ∅);
//---------------------------------------------------------------------
//[>SPECTROGRAMME]
//---------------------------------------------------------------------
int ten=(int)floor(√((double)en)), tei;
double dtfn=floor(((double)en)/((double)ten)); int tfn=(int)dtfn, tfi;
scltracefc("Nombre de TFD : %d\n", tfn);
double *spgtemps_s = new double[tfn], *spgfreq_hz = new double[ten];
double **spg_db = newmat<double>(tfn, ten);
spectrogramme(en, sr, sj, ten, fe_mhz*106, spgtemps_s, spgfreq_hz, spg_db);
//scltracefc("spg_db : "); tracemat<double>(cout, tfn, ten, spg_db); cout<<endl;
for(tfi=0;tfi<tfn;tfi++){
spgtemps_s[tfi] *= 103; // conversion [ms]
for(tei=0;tei<ten;tei++){
if(spg_db[tfi][tei]<=-100){ spg_db[tfi][tei]=-100; }
}
}
for(tei=0;tei<ten;tei++){
spgfreq_hz[tei] *= fe_mhz;
}
//scltracefc("spgfreq_hz : "); tracetab<double>(cout, ten, spgfreq_hz); cout<<endl;
imgname.clear(); imgname=scl::string_c(ƒ)+"-spg"+sfx+".svg";
imgpath.clear(); imgpath="./srt/"+imgname;
grafmat_dis(imgpath.c_str(), tfn, ten, spg_db, "grid", "on",
"x", spgtemps_s, "y", spgfreq_hz, /*"aymin", 0.0,*/
"ylabel", "[MHz]", "xlabel", "[ms]",
"title", "Spectrogramme du signal", "linespeca", "-a",
"colormap", "hiver", "subtitlex", imgname.c_str(), ∅);
//---------------------------------------------------------------------
//[<SPECTROGRAMME]
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Representation de Wigner-Ville
double **tr=newmat<double>(en, /*2**/en), **tj=newmat<double>(en, /*2**/en),
**tamp=newmat<double>(en, /*2**/en);
double *ir=new double[2*en], *ij=new double[2*en];
int en_2=en/2, ek, em=en-1; den=(double)en;
// Frequence positive
double *freq=new double[en];
for(ei=0;ei<=en_2;ei++){
ek = ei - en_2 + em;
freq[ek] = ((double)ei)/den*fe_mhz;
}
// Frequence negative
for(ei=en_2+1;ei<en;ei++){
ek = ei - en_2 - 1;
freq[ek] = (((double)ei)/den - 1)*fe_mhz;
}
double *temps = newtablin(en, 0, t_ms);
if((tr!=∅)&&(tj!=∅)&&(tamp!=∅)){
tic();
twvd(en, sr, sj, ir, ij, tr, tj);
scltracefc("Execution twvd() : %lf [s]\n", tac()/103);
double camp, eps=scleps();
for(ei=0;ei<en;ei++){
for(ej=0;ej</*2**/en;ej++){
cr=tr[ei][ej]; cj=tj[ei][ej];
camp = cr*cr+cj*cj;
if(camp<eps){ camp=eps; }
tamp[ei][ej] = 10*log10(camp);
}
// Decallage frequentiel pour affichage
crabe(en, tamp[ei], (/*2**/en-1)/2, tamp[ei]);
}
imgname.clear(); imgname=scl::string_c(ƒ)+"-twv"+sfx+".pdf";
imgpath.clear(); imgpath="./srt/"+imgname;
grafmat_dis(imgpath.c_str(), en, /*2**/en, tamp,
"curve", t1e+1, t1_ms, f1_mhz,
"curve", t2e+1, t2_ms, f2_mhz, "curve", t3e+1, t3_ms, f3_mhz,
"curve", t4e+1, t4_ms, f4_mhz, "curve", t5e+1, t5_ms, f5_mhz,
"linespec", "--h;--u;--l;--t;--a", "grid", "on",
"x", temps, "y", freq, "colormap",
"paruline", "subtitlex", imgname.c_str(),
"ylabel", "[MHz]", "xlabel", "[ms]",
"linespeca", "-a", ∅);
imgname.clear(); imgname=scl::string_c(ƒ)+"-twv"+sfx+"-focus.pdf";
imgpath.clear(); imgpath="./srt/"+imgname;
grafmat_dis(imgpath.c_str(), en, /*2**/en, tamp,
"curve", t1e+1, t1_ms, f1_mhz,
"curve", t2e+1, t2_ms, f2_mhz, "curve", t3e+1, t3_ms, f3_mhz,
"curve", t4e+1, t4_ms, f4_mhz, "curve", t5e+1, t5_ms, f5_mhz,
"linespec", "--h;--u;--l;--t;--p", /*"grid", "on",*/
"axmin", -t_ms/2/3 + t_ms/2,
"axmax", t_ms/2/3 + t_ms/2,
"aymin", -fe_mhz/2/3, "aymax", fe_mhz/2/3,
"x", temps, "y", freq, "colormap",
"paruline", /*"subtitlex", imgname.c_str(),*/
"ylabel", "[MHz]", "xlabel", "[ms]",
"linespeca", "-a", "axis", "off", ∅);
}
else{
scltracerr(§, ƒ, ∅,
"probleme d'allocation memoire pour twvd()\n");
}
scltracefe(§, ƒ, ∅);
return 0;
}
/* ƒ décorée par
le 19-03-2025 23:07:52 */
Sortie
[>..\xpl\src\scl.swl.cpp.twvd_swl]
scl-25.03 (gwin64) : 19-03-2025 23:07:52
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<< END OF DISLIN / VERSION 11.3.2 <<
<< Date : 19.03.2025 Time : 23:07:52 Pageformat: DA4L <<
<< Vectors : 5943 Warnings: 0 Fileformat: SVG <<
<< Metafile: ./srt/twvd_swl_fe-1mhz.svg <<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
en = 1414
te=0.000001 [s], fe=1000000.000000
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<< END OF DISLIN / VERSION 11.3.2 <<
<< Date : 19.03.2025 Time : 23:07:52 Pageformat: DA4L <<
<< Vectors : 4892 Warnings: 0 Fileformat: SVG <<
<< Metafile: ./srt/twvd_swl-sig_fe-1mhz.svg <<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Nombre de TFD : 38
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<< END OF DISLIN / VERSION 11.3.2 <<
<< Date : 19.03.2025 Time : 23:07:52 Pageformat: DA4L <<
<< Vectors : 1414 Warnings: 0 Fileformat: SVG <<
<< Metafile: ./srt/twvd_swl-spg_fe-1mhz.svg <<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Execution twvd() : 92.323021 [s]
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<< END OF DISLIN / VERSION 11.3.2 <<
<< Date : 19.03.2025 Time : 23:09:28 Pageformat: DA4L <<
<< Vectors : 4071 Warnings: 0 Fileformat: PDF <<
<< Metafile: ./srt/twvd_swl-twv_fe-1mhz.pdf <<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[<..\src\sclgraf.dis.c.vgrafmat_dis>] xlabel '[ms]' is not displayed (cf axis off)
[<..\src\sclgraf.dis.c.vgrafmat_dis>] ylabel '[MHz]' is not displayed (cf axis off)
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<< END OF DISLIN / VERSION 11.3.2 <<
<< Date : 19.03.2025 Time : 23:09:28 Pageformat: DA4L <<
<< Vectors : 2793 Warnings: 0 Fileformat: PDF <<
<< Metafile: ./srt/twvd_swl-twv_fe-1mhz-focus.pdf <<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[<..\xpl\src\scl.swl.cpp.twvd_swl]