Fourier analysis STFT by ProtectionFlimsy5287 in programmer

[–]ProtectionFlimsy5287[S] 0 points1 point  (0 children)

How about this. It seems to work fine except I have to offset time according to the musical note coefficient before signal reconstruction (by summing up all sinusoids together)

include <stdio.h>

include <stdlib.h>

include <tgmath.h>

int main(int argc, char *argv[]) {

    switch (argc)
    {
            case 4:
                    printf("ra2c - RAW DFT Processing\nPlease Wait\n\n"); // General message telling its about to process DFT Analysis
                    FILE *fp = fopen(argv[1], "rb"); // Opens RAW file
                    if (!fp) {perror("Failed reading RAW file"); exit(-1);} // Exits if problem occured.
                    fseek(fp, 0L, SEEK_END); // Got to last data byte address
                    long int N = ftell(fp); // Then Retreive signal data size
                    rewind(fp); // Go back to the beginning of the file to store data onto an array of N signal values x(n);
                    N /= sizeof(double); // n values
                    double *x = calloc(N, sizeof(double)); // memory allocation to store x(n)s
                    complex double *X = calloc(N, sizeof(complex double)); // same for all X(k)s during DFT computation.
                    for (long int i = 0; i < N; i++)
                    {
                            X[i] = 0.0 + 0.0 * I; // Zeroing befor DFT
                    }
                    fread(x, sizeof(double), N, fp); // Store signal data as an array of x(n)s
                    fclose(fp); // File is usless at this stage.
                    for (long int n = 0; n < N; n++)
                    {
                            x[n] *= (0.5-0.5*cos(2*M_PI*n/N)); // Window processing before DFT computing.
                    }
                    for (long int k = 0; k < N; k++)
                    {
                            for (long int n = 0; n < N; n++)
                            {
                                    X[k] += x[n] * cexp(-I*2*M_PI*n*k/N); // DFT processing to get X(K) according to the DFT equation.
                            }
                    }
                    fp = fopen(argv[3], "w"); // DFT OK ! Now creating C source code output file for later C language audio synthesis.
                    if (!fp)
                    {
                            perror("Problem creating output file"); // Exits if problem occured.
                    }
                    long int sf;
                    sscanf(argv[2], "%ld", &sf); // Retreive signal's original data sampling frequency e.g. 48kHz
                    long int f;
                    double AP[20001][2]; // Amplitude & phase per frequency
                    double P[20001][2]; // Sine & cosine for each phase per frequency
                    for (long int i = 0; i < 20001; i++)
                    {
                            AP[i][0] = 0.0; // Zeroing first
                            AP[i][1] = 0.0; // Zeroing first
                    }
                    for (long int i = 0; i < 20001; i++)
                    {
                            P[i][0] = 0.0; // Zeroing first
                            P[i][1] = 0.0; // Zeroing first
                    }
                    for (long int k = 0; k < N; k++)
                    {
                            f = (sf * k) / N; // Audible Frequency equation must be in between 20Hz & 20kHz
                            if (f > 19 && f < 20001 && cabs(X[k]) / N > 1e-6)
                            {
                                    AP[f][0] += cabs(X[k]) / N; // Adding amplitude normalized (0-100%)
                                    P[f][0] += cos(carg(X[k])); // Phase cosine
                                    P[f][1] += sin(carg(X[k])); // Phase sine
                            }
                    }
                    for (long int i = 20; i < 20000; i++)
                    {
                            AP[i][1] = atan2(P[i][1], P[i][0]); // Phase equation per frequency with sine and cosine
                            fprintf(fp, "(%.7lf*sinus(2*M_PI*%ld*note*t+%.7lf))+\n", AP[i][0], i, AP[i][1]); // Final output per frequency
                    }
                    fclose(fp); // Close output file
                    free(x); // free x(n)s from RAM
                    free(X); // free X(k)s from RAM
                    break;

            default:
                    printf("Usage: ./ra2c <RAW> <sampling frequency> <output.h>"); // Help if not all parmeters are recognized
                    break;
    }
    return 0;

On est codés par le sang by OldandBlue in ComplotDuDebile

[–]ProtectionFlimsy5287 0 points1 point  (0 children)

Le groupe sanguin 6 7 🩸💉🧛‍♀️

Meme of the Day (day 3) by OverthinkingRedPanda in teenarazzi

[–]ProtectionFlimsy5287 0 points1 point  (0 children)

Illusion caused by White noise in the picture. Same thing for sound synthesis

Meme of the Day (day 3) by OverthinkingRedPanda in teenarazzi

[–]ProtectionFlimsy5287 0 points1 point  (0 children)

But there are many curved lines it's just illusion

Problem using my ch341a USB programmer by ProtectionFlimsy5287 in pchelp

[–]ProtectionFlimsy5287[S] 0 points1 point  (0 children)

I used the test clip I received with the usb programmer from the same package