AM modulation of audio file

Hi,
I want to do amplitude modulation of an audio signal. More specifically, I want to mix my .wav audio file with a high frequency carrier. I searched the forums but couldn't find a problem similar to mine.
The problem is that the .wav audio file's sampling rate is fixed (actually 8kHz in my .wav file but here I assumed 40 kHz), which means I can't change that. And since my carrier frequency is 25k, the sampling frequency for the carrier signal should be a lot higher. In short, I mean, my audio signal and carrier signal have different fs.
1. I can't generate x2 (carrier) properly. Although I made it the same length as x1 (audio), the plots of x1 and x2 seem somewhat similar although they're different in frequency by around 6 times.
2. Because of that, my mixer output isn't correct.
I'd appreciate it if someone could explain why this is so and what I can possibly do to rectify it.
My understanding is that, since x2 was sampled at a much higher frequency and also made the same length as x1, x2 was "expanded" a bit.
Below is my code:
clear all;
clc;
close all;
fs1 = 40000; %sampling frequency for my audio signal (fixed)
fs2 = 250000; %sampling frequency
%modulating signal (assume single tone 4 kHz)
f1=4000;
t1=(0:5*fs1)/fs1; %5 seconds signal
x1=sin(2*pi*t1*f1);
%carrier signal
fc = 25000 %25 kHz carrier
tc = linspace(0,length(x1)/fs2,length(x1)); %I can't multiply (mix) the two signals x1 and x2
%unless they're of equal length
x2 = sin(2*pi*tc*fc);
figure;
subplot(3,1,1);
plot(x1);
subplot(3,1,2);
plot(x2);
%mixer (AM modulation DSB)
mixer = x1.*x2;
subplot(3,1,3);
plot(mixer);

1 Commento

Clive Sam
Clive Sam il 3 Set 2016
Modificato: Clive Sam il 3 Set 2016
I did an fft on the carrier and I was surprised
P = 1024; %power of 2
fft1 = abs(fft(x2, P)); %magnitude spectrum
fft2 = fft1(1:length(fft1)/2); %cut in half
freqP = 0 : P-1;
freqHz = (freqP/P)*fs2; %normalising i.e conversion to f axis
freqHz2 = freqHz(1:length(freqHz)/2); %cut in half
figure;
plot(freqHz2,fft2);
title('fft of carrier signal');
The fft shows that the frequency of the carrier is 25 kHz (as it should ideally be). That means, my theory that the carrier signal "expanded" is wrong.
Yet, something doesn't seem right about the carrier signal. It doesn't look like it's a lot higher in frequency than the audio tone if you look at the plots.

Accedi per commentare.

Risposte (1)

Star Strider
Star Strider il 3 Set 2016

0 voti

I’m not certain what the problems is. If you have the Signal Processing Toolbox (and you quite definitely need it to do what you want to do here), use the modulate (and demod) functions.
There are other ways if you don’t have these functions, and in the way of documentation, I offer you the Wikipedia Product-to-sum and_sum-to-product identities. They should get you started.
Note that heterodyning (mixing) a carrier and modulating signal without the Signal Processing Toolbox modulate function produces a double-sideband suppressed-carrier output.
I find it difficult to follow your code. I have other examples spread stochastically over the past 2½ years that you are free to search for if you want. Otherwise I’ll do my best to help, but its late here tonight (UTC-6) so we may continue this tomorrow.
73 DE N0KF K

8 Commenti

Clive Sam
Clive Sam il 3 Set 2016
Modificato: Clive Sam il 3 Set 2016
Hi Star Strider,
Thank you for your answer. Yes, I'm aware of the DSBSC output. I think the modulate function in the Signal Processing Toolbox does Hilbert Transform (phase shift method) to get SSB. I have to check that up. Basically, I just wanted to try and simulate it mathematically so I can implement it in a circuit afterward.
My task is to read a .wav file in MATLAB, send it out through the sound card and over a channel to a receiver. The constraint is that the channel bandwidth can only be 4kHz. My circuit would use AM with the filter method to get SSB. So, I want to simulate the filter circuit to to see whether a 2nd or 3rd order filter would suffice (probably won't). Since audio frequencies range from 0-4kHz, after modulation, the sidebands would be located very close to both sides of the carrier frequency. Because the practical filter frequency response isn't sharp, this would make it pretty hard to filter out one sideband I guess. But I reckon it wouldn't really matter from the receiver's point of view if a little of the other sideband cropped in since both sidebands carry the same information anyway.
PS. I use a MacOS and software like Multisim and Proteus don't work (unless I buy Windows ofcourse). It's probably a lot easier to do simulation related to circuits in those.
Hi Clive Sam,
My pleasure.
I’m not familiar with Multisim and Proteus, so you’ll have to enlighten me. To produce SSBSC, I just use a bandpass filter to pass the sideband I want and eliminate the one I don’t. This depends on the carrier frequency, so the 7.3 MHz and below used the lower sideband, and everything above the 40m band the the upper sideband.
If you want to implement it in a circuit afterwards, I would direct you to the American Radio Relay League. Other than my circuit analysis and synthesis courses I took in graduate engineering school, I have relied upon the ARRL for essentially everything, since the crystal receiver and spark-gap era.
Clive Sam
Clive Sam il 3 Set 2016
Hi Star Strider,
I tried the modulate function you suggested. It does dsb too. But it only works as expected when the sampling frequency of both the audio and carrier signals are the same, and that's the same issue that I faced in my code.
I’ll have to check on that in the morning. I wasn’t aware that any such restriction existed. I’ll leave this thread alive and up so I don‘t forget it, and because this is important to me, too.
Clive Sam
Clive Sam il 3 Set 2016
Modificato: Clive Sam il 3 Set 2016
Hi Star Strider,
The "restriction" isn't mentioned anywhere. But that's what I inferred from the results of the execution.
I might give LabVIEW a shot (my uni gives us free access) in case it can't be done on MATLAB.
Thanks
Clive Sam
Clive Sam il 3 Set 2016
Modificato: Clive Sam il 3 Set 2016
Hi Star Strider,
To produce SSBSC, I just use a bandpass filter to pass the sideband I want and eliminate the one I don’t.
Yes that works theoretically. But, since my audio file's frequency range is 0-4 kHz, won't the lower sideband range from (fc - 4) kHz to (fc - 0) kHz and the upper sideband range from (fc + 0) kHz to (fc + 4) kHz? This means that both the sidebands are "very close" to each other. It would be difficult to do SSB using filter method in this case. Is that correct? So what can be done? I don't want to use a really high order filter. That would entail complex circuitry.
Clive Sam
Clive Sam il 3 Set 2016
Modificato: Clive Sam il 3 Set 2016
I think the reason is because in computer simulations, we always use discrete signals in reality and NOT analog (the computer has finite precision) and this is why the sampling frequency matters. But in analog circuits, the signals are processed as analog itself and thus there isn't an issue when mixing different signals.
I apologise for the delay. Busy day yesterday and I was too tired to continue last night.
I’ve always heterodyned signals with the same sampling frequency (using the same time vector) simply because it was convenient and because I’ve always done it that way. I hadn’t thought of that being any particular constraint. I've not studied it analytically, but different sampling frequencies that were related (one was an integer multiple of the other) would require special coding, and consideration of the effect of different sampling frequencies on the resulting signal. You would have to do it with a loop, and then analyse the resulting signal with a Fourier transform. I've not done it myself. I imagine it would resemble a signal contaminated by high-frequency pulse noise with varying-amplitude pulses, not a truly heterodyned signal.
You can always resample your lower-sampling frequency to the (higher) carrier sampling frequency. (This isn’t a factor in analogue signals because there’s an infinite sampling frequency.)
Filtering the heterodyned DSB-SC is not difficult with the appropriate filter. (Cascaded Bessel filters are good for this in hardware but unrealisable in software.) I've done it in software with Chebyshev filters. The filter technique, as I remember, is used in SSB transmitters, where the DSB-SC signal is produced at a constant frequency, filtered to remove one sideband, then mixed with the final carrier frequency before being sent to the final amplifier.

Accedi per commentare.

Richiesto:

il 3 Set 2016

Commentato:

il 3 Set 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by