AM modulation of audio file
Show older comments
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
Answers (1)
Star Strider
on 3 Sep 2016
0 votes
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
Star Strider
on 3 Sep 2016
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
on 3 Sep 2016
Star Strider
on 3 Sep 2016
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.
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.
Categories
Find more on Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!