1
$\begingroup$

I'm attempting to use a frequency mixer to shift one frequency range to another. Right now, I have a complex sine wave at $43\ \rm kHz$. My imaginary value on the complex object is 0.

If I output a frequency-amplitude spectrum it looks like this:

enter image description here

Now let's say I want to move that frequency to $65\ \rm kHz$. For that I realized that I need to create a new complex sine wave at that frequency and multiply it by my original signal in time.

The problem is, it's not working. I'm getting 2 spikes for some reason. I don't understand why that happens.

enter image description here

Here is my code:

typedef std::complex<float> Complex; Complex chunk[N]; float Fs = 176400; // How many time points are needed i,e., Sampling Frequency const double T = 1 / Fs; // At what intervals time points are sampled float value; float value2; for (int i = 0; i < N; i++) { value2 = (float)(1 * sin(2 * M_PI * 43000 * (i * T))); // Original Signal Complex value3 = {(float)(1 * sin(2 * M_PI * 12000 * (i * T))), 0}; // The frequency I want to add double multiplier = 0.5 * (1 - cos(2*M_PI*i/256)); // Hamming Window chunk[i] = {value2 * multiplier, 0 };// generate (complex) sine waveform chunk[i] = chunk[i] * value3; // Frequency Mixer } 
$\endgroup$
0

1 Answer 1

0
$\begingroup$

your original signal is a real-valued sine - so, that's not one spike to begin with, but two.

Nothing in your code actually computes a complex sine, so that's your bug!

You will have to review what a complex sine is (hint: it's not a complex number where the imaginary part is 0!). The rest will clear itself up.

$\endgroup$
4
  • $\begingroup$ This code was just an example, I actually read 1D samples from a wav audio file, I don't have an option but to use real-valued "complex" value where the imaginary part is 0, and it's working fine until now where I came across this issue. $\endgroup$ Commented Sep 1, 2021 at 17:13
  • $\begingroup$ your mixer / local oscillator still is not a complex one. So, that's your bug. You introduce that imaginary part for exactly no purpose – it's zero all along. $\endgroup$ Commented Sep 1, 2021 at 17:14
  • $\begingroup$ @yarinCohen Write your signals in terms of complex exponentials, and carry out the calculations -- you will see what is happening. $\endgroup$ Commented Sep 1, 2021 at 17:16
  • $\begingroup$ Thank you, I solved my issue by creating my sine wave this way: Complex value3 = {(float)(1 * cos(2 * M_PI * 22000 * (i * T))),(float)(1 * sin(2 * M_PI * 22000 * (i * T)))}; $\endgroup$ Commented Sep 1, 2021 at 17:20

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.