Azzera filtri
Azzera filtri

Creating a Triangle Wave woes

6 visualizzazioni (ultimi 30 giorni)
Alex il 10 Gen 2012
I'm having trouble generating a nice looking triangle wave. Doing the calculation, with what I think is, the proper way results in a distorted PSD of the signal. Doing the Triangle in another way (with time reversal), gives a much better PSD image.
However, when these two signals are loaded into a VSG, the proper way has the correct period, whereas the second way has a period of 1/2.
In the following code, I'll show the 2 methods used. When loaded loaded into the VSG, the first has spectral spacing of 1 KHz (which is expected with a rep_rate of 1000). However, the second (with the better PSD) has a spectral spacting of 2 KHz. I have been unable to determine what is causing the issues with either method.
bandwidth = 20e6; %20 MHz
sample_rate = 100e6; %100MHz
rep_rate = 1000; %1000 times a second
num_samples = sample_rate/rep_rate;
%method 1
time_vector = 1/sample_rate : 1/sample_rate: 1/(rep_rate);
mid_time = round(length(time_vector)/2);
%linear rate at which the sweep increases in frequency
inc_chirp_rate = (2*band_width*sample_rate)/num_samples;
dec_chirp_rate = -1*((2*band_width*sample_rate)/num_samples);
%freqency which the saw sweep starts at
inc_start_freq = -1*(band_width/2);
dec_start_freq = 3*band_width/2;
%A linear sweep argument fits the following format:
% 2*pi( start_freq + (chirp_rate/2)*t)*t
inc_sweep_values = 2*pi*( inc_start_freq + (inc_chirp_rate/2).*time_vector(1:mid_time) ).*time_vector(1:mid_time);
dec_sweep_values = 2*pi*( dec_start_freq + (dec_chirp_rate/2).*time_vector(mid_time + 1:end)).*time_vector(mid_time + 1:end);
%Complete signal method 1
complete_val = [inc_sweep_values dec_sweep_values];
%create the I & Q followed by the Complex combination of the signal
i1 = cos(complete_val);
q1 = sin(complete_val);
com1 = complex(i1,q1);
%complete signal method 2
%uses the time reversal of the incline
complete_val2 = [inc_sweep_values inc_sweep_values(end:-1:1)];
%calculate the I & Q and then complex signal for the 2nd method
i2 = cos(complete_val2);
q2 = sin(complete_val2);
com2 = complex(i2,q2);
%compare the signals
%resample the signals for easier viewing
[f1, p1] = freqz(com1, 1, 1024 ,'whole', sample_rate);
[f2, p2] = freqz(com2, 1, 1024 ,'whole', sample_rate);
%take the log of the fft of the signal
logdata1 = 20*log10(fftshift(abs(f1)));
logdata2 = 20*log10(fftshift(abs(f2)));
%plot the 2 signals
title('Formal way to calculate Tri');
title('Time reveral way to calculate');

Risposta accettata

Alex il 13 Gen 2012
Ok, I was able to figure this out on my own after much fiddling.
Method 1: 'proper method'
The issue here is that the incline & decline sections of waveform hit different frequencies. I.e. The incline section hits the odd frequency index's (1, 3, 5,...) whereas the decline section his the even frequency index's (2, 4, 6,...). Due to this lack of symmetry, the PSD will also not be symmetric.
The good side to using this method though is that every possible frequency is touched during the sweep. I.e. the spectral spacing of for this method will be 1KHz based on the previous example.
using an indexed example, the freq index's using this method would be something like : 1, 3, 5, 7, 9, 10, 8, 6, 4, 2 (each number is hit once, but the vector isn't symmetric)
Method 2: 'Time reversal Method'
In this case, each frequency is actually hit twice, once on the way up and once on the way down. Since the incline and decline steps are symmetric, the resulting PSD will also be symmetric.
The downside to this is that the spectral lines will result in being twice the distance. This is because each of those frequencies are being hit twice.
using an indexed example, the freq index's using this method would be something like : 1, 3, 5, 7, 9, 9, 7, 5, 3, 1 (each number is hit twice, but the values are symmetric)
In result, there is no way to have both, a symmetric PSD AND hit every desired frequency.

Più risposte (0)


Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by