Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Shifting spectrum in matlab

Status
Not open for further replies.

micro7311

Junior Member level 2
Junior Member level 2
Joined
Jun 21, 2015
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
199
Hi, in the below code I am generating a signal with a center frequency of 0MHz, +/- 10 MHz. I am wondering how to shift the entire spectrum to a center frequency of 20 MHz, +/-10 MHz (10 MHz to 30 MHz). What I am trying to do is take the final spectrum and multiply it by a complex exponential. No matter what time value I choose in the exponential, the spectrum doesn't move from fc = 0 MHz. Am I approaching this correctly?

Code:
nFFTSize = 64;
subcarrierIndex = [-26:-1 1:26];
nBit = 1000; 
ip = rand(1,nBit) > 0.5; 
nBitPerSymbol = 52;
nSymbol = ceil(nBit/nBitPerSymbol);

ipMod = 2*ip - 1; 
ipMod = [ipMod zeros(1,nBitPerSymbol*nSymbol-nBit)];
ipMod = reshape(ipMod,nSymbol,nBitPerSymbol);

st = []; 

for ii = 1:nSymbol

inputiFFT = zeros(1,nFFTSize);

% assigning bits a1 to a52 to subcarriers [-26 to -1, 1 to 26]
inputiFFT(subcarrierIndex+nFFTSize/2+1) = ipMod(ii,:);

%  shift subcarriers at indices [-26 to -1] to fft input indices [38 to 63]
inputiFFT = fftshift(inputiFFT); 

outputiFFT = ifft(inputiFFT,nFFTSize);

% adding cyclic prefix of 16 samples 
outputiFFT_with_CP = [outputiFFT(49:64) outputiFFT];

st = [st outputiFFT_with_CP]; 

end

st2 = st*exp(2*pi*20*i*.0000032);

scatterplot(st2), grid;
 

The statement:

Code:
st2 = st*exp(2*pi*20*i*.0000032);
is not dependent on time (sample index), it just multiplies st by a complex constant. You need to do something like this.

Code:
t = 1:length(st);
st2 = st.*exp(2*pi*20*i*0000032*t);

Don't forget the .* between st and exp.
 
Thank you, I forgot the dot operator. I have added the following code.

Code:
fcMHz = 20;
fsMHz = 20;

t = 0:size(st)-1;
st2=st.*exp(1j*2*pi*fcMHz*t/fsMHz);

scatterplot(st2), grid;

My baseband signal still won't move from 0 MHz center. I can get the spectrum to shift by manually assigning x-axis frequency scale points, but I need just the baseband signal to have positive frequencies, centered around 20 MHz with 20 MHz bandwidth.
 

You must understand that in real life there is no complex signals. What to do? I think it's an answer!

https://en.wikipedia.org/wiki/In-phase_and_quadrature_components
https://en.wikipedia.org/wiki/Quadrature_amplitude_modulation

Code:
fcMHz = 20;
fsMHz = 20;

t = 0:size(st)-1;
st2=st.*exp(1j*2*pi*fcMHz*t/fsMHz);

So, in Euler's formula:

exp(jwt) = cos(wt) + j*sin(wt)

In your notation your have w = 2*pi*N (N is natural number) ALWAYS. Well, |cos(2*pi*N)| = 1 ALWAYS, and sin(2*pi*N) = 0 ALWAYS => there are not reasons for spectrum shifting!
 

Thank you that is very helpful information and it makes sense. So then the question becomes how to plot 2 of these baseband spectrums together, one at fc =0MHz +/- 10 MHz, and the other at fc = 20 MHz +/- 10 MHz. My plan was to generate two independent baseband signals and concatenate them to one matrix.
 

Thank you that is very helpful information and it makes sense. So then the question becomes how to plot 2 of these baseband spectrums together, one at fc =0MHz +/- 10 MHz, and the other at fc = 20 MHz +/- 10 MHz. My plan was to generate two independent baseband signals and concatenate them to one matrix.

Do you mean how to plot figure like this one?

broken link removed

Blue modulated red zero-frequacy component.
 
Last edited by a moderator:

Yes like that plot, using only baseband data. Essentially 3 independent channels.
 

Well, i have used BPSK modulation with filtering.

Spectrum of binary seq.:

broken link removed

Spectrum of modulated signal:

broken link removed

Spectrum of binary seq. and modulated signal:

broken link removed

Code:
Code:
L = length(FILT_CODE);
k = 2^nextpow2(L); %the nearest 2's pow. for using FFT
FFT_VALUE = abs(fft(FILT_CODE,k)); 
FFT_SHIFT_ARRAY = fftshift(FFT_VALUE); %shift first value of FFT_VALUE in the middle 
f = (-k/2:k/2-1)/k*Fs; %freq.-s net
plot(f, FFT_SHIFT_ARRAY/max(FFT_SHIFT_ARRAY));
grid on;
xlabel('Freq.,Hz');
ylabel('Normalized magnitude');

hold on; %plot 2 graphs on one figure

CARRIER = zeros(1:L,1);
CARRIER = cos(2*pi*30e6*td*(1:L));
MODULATED_SIGNAL = FILT_CODE.*CARRIER'; %BPSK modulation
FFT_VALUE_2 = abs(fft(MODULATED_SIGNAL,k)); 
FFT_SHIFT_ARRAY_2 = fftshift(FFT_VALUE_2);
plot(f, FFT_SHIFT_ARRAY_2/max(FFT_SHIFT_ARRAY));
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top