LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CALCULATE THE FREQUENCY OF A SQUARE WAVE WITH NOISE

HI,

for the study and analysis of a signal that then I will experimentally acquire  through a USB 6009, I am trying to write a specific code in LabVIEW that allows me to measure the frequency of a Square Wave with the presence of noise.

In this moment not of practical acquisition, I am considering as source of my Square Wave the Simulate Signal,I'm doing all the attempts with signals generated in this way, with orders of quantities not fundamental for now.

 

What could be a solution? Which code could I implement?

I am attaching a written program that i find here in the Community that through the count of the times when the square wave "is high" compared to the duration of the signal, gives me the correct frequency but only if I do not add the noise through the Simulate.

Could it be modified to provide the correct result even with the presence of noise?

I hope you can help me and thank you all!

0 Kudos
Message 1 of 7
(3,729 Views)

There are many ways to solve this problem.  What do you know about Signal Analysis?  Are you familiar with Frequency Spectra?  How's your Math skills?  Ever heard about fitting a function to data using Least Squares?

 

I'm going to delete the rest of this post -- I realized I was "starting to give a lecture about Fitting Functions to Data", which is not part of my current Job Description, and probably isn't what you want.  Still, sooner or later it may serve you well to know something about it.  I'm assuming you are an Engineering Student -- pay attention in Signals class, and learn some Statistics.

 

Bob Schor

 

0 Kudos
Message 2 of 7
(3,702 Views)

Thanks for the quick answer Bob!

 

I am now approaching to this kind of analysis on labview, and no .. although I do not know well the LabVIEW function that regards this type of specific studies, it is nice to read and learn 🙂

I share the importance of knowing the analysis of the signals and learning more and more!

So absolutely No Problem! 🙂
I am generating with the Simulate Signal a "classic" Square Wave for test (i have attached a screenshot of my simulation) and for now I would like to know a code that allows me to calculate the frequency just of the signal with the noise generated. 

For now i want study just this,without other problems and parameters that could be born experimentally then.
Could I have a simple code VI to start studying it? A simple programmed code VI based for example as you mentioned on Frequency Spectra that will calculate the frequency for the signal I simulated?

 

Thank you very much and I hope in your answer!

It would be really important for me to solve this problem,and then continue my learning to carry out my entire experiment!

Thanks again,

 

Vinlet

 

0 Kudos
Message 3 of 7
(3,691 Views)

About two years ago, I got a Very Well Deserved "reputation" on these Forums for yelling and screaming "No Pictures, show us the VIs or the entire LabVIEW Project!".  I've calmed down a bit (particularly since there is, in some instances, a virtue in attaching LabVIEW Snippets, which are, after all, LabVIEW wrapped inside a .PNG file).  However, NEVER SEND CODE VIA POWERPOINT!!!  Not everyone uses Microsoft Office, Office is a great vector for passing Viruses and Malware to unsuspecting folk, and the usual objection to Pictures vs Code (they are sometimes hard to see, they sometimes only show part of the code, and maybe the part that doesn't have the problem, they only show one case of a Case structure, they can't be edited, you can't ask LabVIEW for "Help" on a function you don't recognize, and you can't "run" the Picture to see where/how it fails) applies to PowerPoint images, as well.

 

Accordingly, I haven't looked at your pictures.  However, I'd be happy to look at your code.

 

In my "mini-rant", above, I mentioned a LabVIEW Snippet.  Here's how to make them:

  1. Go to your Block Diagram.
  2. Select what you want to show.  For best results (from we Forum readers), Select Everything (which you can do by typing ^A, Control-A).
  3. In the Edit Drop-down menu, choose "Create VI Snippet from Selection" (it's just past half-way down).  It will ask you to name the Snippet (choose a meaningful name, it's good practice) and ask where you want to save it (Desktop, My Documents, someplace else?).
  4. At the bottom of the Forum Reply window, there's a button on the left that says "Choose File".  Click it, navigate to your Snippet, and select it.  When you Post your reply, the Snippet will go along as an attachment.

Why bother?  Why is this Picture different from All Other Pictures?  Because it is a LabVIEW Snippet, not an ordinary PNG -- if a Forum Reader drags and drops it into an appropriate Block Diagram (e.g. into LabVIEW 2017 or 2018 if the Snippet was created with LabVIEW 2017), the "picture" will magically turn into LabVIEW code!  Don't ask me how -- there are Wizards at work in Austin.

 

So try again, and send me your code ...

 

Bob "A Little Calmer" Schor

0 Kudos
Message 4 of 7
(3,686 Views)

Thanks again Bob,

 

and I'm really sorry for the Microsoft file! I apoligize! And i follow your advise...never send this type of file here! 🙂

So I attach the VI as you suggested me to do.

In this VI as I said in the previous message,i calculate the frequency of the Sqaure Wave generated with Simulate Signal but only WITHOUT NOISE!

Could I have a simple  VI to study based for example as you mentioned on Frequency Spectra that will calculate the frequency of Square Wave with noise?

For now i'm studying this only for "classic" simulated Square Wave,so it's ok an easy and generic code,without other problems and parameters that could be born experimentally then.

 

Thanks a lot again and i hope in your response!

 

0 Kudos
Message 5 of 7
(3,677 Views)

Assume you have a waveform (any waveform) made up of a sub-section that repeats over and over again (without any noise).  An example would be something that alternates from 0 to 1 to 0 to 1 to ... (i.e. a Square Wave), where the "unit of repeat" is a High (for some time) followed by a Low (for some time).  Another example would be a sinusoid.  How would you go about determining the period of the repeat?  If an answer doesn't immediately pop into your head, do the following experiment:

  • Take a strip of paper and draw a square wave on it.  Make the square wave near the edge of the paper.
  • Make a copy of this paper.
  • Look at your two square waves.  Find an operation that shows you the period of the repeat.

There are "more sophisticated" methods of doing this, but this simple method requires much less mathematical sophistication and is visually "easy to see".

 

Now use the Waveform Generator to generate a Square Wave (by default, if you specify no parameters, it will generation 10 cycles of a 10Hz square wave).  Write a VI that returns the period of this square wave (it should return 0.1 s).  Test it by changing the period of the Square Wave.  What happens if you use a frequency of 7Hz?

 

Now add a little noise to the Square Wave and try again.

 

Bob Schor

0 Kudos
Message 6 of 7
(3,637 Views)

Help >>> Find Examples ...

 

Browse for something that sounds like what you are trying to do.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 7
(3,621 Views)