Skip to content

Commit

Permalink
spgram: adjusting scale in gnuplot output according to maximum frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaeddert committed Jan 28, 2022
1 parent 1ca547f commit 7425b66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions examples/spgramcf_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int main() {
}

// explort to gnuplot
spgramcf_set_rate (q,200e6);
spgramcf_export_gnuplot(q,"spgramcf_example.gnu");

// compute power spectral density output
Expand All @@ -63,9 +64,7 @@ int main() {
firhilbf_destroy(ht);
spgramcf_destroy(q);

//
// export output file
//
FILE * fid = fopen(OUTPUT_FILENAME,"w");
fprintf(fid,"%% %s : auto-generated file\n", OUTPUT_FILENAME);
fprintf(fid,"clear all;\n");
Expand Down
7 changes: 5 additions & 2 deletions src/fft/src/spgram.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 - 2021 Joseph Gaeddert
* Copyright (c) 2007 - 2022 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -471,7 +471,10 @@ int SPGRAM(_export_gnuplot)(SPGRAM() _q,
} else {
char unit = ' ';
float g = 1.0f;
liquid_get_scale(_q->frequency, &unit, &g);
float f0 = fabsf( _q->frequency - _q->sample_rate/2.0f );
float f1 = fabsf( _q->frequency + _q->sample_rate/2.0f );
float fmax = f0 > f1 ? f0 : f1;
liquid_get_scale(fmax, &unit, &g);
fprintf(fid,"set xlabel 'Frequency [%cHz]'\n", unit);
fprintf(fid,"set xrange [%f:%f]\n", g*(_q->frequency-0.5*_q->sample_rate), g*(_q->frequency+0.5*_q->sample_rate));
fprintf(fid,"plot '-' u ($1*%f+%f):2 w %s lt 1 lw 2 lc rgb '#004080'\n",
Expand Down

0 comments on commit 7425b66

Please sign in to comment.