1
$\begingroup$

This question already has an answer here:

As there is no ChirpSignal function in Mathematica, I wrote a simple code to generate a sinusoid with a frequency that changes continuously from frequency f1 to f2 over a certain time of t

This is what I"ve done to generate the chirp:

{freq0, freqs, TrBandw, RCbandw, pulseLength, dt} = 
  {9 10^6, {10 10^6, 20 10^6}, 4, 10^6, 5 10^5, 2.67 10^-6, 1 10^-8};

i = 0;
nfreqs = Length@freqs;
n = Ceiling[pulseLength/dt];

fmin = freqs[[1]] - RCbandw/2;
fmax = freqs[[-1]] + RCbandw/2;

nextend = n*nfreqs;
w = 2 Pi (fmin + Range[0, nextend - 1] (fmax - fmin)/(nextend - 1));

Phi = 
  PadRight[
    Accumulate[Insert[Table[w[[i]] dt, {i, 2, n*nfreqs}], 0, 1]], 
    IntegerPart[((nfreqs + 1) pulseLength)/dt], 
    0];

s = Sin[Phi];

enter image description here

Through my previous question I learned simpler methods to generate a chirp, BUT I still need to filter the chirp with a Butterworth to remove frequencies that do not fit in the span of [cut1, cut2]

cut1 = (freq0 - 0.5 TrBandw)/(1/dt/2)
cut2 = (freq0 + 0.5 TrBandw)/(1/dt/2)

cut1 = 0.14 Hz
cut2 = 0.22 Hz

I know how to filter the signal in matlab and the final result looks something like this

enter image description here

However, my entire code is written in Mathematica, so it would be great to have help with the filtering part, too.

$\endgroup$

marked as duplicate by Karsten 7., Sjoerd C. de Vries, rm -rf Nov 27 '14 at 8:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ None of the answers address the Butterworth bandpass filter which completes the process of generating the chirped signal. $\endgroup$ – kvnF2 Dec 7 '14 at 23:41
0
$\begingroup$
Clear[PulseTemplateChirp];
PulseTemplateChirp[freq0_, freqs_, TrBandw_, RCbandw_, pulseLength_, 
  dt_] :=
 Block[{fmin, fmax, chirpLength0, nfreqs, 
   chirpLength, \[Phi],(*chirp0,*)cut1, cut2, tf, dtf, chirp1, cut01, 
   cut02, bwf, dbwf, chirpn, z},

  fmin = freqs[[1]] - RCbandw/2;
  fmax = freqs[[-1]] + RCbandw/2;

  chirpLength0 = Round[pulseLength/dt] + 1;
  nfreqs = Length@freqs;
  chirpLength = nfreqs chirpLength0;

  \[Phi] = PadRight[
    Accumulate[
     Insert[
      Table[
       2 \[Pi] (fmin + (fmax - fmin)/chirpLength t) dt, {t, 2, 
        chirpLength}]
      , 0, 1]
     ],
    IntegerPart[((nfreqs + 1) pulseLength)/dt], 0];

  chirp0 = Sin[\[Phi]];


  cut1 = (freq0 - 0.5 TrBandw)/0.5;
  cut2 = (freq0 + 0.5 TrBandw)/0.5;

  (*This creates a Butterworth filter with a 5 dB passband at 
  cut1\[LessEqual]f\[LessEqual]cut2 and -50 dB stopbands at f\
\[LessEqual](0.8cut1) and f\[GreaterEqual](2cut2)*)
  tf = ButterworthFilterModel[{"Bandpass", 
     2 \[Pi] {0.8 cut1, cut1, cut2, 2 cut2}, {50., 5.}}];
  (*Convert to discrete-time IIR filter*)
  dtf = ToDiscreteTimeModel[tf, 0.5 dt, z];
  (*Filter chirp sequence*)
  chirp1 = RecurrenceFilter[dtf, chirp0];

  chirpn =
   Reap[
     Do[
      cut01 = (freqs[[i]] - 0.5 RCbandw)/0.5;
      cut02 = (freqs[[i]] + 0.5 RCbandw)/0.5;

      bwf = 
       ButterworthFilterModel[{"Bandpass", 
         2 \[Pi] {0.9 cut01, cut01, cut02, 2 cut02}, {15., 2.}}];
      dbwf = ToDiscreteTimeModel[bwf, 0.5 dt, z];

      Sow[RecurrenceFilter[dbwf, chirp1]],

      {i, nfreqs}]
     ][[2, 1]]
  ]


chirps = PulseTemplateChirp[9 10^6, {10 10^6, 12 10^6}, 4 10^6,5 10^5, 2.67 10^-6, 1 10^-8];

ListLinePlot[chirps[[1]]]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.