Azzera filtri
Azzera filtri

Unwanted axis in the figure

3 visualizzazioni (ultimi 30 giorni)
Florian
Florian il 21 Mag 2024
Hello everyone,
I have a problem trying to create an animation. When I use the movie() function, an additional axis is created that moves all subplots into the top right corner. While the individual frames are being created everything looks fine, the problem only appears once the movie() function is executed.
This is the code I'm using:
close all, clc, clear all
tic
filename = '1mDyn440Hz.wav'; %signalname
resolution = 50; %Auflösung in ms
speed = 1;
[pRaw, Fs] = audioread(filename);
sampleStep = Fs * (resolution/1000); %Berechnung der Samples die auf einmal berechnet werden sollen
pmax = fix(length(pRaw)/sampleStep); %ermittelt die maximalen schleifen durchläufe
p = pRaw(1:sampleStep,:);%der erste sampleblock der berechnet wird
fps = speed*pmax/(length(pRaw)/Fs);%berechnung der FPS damit wird die Animation auf die Aufnahmezeit Skaliert
%Globale Variablen
M = 8; %anzahl der mikrofone
%Ausschnitt = [4.7e4:5e4];
N = length(p);
%N = length(Ausschnitt); %blocklaenge -> hier ein einziger großer block
c = 344; %schallgeschwindigkeit [m/s]
% Theta = -pi/2:pi/60:pi/2; %winkel von -90° bis +90° durchlaufen
Theta = 0:pi/180:pi; %winkel von -90° bis +90° durchlaufen
d = 0.17; %abstand zwischen zwei mikrofonen
xm = [((-7*d)/2) ((-5*d)/2) ((-3*d)/2) ((-1*d)/2) ((1*d)/2) ((3*d)/2) ((5*d)/2) ((7*d)/2)]; %orte der mikrofone im koordinatensystem
cal_faktor = 1./[0.0648 0.0698 0.0506 0.0702 0.0729 0.0618 0.0474 0.0606];
k = [0:N/2]; %stützstellen mit der hälfte der abtastrate
f = Fs/N*k; %frequenzen
[xm_all, k_all,Theta_all]=meshgrid(xm, k, Theta);
nextFrame = 1;%Counter für die einzelnen frames die in Mframes gespeichert werden
h = figure;
% %axis tight manual
% % ax = gca;
% % ax.NextPlot = 'replaceChildren';
h.Visible = 'on'; %Verhindert das wärend der Berechnung die einzelnen Frames zu sehen sind. On => Vorschau
axis off
Mframe(pmax) = struct('cdata',[],'colormap',[]); % Beinhaltet die einzelnen Frames
%polar(S_ges);
tiledlayout(2, 2);
for index = 1:sampleStep:pmax*sampleStep % For-Schleife zählt in smapleblock(sampleStep) schritten bis die maximale anzahl an samples erreicht ist
%fft der Mikrofonsignale
% P = fft(p(1:N,3:8));
P = fft(p(1:N,1:8));
P_big = repmat(P,1,1,length(Theta));
efkt=exp(-j*((2*pi)/N).*k_all.* Fs .*(xm_all/c).*cos(Theta_all));
S =squeeze((1/M)*sum(P_big(k+1,:,:).*efkt,2));
fIndU = 10 * N / Fs;
fIndO = 5000 * N / Fs;
S_ges = sum(abs(S(fIndU:fIndO,:)));
nexttile(1) %
hp=plot(S_ges/max(S_ges),'b');
ylim([0 1])
xlabel("Winkel [°]");
ylabel("Summensignal [Abs]");
nexttile(2)
polar(Theta,abs(S_ges),'r');
nexttile(3)
[maxX,maxXin] = max(S_ges);
[x,y] = pol2cart(Theta(maxXin),maxX);
nexttile(3)
% axis manual;
quiver(0,0,x,y,'AutoScale','off','AutoScaleFactor',1); %?
xlim([-3 3]); % x-Achse von -3 bis 3
ylim([-3 3]); % y-Achse von -3 bis 3
drawnow;
Mframe(nextFrame) = getframe(1);%Speichert nach jedem sampleblock den frame ab
nextFrame = nextFrame + 1; %counter wird erhöht für nächsten frame
p = pRaw(index:index+sampleStep,:); %neuer block an samples wird für neue berechnung geladen
end
%%
figure;%scihtbar machen der figure
movie(Mframe,1,fps); %abspielen der Animation

Risposte (1)

Abhishek Kumar Singh
Abhishek Kumar Singh il 27 Mag 2024
Hi Florian,
To execute the code you provided, it requires the '1mDyn440Hz.wav' file. However, in the absence of this file, I've used a dummy simulated 8-channel audio signal as follows:
% Simulated audio signal parameters
Fs = 44100; % Sample rate in Hz
t = 0:1/Fs:1-1/Fs; % Time vector for 1 second
f1 = 440; % Frequency of the first tone in Hz
f2 = 880; % Frequency of the second tone in Hz
% Frequencies for the 8 channels (can be the same or different)
frequencies = [440, 880, 500, 750, 1000, 1250, 1500, 1750]; % Example frequencies for each channel
% Generating the 8-channel audio signal
pRaw = zeros(length(t), 8); % Initialize the matrix to store the 8-channel signal
for i = 1:8
pRaw(:, i) = sin(2*pi*frequencies(i)*t)'; % Each channel with its own frequency
end
Then I ran the script and as you described, I received similar output as you shared in the query.
To ensure that the figure used for displaying the animation does not have an extra axis, you can explicitly control the figure and axes properties when displaying the animation. Here's how you can modify your code to remove any extra axes from the last figure:
% Display the animation
figAnimation = figure;
% Set figure to fullscreen or a specific size as needed
% set(figAnimation, 'Position', get(0, 'Screensize')); % Uncomment to make fullscreen
% Create axes in the figure for the movie, ensuring it fills the entire figure
axesAnimation = axes('Parent', figAnimation, 'Position', [0 0 1 1]);
% Remove axis ticks and labels
axis off;
% Play the movie in the axes created
movie(axesAnimation, Mframe, 1, fps);
By controlling the figure and axes properties like this, you can ensure that your animation display is as intended, without extra or unwanted graphical elements.
Here's what I received after running the program successfully:
Hope it helps!

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!