PSoC C Programming Help

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

So I modified the AN2283 FrequencyProject code provided on the Cypress Website (http://www.cypress.com/?rID=2671) so that it can read frequencies from a microphone. So what I really want to do is filter a siren from other noises and the siren fluctuates in the pattern of 1.5kHz to 2.0kHz to 1.5kHz. Would I have to use a while loop? I am not to familiar with C.

   

 

   

Here is a snip of the modified code and the project is also attached:

   

LCD_Position(0,0);

   

if (fFreqValue >= 1.4 && fFreqValue <= 1.6) {

   

if (fFreqValue >= 1.8 && fFreqValue <= 2.2) {

   

if (fFreqValue >= 1.4 && fFreqValue <= 1.6) {

   

LCD_PrCString("Siren Detected!");

   

}

   

}

   

}

   

else {

   

LCD_PrCString("Scanning...    ");

   

}

0 Likes
11 Replies
Anonymous
Not applicable
        Your code Is inconsistent   
   
if (fFreqValue >= 1.4 && fFreqValue <= 1.6)   
{ // ... in this nest allow to 1.4KHz to 1.6KHz   
.. if (fFreqValue >= 1.8 && fFreqValue <= 2.2) // this condition never happen, because F is 1.4-1.6KHz //   
.. {   
.... if (fFreqValue >= 1.4 && fFreqValue <= 1.6)   
.... {   
...... LCD_PrCString("Siren Detected!"); // this display never issue   
.... }   
.. }   
}   
else   
{ // this nest is do when F is not 1.4-1.6KHz // .. LCD_PrCString("Scanning... ");   
}   
   
I can't understand what you want to do and your algorithm.   
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

To be honest: You define a function named DisplayValue () and do calculations within it over and over that neither me nor PSoC73 can really follow. This uncommented project even containing asm-parts (why?) is barely readable and I must agree to PSoC73's question: What is your problem? What runs and what does not??

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Are you trying to extract the siren from overall signal (BP filter) or suppress it

   

(Notch) from the signal of interest ?

   

 

   

What is the ~rate of warble in Hz ?

   

 

   

if (fFreqValue >= 1.4 && fFreqValue <= 1.6) {                                 // First you test for        1.6>=signal>=1.4

   

if (fFreqValue >= 1.8 && fFreqValue <= 2.2) {                        // Then you test for        2.2>=signal>=1.8 

   

if (fFreqValue >= 1.4 && fFreqValue <= 1.6) {                //   First you again for    1.6>=signal>=1.4

   

 

   

Why 3 inconsistemt tests ?

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

For example, if you needed to extract siren using BP you can tune your

   

filter per the defining equations with a clock timer. Note there is a side effect

   

the G will vary. Note topology leads itself to constant Q.

   

 

   

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Of just use BPF to extract a fixed BW -

   

 

   

0 Likes
Anonymous
Not applicable

Yes, I apologize on the lack of comments. What I am trying to do is detect an ambulance siren that follows the changing pattern of 1.5kHz to 2.0kHz and then back to 1.5kHz. I believe that code I wrote is wrong because it only tests for 1 instantaneous value but I want it to read a continous input maybe for a duration of 5 seconds or more, but I do not have much experience coding in C or even coding with the PSoC. fFreqValue is a changing input, but I believe the conditions I wrote is for only one instant of fFreqValue. If you can the code to only pass the first if statement the project will work and pass only frequencies within the specified range. What I want to do is test the first condition (if it passes), then second condition (if it passes), then third condition (if it passes) then display siren detected, but I believe this is has to be done over a specified time period. I believe Dana is on the right track! Thanks again for all of your help because I am fairly new to this.

0 Likes
Anonymous
Not applicable

Also I do believe I can use bandpass filters, but I thought that since this project already read frequencies I could use c programming if statements to "filter" the frequency inputs. I guess it makes more sense if you can visualize a sampling of an input signal over a certain time then see if it follows the pattern of low frequency then rising to a higher frequency then dropping back to a low frequency similar to that of an ambulance siren.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

If you used a BP filter to get rid of unwanted noise, then gained up

   

signal enough to trigger a comparator that in turn could be fed to

   

a freq cntr, with a 10 Hz gate (a measurement every 100 mS) that

   

could be the basis of tracking and testing the siren frequency. This

   

would allow you to differentiate a warbling siren vs a steady tone

   

siren as well.

   

 

   

Another way would to be measure the PW of one cycle of siren, that would yield

   

instantaneous freq, would be a fast measurement, and then take a Nyquist series of

   

samples. For example, if warble from low to high takes 1 sec, then do 10 PW

   

measurements, and if they fit a "nominal" freq response curve then you have a hit.

   

This would allow you to create templates for different siren manufacturers and

   

test all the templates for a hit.

   

 

   

Best way to do PW measurement is divide the input freq by 2 so high time = period

   

of Fx, then use that as enable to a counter/timer with a high freq clck, say 1 Mhz,

   

and count for 1 period would be = # uS of the period. Store that in a 10 sample array,

   

then get the next measurement. After 10 try to match its readings against a template

   

array.

   

 

   

Just a thought, regards, Dana.

0 Likes
Anonymous
Not applicable

 I think I might try the first suggestion. Thanks for all your help!

   

-Chris

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Attached is a basic Freq Cntr project that may be useful. Its setup

   

for 1 sec gate, you can easily make the changes for 100 mS gate.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 Thanks so much for your help!!!

   

-Chris

0 Likes