Wolfram Signal Processing | Things to Try

Make edits and run any piece of code by clicking inside the code and pressing
+
.
Signal Processing & Analysis. Comprehensive signal processing capabilities, tightly bundled with powerful calculus, statistics and machine learning, for students and professionals in engineering, finance, medicine and more.

Lowpass IIR Butterworth Filter

Create the analog Butterworth prototype of order
n=3
for an infinite impulse response (IIR) filter with cutoff frequency
ω
c
=π/6
assuming sampling period
T=1
:
Run
In[]:=
T=1;
ω
c
=
π
6
;n=3;
Ω
c
=
2.
T
Tan
ω
c
2
;tf=ButterworthFilterModel[{n,
Ω
c
},s]//TransferFunctionExpand//Chop
Create the corresponding digital filter using bilinear transformation:
Run
In[]:=
dtf=ToDiscreteTimeModel[tf,T,z]//Chop
Visualize the Bode plot of the filter:
Run
In[]:=
BodePlotdtf,{0,π},

Data Filtering with an IIR Filter

Create a noisy sinusoidal signal:
Run
In[]:=
sig=TableSin
3.π
128
n,{n,0,127}+RandomReal[{-0.25,0.25},128];
Define an IIR Butterworth filter:
Run
In[]:=
dtf=
0.153903
3
(1.+z)
-4.70766+19.0258z-26.6767
2
z
+13.5898
3
z
1
;
Filter the noisy signal:
Run
In[]:=
res=RecurrenceFilter[dtf,sig,Padding->None];ListPlot[{sig,res}]

Lowpass FIR Filter Using the Window Method

Create a length
L=17
finite impulse response (FIR) filter with cutoff frequency
ω
c
=π/6
:
Run
In[]:=
ω
c
=
π
6
;L=17;h=LeastSquaresFilterKernel[{"Lowpass",
ω
c
},L]
Apply a Hann window to the unit sample response:
Run
In[]:=
w=Array[HannWindow,L,{-0.5,0.5}];fir=wh
Show the frequency response of the resulting filter:
Run
In[]:=
PlotEvaluate[20Log10[Abs[ListFourierSequenceTransform[fir,ω]]]],{ω,0,π},

Data Filtering with an FIR Filter

Create a noisy signal:
Run
In[]:=
sig=Table[SquareWave[n/64],{n,0,127}]+RandomReal[{-0.25,0.25},128];
Create a lowpass FIR filter:
Run
In[]:=
fir=LeastSquaresFilterKernel[{"Lowpass",π/6},17]Array[HannWindow,17,{-0.5,0.5}];
Filter the signal using
ListConvolve
:
Run
In[]:=
res=ListConvolve[fir,sig,9];ListPlot[{sig,res}]
Equivalently, filter the signal using the
LowpassFilter
function:
Run
In[]:=
ListPlot[{sig,LowpassFilter[sig,π/6,17,HannWindow,Padding->0]}]

Power Spectrum of a DTMF Signal

Define a pair of dual-tone multi-frequency (DTMF) normalized frequencies (in radians/sample) for the dial-tone digit 2:
Run
In[]:=
{fp,fs}={697,1336};{wp,ws}=
2π
8000.
fp,
2π
8000.
fs
Create a dual-tone signal of approximately 200 ms duration:
Run
In[]:=
dtmf=Table[Sin[wpn]+Sin[wsn],{n,0,1799}]+RandomReal[{-0.25,0.25},1800];audio=AudioPad[Audio[dtmf,SampleRate8000],{0.02,0.02}]
Displays the power spectrum:
Run
In[]:=
Periodogramaudio,
Welchs method averages power spectra of smoothed and overlapped partitions:
Run
In[]:=
Periodogramaudio,600,300,BlackmanWindow,

Signal Analysis Using a Spectrogram

Define pairs of DTMF normalized frequencies (in radians/sample) for the dial-tone digits 9 and 1:
Run
In[]:=
freqs=
2π
8000.
#[[1]],
2π
8000.
#[[2]]&/@{{852,1447},{697,1209}}
Create an audio clip for the dual-tone sequence:
Run
In[]:=
dtmf=(Table[Sin[#[[1]]n]+Sin[#[[2]]n],{n,0,1799}]+RandomReal[{-0.25,0.25},1800]&)/@freqs;audio=AudioJoin[AudioPad[Audio[#,SampleRate8000],{0.01,0.01}]&/@dtmf]
View the spectrogram:
Run
In[]:=
Spectrogramaudio,
Improve the frequency resolution by increasing the segment length:
Run
In[]:=
Spectrogramaudio,512,
Additionally, improve the time resolution by increasing the overlap between segments:
Run
In[]:=
Spectrogramaudio,512,64,

Time Series Processing

Get daily temperature data. The data has a sampling period of
T=1
day or
T=86400
seconds giving a sampling rate of
sr=
1
86400
samples per second:
Run
In[]:=
ts=TimeSeries
Time:
01 Jan 2024
to
06 Aug 2024
Data points: 219
;
Smooth the data by applying a lowpass filter with a cutoff frequency approximating a weekly average:
Run
In[]:=
sr=1/86400;DateListPlotts,LowpassFilterts,
π
6
sr,15,
Additionally, compute and visualize the approximate monthly average:
Run
In[]:=
DateListPlotts,LowpassFilterts,
π
6
sr,15,LowpassFilterts,
π
186
sr,65,
Wolfram Cloud

You are using a browser not supported by the Wolfram Cloud

Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


I understand and wish to continue anyway »

You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.