这一看就是百度做的,百度文库的味道。
我刚试了一下:
#include <c6x.h>
#include <csl.h>
#include <math.h>
#define PI 3.14159265358979323846
/* Initialize PLL */
void initPLL(unsigned int pllm, unsigned int plld, unsigned int pllf)
{
PLL_CONFIG pllcfg;
/* Configure PLL */
pllcfg.PLLM = pllm;
pllcfg.PLLD = plld;
pllcfg.PLLF = pllf;
pllcfg.PLLR = 4; // Divide system clock by 4
pllcfg.PLLM2 = 2;
pllcfg.odiv1_div = 1;
pllcfg.odiv2_div = 1;
/* Initialize PLL */
PLL_init(&pllcfg);
/* Wait for PLL to lock */
while (!PLL_locked());
}
/* Initialize DAC */
void initDAC(void)
{
/* Configure DAC */
DAC_config(DAC_CHANNEL_BOTH, DAC_FMT_SIGN_MAG, DAC_POL_UNIPOLAR, DAC_REF_INTERNAL, DAC_ALIGN_LEFT);
DAC_enable(DAC_CHANNEL_BOTH);
}
/* FM Modulation */
void FMModulate(float freqDeviation, float sampleRate, float *inputBuffer, float *outputBuffer, int numSamples)
{
float phi = 0.0;
float deltaPhi = 2 * PI * freqDeviation / sampleRate;
/* FM modulation loop */
for (int i = 0; i < numSamples; i++) {
/* Update phase */
phi += deltaPhi + 2 * PI * inputBuffer[i] / sampleRate;
if (phi > 2 * PI) {
phi -= 2 * PI;
}
/* Generate modulated output */
outputBuffer[i] = sinf(phi);
}
}
int main(void)
{
float sampleRate = 44100.0; // Sample rate in Hz
float freqDeviation = 75000.0; // Frequency deviation in Hz
float *inputBuffer, *outputBuffer;
int numSamples = 1024;
/* Initialize PLL and DAC */
initPLL(40, 2, 200);
initDAC();
/* Allocate memory for input and output buffers */
inputBuffer = (float *)malloc(numSamples * sizeof(float));
outputBuffer = (float *)malloc(numSamples * sizeof(float));
/* Generate input signal */
for (int i = 0; i < numSamples; i++) {
inputBuffer[i] = sinf(2 * PI * 1000.0 * i / sampleRate);
}
/* Perform FM modulation */
FMModulate(freqDeviation, sampleRate, inputBuffer, outputBuffer, numSamples);
/* Output modulated signal to DAC */
for (int i = 0; i < numSamples; i++) {
DAC_write(DAC_CHANNEL_BOTH, outputBuffer[i]);
}
/* Free memory */
free(inputBuffer);
free(outputBuffer);
return 0;
}
#define ORDER 1 // Pre-emphasis filter order
#define COEFF 0.95 // Pre-emphasis filter coefficient
float preEmphasisFilter(float x, float *z)
{
float y;
y = x + COEFF * z[0]; // Filter equation
z[0] = x; // Update filter state
return y;
}
int main(void)
{
float x, y, z[ORDER];
/* Initialize filter state */
for (int i = 0; i < ORDER; i++) {
z[i] = 0;
}
/* Pre-emphasis loop */
while (1) {
/* Read input signal */
x = readInput();
/* Apply pre-emphasis filter */
y = preEmphasisFilter(x, z);
/* Process output signal */
processOutput(y);
}
return 0;
}
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |