Go Down

Topic: Question about magnitude (Read 2881 times) previous topic - next topic

Noisecontrol

Why in the sin wave example code if amplitude multiplay 2 it become equal peak amplitude .
Do in this code if amplitude *2 it become peak amp?

PieterP

I don't understand your question.

Noisecontrol

#92
Jun 22, 2018, 02:24 pm Last Edit: Jun 22, 2018, 02:27 pm by Noisecontrol
Hello pieter
I change code to this and use 3.3 V of ardino pin

Code: [Select]

#define LIN_OUT 1 // use the log output function
#define FHT_N 256 // set to 256 point fht
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

#include <FHT.h> // include the library
const double a12200 = pow(12200,2);
const double a206 = pow(20.6,2);
const double a1077 = pow(107.7,2);
const double a7379 = pow(737.9,2);
const double CORR = 0;

const int GAIN = 1;

int f;
double RA,CF,f2,f4,C,ADCNUM;


void setup() {
  Serial.begin(115200); // use the serial port
  ADCSRB = 0; // Free running mode
  ADMUX = (DEFAULT << 6) | 0; // A0
  sbi(ADCSRA, ADEN); // Enable ADC
  sbi(ADCSRA, ADATE); // Auto trigger
  sbi(ADCSRA, ADSC); // Start conversion
  // 19.231 kHz
  sbi(ADCSRA, ADPS2);
  sbi(ADCSRA, ADPS1);
  cbi(ADCSRA, ADPS0);
}

void loop() {
 do {
    cli();  // UDRE interrupt slows this way down on arduino1.0
    for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples
      while (!(ADCSRA & _BV(ADIF))); // wait for adc to be ready
      sbi(ADCSRA, ADIF); // Clear interrupt flag
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int k = (j << 8) | m; // form into an int
      k -= 0x0200; // form into a signed int
      k <<= 6; // form into a 16b signed int
      fht_input[i] = k; // put re3l data into bins
    }
    fht_window(); // window the data for better frequency response
    fht_reorder(); // reorder the data before doing the fht
    fht_run(); // process the data in the fht
    fht_mag_lin(); // take the output of the fht
    sei();
    for (uint8_t i = 0 ; i < FHT_N / 2 ; i++) {
      f=i * 19231UL / FHT_N;
      Serial.print(f);
      Serial.print(" HZ:");
      Serial.println(fht_lin_out[i]); // send out the data
    }
  } while(0);
  while(1);
}




Result is for frequency 1051 Hz is 2928

Code: [Select]


0 HZ:16000
75 HZ:7936
150 HZ:23
225 HZ:36
300 HZ:6
375 HZ:11
450 HZ:9
525 HZ:30
600 HZ:20
676 HZ:30
751 HZ:4
826 HZ:19
901 HZ:59
976 HZ:1664
1051 HZ:2928
1126 HZ:1296
1201 HZ:29
1277 HZ:20
1352 HZ:17
1427 HZ:31
1502 HZ:10
1577 HZ:21
1652 HZ:20
1727 HZ:24
1802 HZ:11
1878 HZ:14
1953 HZ:46
2028 HZ:780
2103 HZ:1224
2178 HZ:468
2253 HZ:23
2328 HZ:17
2403 HZ:7
2478 HZ:5
2554 HZ:12
2629 HZ:13
2704 HZ:19
2779 HZ:17
2854 HZ:12
2929 HZ:15
3004 HZ:13
3079 HZ:81
3155 HZ:130
3230 HZ:54
3305 HZ:12
3380 HZ:26
3455 HZ:20
3530 HZ:38
3605 HZ:17
3680 HZ:36
3756 HZ:32
3831 HZ:20
3906 HZ:13
3981 HZ:4
4056 HZ:55
4131 HZ:370
4206 HZ:468
4281 HZ:135
4357 HZ:26
4432 HZ:16
4507 HZ:16
4582 HZ:7
4657 HZ:26
4732 HZ:27
4807 HZ:13
4882 HZ:3
4957 HZ:12
5033 HZ:8
5108 HZ:28
5183 HZ:178
5258 HZ:197
5333 HZ:46
5408 HZ:8
5483 HZ:9
5558 HZ:26
5634 HZ:46
5709 HZ:17
5784 HZ:9
5859 HZ:26
5934 HZ:6
6009 HZ:9
6084 HZ:1
6159 HZ:20
6235 HZ:72
6310 HZ:74
6385 HZ:10
6460 HZ:13
6535 HZ:11
6610 HZ:36
6685 HZ:25
6760 HZ:35
6836 HZ:20
6911 HZ:29
6986 HZ:6
7061 HZ:17
7136 HZ:13
7211 HZ:19
7286 HZ:59
7361 HZ:52
7436 HZ:2
7512 HZ:17
7587 HZ:7
7662 HZ:12
7737 HZ:44
7812 HZ:42
7887 HZ:6
7962 HZ:6
8037 HZ:5
8113 HZ:8
8188 HZ:8
8263 HZ:20
8338 HZ:44
8413 HZ:29
8488 HZ:1
8563 HZ:3
8638 HZ:9
8714 HZ:44
8789 HZ:51
8864 HZ:18
8939 HZ:10
9014 HZ:14
9089 HZ:12
9164 HZ:8
9239 HZ:10
9315 HZ:31
9390 HZ:36
9465 HZ:17
9540 HZ:9




I dont know how this number change to voltage
Please help me and say what is furmula for do it and write it for me



PieterP

I dont know how this number change to voltage
Please help me and say what is furmula for do it and write it for me
No. I cannot keep on holding your hand like this. I already gave you the formulas you need, and the documentation of the FHT library tells you what the different functions do to the output, how to interpret it, and the mathematical formulas used to calculate these results.

Noisecontrol

Why k value in above code is biger than 1024?
Code: [Select]

fht_input[i] = k; // put real data into bins

PieterP

Write down mathematically what happens with k, then you know why.

Noisecontrol

#96
Jun 22, 2018, 08:44 pm Last Edit: Jun 22, 2018, 08:48 pm by Noisecontrol
Write down mathematically what happens with k, then you know why.
My math is bad
I wish to have good math
I have to leave this project after one month effort .it doesnt have any thrive

PieterP

Whining about it won't help. Trying will.

Noisecontrol

#98
Jun 23, 2018, 04:22 am Last Edit: Jun 23, 2018, 01:30 pm by Noisecontrol
I think k is 16 bit thus range of it is 0 to 65536
Thus per 1 ADC  is equal voltage/65536
For example for 5 volt is equal 0.000076 volt
Is it true?

Noisecontrol

#99
Aug 05, 2018, 08:27 pm Last Edit: Aug 05, 2018, 08:29 pm by Noisecontrol
Hello
Finally make sound level meter after 4 month
It show dBA
Leq
Sone
Phone
Ta
NRR
O

Go Up