AM modulation of audio file

23 views (last 30 days)
Clive Sam
Clive Sam on 3 Sep 2016
Commented: Star Strider on 3 Sep 2016
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 Comment
Clive Sam
Clive Sam on 3 Sep 2016
Edited: Clive Sam on 3 Sep 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.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 3 Sep 2016
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 Comments
Clive Sam
Clive Sam on 3 Sep 2016
Edited: Clive Sam on 3 Sep 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.
Star Strider
Star Strider on 3 Sep 2016
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!