Example Code

Signal to Square Wave Converter Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

 Overview

This example shows one way to convert an input signal into a square wave of arbitrary amplitude.

 

Description

This example shows one way to convert an input signal into a square wave of arbitrary amplitude.  The VI takes an input signal, filters it to get the desired frequency components, then amplifies the signal greatly so that it can then be clipped into a square wave.  The example assumes that the measured signal does not have a DC offset or that the DC offset is removed during filtering.  An offset can be applied to the signal after filtering but before scaling to change the duty cycle of the resulting square wave if desired.  The program assumes that the input signal is an array of doubles.

  

Requirements

LabVIEW Full System Development 2012 or compatible, LabVIEW Advanced Signal Processing Toolkit 

 

Steps to Implement or Execute Code

  1. Enter the Input Original Signal parameters (Number of samples, Amplitude, Frequency
  2. Enter the filter parameters for the incoming signal (fs, fh, fl, order)
  3. Enter the Upper and Lower limits for the desired Output Square Wave
  4. Run the VI

 

Additional Information or References

VI Front Panel

3797 fp.PNG

VI Block Diagram

 

3797.PNG

 

**This document has been updated to meet the current required format for the NI Code Exchange. **

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Todd S.
NI Employee (retired)
on

Doesn't look like the attachment is showing up...

Todd S.
LabVIEW Community Manager
National Instruments
Burt_S
NI Employee (retired)
on

Thanks Todd.Fixed it!

BigBri
Member
Member
on

Why not pass the original signal array through the 'Sign' function to get a unit amplitude square wave then scale it to the amplitude you need? Much less code required.