I am trying to implement AM demodulation in Matlab by taking advantage of the fact that in the frequency domain, the spectrum of the modulated signal is shifted by the frequency of the carrier.
I wrote code in Matlab that shifts the componenets back and does an inverse Fourier Transform to reconstruct the signal. The code seems to work well enough for a cosine with a cosine envelope, but if I try using a cosine to modulate a sine, I do not get the correct signal, and my Fourier specturm seems to have both real and imaginary components, which has me buffled: If the Fourier transform should be the spectrum of the envelope just shifted, and the envelope is a sine, shouldn't the transform be pure imaginary?
I attach my code along with a graph that shows my resultsAny help is appericiated in getting to the bottom of this.
clear all f = 50; % Message Frequency fc = 1000; % Carrier Frequency Fs = 5000; % Sample Frequency t = (0:(1/Fs):1); L = length(t); s = sin(2*pi*f*t); % Message Signal mod = s.*cos(2*pi*fc*t); % Modulated Signal % Fourier Transform a = fftshift(fft(mod)); w = Fs*(-(L/2):(L/2-1))/Fs; % Frequency axis %% Perform complex demodulation: % Zero all components less than the carrier frequency a_zeroes = a; a_zeroes(w<fc) = 0; % Move the spectrum back by the carrier circularly to effectivly shift % back: a_shifted = circshift(a_zeroes,[0,-fc]); % Reflect a_reflected = fliplr(a_shifted); a_demoded = a_shifted; a_demoded(1:floor(length(a_demoded)/2)) = a_reflected(1:floor(length(a_demoded)/2)); % Take inverse fft demoded = ifft(ifftshift(((a_demoded)))); %% Plot fft and demodulated vs. modulated figure; subplot(3,1,1); plot(w,real(a),'r','linewidth',4); hold on; plot(w,imag(a),'g','linewidth',2); title('Original FFT'); subplot(3,1,2); plot(w,real(a_demoded),'r','linewidth',4); hold on; plot(w,imag(a_demoded),'g','linewidth',2); title('Shifted FFT'); subplot(3,1,3); plot(t,s); hold on; plot(t, (sqrt(2*pi)).*(demoded)); title('Original Vs. Demodulated');
Here you can see the original FFT. I reconstructed the envelope's spectrum, then did an inverse FFT, but the result has less amplitude and is out of phase.