MATLAB Examples

# Low Pass Filter an Infiniium Waveform

The InfiniiumWaveform Toolbox lets you easily modify, in Matlab, data acquired on the scope, and then load the results back onto the scope. This demo starts with a .mat file saved by the scope, applies a low-pass filter to it, and then saves it to a new .mat file, which can be opened by the scope.

## Read scope waveform

The first step is to save a waveform file from the scope in .mat format. We can use one of the demo files in the help folder as an example. The infiniiumWfmRead function opens the file and reads the waveform data.

```inputFilename = 'channel_1_Demo.mat'; % file saved by scope [y,x0,dx,x] = infiniiumWfmRead(inputFilename); % read data ```

## Construct a filter

Construct a low-pass filter using MATLAB's Signal Processing Toolbox. For this example we'll construct a 2nd order Butterworth filter with cutoff frequency 1/10 the sample rate.

Construct the filter

```fs = 1/dx; % sample rate is the inverse of the sample time fc = .1*fs; % cutoff frequency order = 2; % filter order [b,a] = butter(order,fc/(fs/2)); % construct Butterworth filter ```

Plot the filter

```figure(1), hold off, [h,w] = freqz(b,a); plot(fs*w/(2*pi),mag2db(abs(h))) % plot filter magnitude in dB grid xlabel('Frequency (Hz)') ylabel('Attenuation (dB)') ``` ## Filter the waveform

Use the filter function to filter the waveform, and plot the results.

```yOut = filter(b,a,y); % filter the data figure(2), hold off, plot(x,y,'b') % plot original data hold on, plot(x,yOut,'r') % plot filtered data legend({'original','filtered'}) xlabel('Seconds'), ylabel('Volts'), title('filtered waveform') ``` ## Save to waveform file

We can now save the filtered waveform to a new .mat waveform file that can be opened on the scope. The function infiniiumWfmSave will format the data automatically for Infiniium. We can change the source label to Channel_1_Filtered to indicate that we modified the file by filtering. This label doesn't show up on the scope, but it's a useful reference for when the file is opened again in MATLAB.

```outputFilename = 'tmp.mat'; % output file infiniiumWfmSave(yOut,x0,dx,outputFilename,'Source','Channel_1_Filtered'); ```