Creating a signal including a linear chirp
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello everyone,
for a current project I am working on, I am trying to create a test signal with Matlab. The signal should include: A constant sine(or cosine) wave, followed by a linear chirp which, in a given time, increases the former frequency to a higher frequency x, this frequency x should then be kept for some time. After that, an inverted linear chirp should make the signal go back to the initial frequency.
I included a UI for the input of the times and frequencys and so on.
My problem is: The chirps do not work as intended. I'll insert photos of the UI, of the plot and of my code. In this example, the output should be: 5 seconds constant cosine of 1Hz, then the linear sweep from 1Hz to 2Hz within 5 seconds, then the 2Hz should be kept for 5 seconds, then the inverted linear sweep goes back from 2Hz to 1Hz within 5 seconds and then the 1Hz signal should be kept for 5 more seconds.
I know that I still have problems with the phase between the signal parts, but I wanted to face the problem with the chirp first, which does not work as intended. If you need further information, please let me know.
This is the code that reads the given values from the UI and then should create the signal from it:
app.TextArea.Value = compose ("Building Wave Data...");
sampleRate = (1/44100); %Samplerate 44,1kHz
%Alle Variablen aus App speichern
%Save all variables from the UI (works as intended)
allVariables = zeros(1, 20);
allVariables = returnAllVariables(app);
%Generiere die Zeitvektoren mit 44,1 kHz Abtastrate,
%Unterteilung in 5 Zeitabschnitte
%Generate the time vectors for the five signal parts (works as intended)
time_t1 = 0:sampleRate:allVariables(1, 1);
time_t2 = allVariables(1, 1):sampleRate:(allVariables(1, 1) + allVariables(1, 2));
time_t3 = (allVariables(1, 1) + allVariables(1, 2)):sampleRate:(allVariables(1, 1) + allVariables(1, 2) + allVariables(1, 3));
time_t4 = (allVariables(1, 1) + allVariables(1, 2) + allVariables(1, 3)):sampleRate:(allVariables(1, 1) + allVariables(1, 2) + allVariables(1, 3) + allVariables(1, 4));
time_t5 = (allVariables(1, 1) + allVariables(1, 2) + allVariables(1, 3) +allVariables(1, 4)):sampleRate:(allVariables(1, 1) + allVariables(1, 2) + allVariables(1, 3) + allVariables(1, 4) + allVariables(1, 5));
time_all = horzcat(time_t1, time_t2, time_t3, time_t4, time_t5); %Gesamtzeitvektor
%Berechne Kreisfrequenzfaktor
%%NOT USED RIGHT NOW
k_steigend = ((allVariables(1, 7)) - (allVariables(1, 6))) / (allVariables(1, 2));
k_fallend = -k_steigend;
%%
%Generiere den Signalverlauf
%Generate the signal
signal_t1 = cos(allVariables(1, 6) * time_t1);
%signal_t2 = sin((allVariables(1, 6) + (k_steigend/2)*time_t2) .* time_t2);
signal_t2 = chirp(time_t2, (allVariables(1, 6)/(2*pi)), allVariables(1, 2), (allVariables(1, 7)/(2*pi)), 'linear', 0); %Signalverlauf für T2
signal_t3 = cos(allVariables(1, 7) * time_t3);
signal_t4 = chirp(time_t4, (allVariables(1, 7)/(2*pi)), allVariables(1, 4), (allVariables(1, 6)/(2*pi)), 'linear', 0); %Signalverlauf für T4
signal_t5 = cos(allVariables(1, 6) * time_t5);
signal_all = horzcat(signal_t1, signal_t2, signal_t3, signal_t4, signal_t5);
plot(time_all, signal_all);
grid on;
This is the UI
![UI with values.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/220305/UI%20with%20values.png)
This is the plot I receive:
![Plot.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/220306/Plot.png)
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!